Here's what error I got while connecting the Access database to my Visual Studio.
I am confused about what to do next.
Public Class main
Const WM_NCHITTEST As Integer = &H84
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DoubleBuffered = True
Timer1.Start()
Label1.Text = "Locker"
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Location = New Point(Label1.Location.X + 15, Label1.Location.Y)
If (Label1.Location.X >= 330) Then
Timer1.Stop()
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
DoubleBuffered = True
GroupBox1.Size = New Size(GroupBox1.Size.Width, GroupBox1.Size.Height + 10)
If (GroupBox1.Size.Height >= 298) Then
Timer2.Stop()
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_NCHITTEST
MyBase.WndProc(m)
If m.Result = IntPtr.op_Explicit(HTCLIENT) Then m.Result = IntPtr.op_Explicit(HTCAPTION)
Case Else
MyBase.WndProc(m)
End Select
End Sub
End Class
Try removing it from Resources from Properties(Alt+Enter). And Re-open it. I think whenever you delete any resource file which is been used by a form then the form designer code can not locate it so try this one also by removing the line of code from Form[Designer].vb (opening in Notepad++).
Related
I have two forms with msflexgrid to display data with datasource from datatable.
I want to drag and drop rows between two form each other. I saw this topic and edited but it doesn't work.
Drag data from DG and other controls to another DG in vb.net
This error:
Please help me!
This is my form1
form1
Code form 1:
Imports C1.Win.C1FlexGrid
Public Class frm1
Private mdt As New DataTable("Test")
Private downHitInfo As C1.Win.C1FlexGrid.HitTestInfo = Nothing
Private Sub frm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mdt.Columns.Add("EmplCode")
mdt.Columns.Add("EmplName")
mdt.Rows.Add("012345", "A")
mdt.Rows.Add("012346", "B")
mdt.Rows.Add("012347", "C")
flg1.DataSource = mdt
With flg1
.DragMode = DragModeEnum.Manual
.DropMode = DropModeEnum.Manual
End With
End Sub
Private Sub flg1_MouseDown(sender As Object, e As MouseEventArgs) Handles flg1.MouseDown
Dim view As C1FlexGrid = CType(sender, C1FlexGrid)
Dim hitInfo As C1.Win.C1FlexGrid.HitTestInfo = view.HitTest(e.X, e.Y)
If Not Control.ModifierKeys = Keys.None Then
Exit Sub
End If
If e.Button = MouseButtons.Left Then
downHitInfo = hitInfo
End If
End Sub
Private Sub flg1_MouseMove(sender As Object, e As MouseEventArgs) Handles flg1.MouseMove
Dim view As C1FlexGrid = CType(sender, C1FlexGrid)
If e.Button = MouseButtons.Left And Not downHitInfo Is Nothing Then
Dim dragSize As Size = SystemInformation.DragSize
Dim DragRect As Rectangle = New Rectangle(New Point(Convert.ToInt32(downHitInfo.X - dragSize.Width / 2), _
Convert.ToInt32(downHitInfo.Y - dragSize.Height / 2)), dragSize)
If Not DragRect.Contains(New Point(e.X, e.Y)) Then
'Extract the DataRow
Dim gridRowView As C1.Win.C1FlexGrid.Row = DirectCast(view.Rows(downHitInfo.Row), C1.Win.C1FlexGrid.Row)
'Dim rowView As DataRowView = DirectCast(gridRowView.DataBoundItem, DataRowView)
Dim rowView As DataRowView = DirectCast(gridRowView.DataMap, DataRowView)
'Raise the DragDrop with the extracted DataRow
view.DoDragDrop(rowView.Row, DragDropEffects.Move)
downHitInfo = Nothing
End If
End If
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
Dim lfrm As New frm2()
lfrm.Show()
End Sub
End Class
This is form 2:
Form 2
Code of form 2:
Imports C1.Win.C1FlexGrid
Public Class frm2
Private Sub frm2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With flg2
.DragMode = DragModeEnum.Manual
.DropMode = DropModeEnum.Manual
End With
End Sub
Private Sub flg2_DragOver(sender As Object, e As DragEventArgs) Handles flg2.DragOver
e.Effect = DragDropEffects.Move
End Sub
Private Sub flg2_DragDrop(sender As Object, e As DragEventArgs) Handles flg2.DragDrop
Dim draggedRow As DataRow = CType(e.Data.GetData(GetType(DataRow)), DataRow)
End Sub
End Class
I created a small app in vb.net for a friend. The problem is that on my PC (W7 64bits) it works great (registry reading / writing) but on my friends PC (W8 64bits) it doesn't work.
It it strange but at the moment he runs my app (it checks the registry on loading) it gives him a "Access to registry denied" error. I tried to run it with admin rights but it doesn't work either.
Here is my code:
Imports Microsoft.Win32
Public Class Form1
Dim planned As Date
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
Private Sub planifier_Click(sender As Object, e As EventArgs) Handles planifier_button.Click
Dim toExecute As String = String.Format("shutdown -s -f -t {0}", 100)
Dim currentDate = System.DateTime.Now
Dim futureDate = DateTimePicker1.Value
Dim difference = futureDate - currentDate
Console.Out.WriteLine(difference)
System.Diagnostics.Process.Start("shutdown", "-s -f -t " & Math.Round(difference.TotalSeconds))
Me.planned = futureDate
saveStgFile(futureDate)
setup()
End Sub
Private Sub Shutdown_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Console.Out.WriteLine(Application.ProductName & " & " & Application.ExecutablePath)
getStgFile()
getPlanned()
setup()
Dim baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
Startup.Checked = baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).GetValue(Application.ProductName).Equals(Application.ExecutablePath)
End Sub
Private Sub cancel_button_Click(sender As Object, e As EventArgs) Handles cancel_button.Click
System.Diagnostics.Process.Start("shutdown", "-a")
Me.planned = Nothing
saveStgFile(Nothing)
setup()
End Sub
Sub setup()
If Me.planned.Equals(Nothing) Then
cancel_button.Enabled = False
planifier_button.Enabled = True
planifier_button.Text = "Planifier"
Else
cancel_button.Enabled = True
planifier_button.Enabled = False
planifier_button.Text = Me.planned.TimeOfDay.ToString()
End If
End Sub
Function getPlanned() As TimeSpan
Dim stg As String = getStgFile()
Dim fileContent As String = My.Computer.FileSystem.ReadAllText(stg)
Dim timespan As Date
If fileContent = "none" Then
Me.planned = Nothing
ElseIf Date.TryParse(fileContent, timespan) Then
Me.planned = timespan
End If
Return (Me.planned - System.DateTime.Now)
End Function
Function getStgFile() As String
Dim stgFile = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "AutoShutdown")
If My.Computer.FileSystem.DirectoryExists(stgFile) = False Then
FileSystem.MkDir(stgFile)
End If
stgFile = System.IO.Path.Combine(stgFile, "settings.ini")
If My.Computer.FileSystem.FileExists(stgFile) = False Then
My.Computer.FileSystem.WriteAllText(stgFile, "none", False)
End If
Return stgFile
End Function
Sub saveStgFile(planned As Date)
Dim stgFile As String = getStgFile()
Try
If (planned.Equals(Nothing)) Then
My.Computer.FileSystem.WriteAllText(stgFile, "none", False)
Else
My.Computer.FileSystem.WriteAllText(stgFile, planned.ToString(), False)
End If
Catch ex As Exception
Throw ex
End Try
End Sub
Private Sub Startup_CheckedChanged(sender As Object, e As EventArgs) Handles Startup.CheckedChanged
Dim baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
If Startup.Checked Then
baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Console.Out.WriteLine("Add to startup")
Else
baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)
Console.Out.WriteLine("Remove from startup")
End If
End Sub
End Class
I am building a program in visual-studio to check and fix drive using the cmd chkdsk command
I have been able to display the list of drive available is a dataGridview
I want to run chkdsk command on any selected drive(by the user) please how do I achieve that successfully. Furthermore I want the process and result of the chkdsk to be displayed on a textbox.
problem is the drives are displaying but when one is select and i click on the button fix is dose not execute(i.e fix the drive and show result&process in the textbox) Any help/code/suggestion will b appreciated, please note this is note a console application. My code are on is posted here as requested. i added the subs were i feel the problem could be from. , but if you want me to add more of my other subs i will.
Public Class Form2
Private binder As New BindingSource
Private drives As New BindingList(Of DriveInfo)
Private psi As ProcessStartInfo
Private cmd As Process
Private Delegate Sub invokeWithString(ByVal text As String)
Dim BackgrounndWorker1 As New BackgroundWorker
Private Shadows Sub OnClick(sender As Object, e As EventArgs) Handles btnfix.Click
If TypeOf sender Is Button Then
Dim btn = DirectCast(sender, Button)
btn.Enabled = False
If btn.Equals(btnfix) Then
Ddrives.Enabled = False
pgb.Visible = True
BackgroundWorker1.RunWorkerAsync(New List(Of DriveInfo)(From drive As DriveInfo In cldrive.CheckedItems Select drive))
End If
End If
End Sub
Private Sub OnDoWOrk(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If TypeOf sender Is BackgroundWorker Then
Dim worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
If e.Argument IsNot Nothing AndAlso TypeOf e.Argument Is IEnumerable(Of DriveInfo) Then
Dim drives As IEnumerable(Of DriveInfo) = DirectCast(e.Argument, IEnumerable(Of DriveInfo))
For Each drive As DriveInfo In drives
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox1.Text = ""
psi = New ProcessStartInfo("Chkdsk /f")
Dim systemcoding As System.Text.Encoding =
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemcoding
.StandardErrorEncoding = systemcoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_data_received
AddHandler cmd.OutputDataReceived, AddressOf Async_data_received
Try
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
Catch ex As System.ComponentModel.Win32Exception
End Try
Next
End If
End If
End Sub
Private Sub Async_data_received(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(New invokeWithString(AddressOf Sync_output), e.Data)
End Sub
I have a ListBox on which I want to handle the mousemove event; And for that reason I'm using the following code
Private Sub AreaLB_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles AreaLB.MouseMove
Dim ListMousePosition As Point = AreaLB.PointToClient(Me.MousePosition)
Dim itemIndex As Integer = AreaLB.IndexFromPoint(ListMousePosition)
Dim AreaToolTip As ToolTip = ToolTip1
Dim myLB As ListBox = AreaLB
AreaToolTip.Active = True
Dim g As Graphics = AreaLB.CreateGraphics()
If itemIndex > -1 Then
Dim s As String = myLB.Items(itemIndex)
If g.MeasureString(s, myLB.Font).Width > myLB.ClientRectangle.Width Then
AreaToolTip.SetToolTip(myLB, s)
Else
AreaToolTip.SetToolTip(myLB, "")
End If
g.Dispose()
End If
End Sub
My problem is... When I'm not moving the mouse this procedure runs always when the
g.MeasureString(s, myLB.Font).Width > myLB.ClientRectangle.Width
Why that happens and how can I avoid it.
What you can do is only set the ToolTip if it isn't already the value you want it to be:
Private Sub AreaLB_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles AreaLB.MouseMove
ToolTip1.Active = True
Dim itemIndex As Integer = AreaLB.IndexFromPoint(e.X, e.Y)
If itemIndex > -1 Then
Using g As Graphics = AreaLB.CreateGraphics()
Dim s As String = AreaLB.Items(itemIndex)
If g.MeasureString(s, AreaLB.Font).Width > AreaLB.ClientRectangle.Width Then
If ToolTip1.GetToolTip(AreaLB) <> s Then
ToolTip1.Show(s, AreaLB)
End If
Else
ToolTip1.Show("", AreaLB)
End If
End Using
End If
End Sub
I only have access to the internet at school, so the filters get in the way of any real research. I'm currently coding an rpg for a school project but it's difficult to get the avatar to move on a map. Here's my pathetic code so far:
Public Class Map1
Private Sub USER_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
User.Top = User.Top - 1
End Sub
Private Sub USER_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
User.Top = User.Bottom + 1
'User.Location.X = 200
End Sub
End Class
I have the following problems with it:
User.location.x = 200 had syntax errors when I deleted the x and when I didn't.
The player also had to continually press the keys to move.
both I do not know how to correct.
Any help at all is greatly appreciated as it's for my final grade.
You can put it in a timer_tick to loop over it, that is what I do.
And the correct version of User.Location.X = 200 is:
User.location = new point(200, User.location.y)
nvm found the solution.
Here it is for anyone else how might need the code in the future.
Private Sub Map_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Up Then
User.Location = New Point(User.Location.X, User.Location.Y - 5)
ElseIf e.KeyCode = Keys.Down Then
User.Location = New Point(User.Location.X, User.Location.Y + 5)
ElseIf e.KeyCode = Keys.Left Then
User.Location = New Point(User.Location.X - 5, User.Location.Y)
ElseIf e.KeyCode = Keys.Right Then
User.Location = New Point(User.Location.X + 5, User.Location.Y)
End If
Module
Public Sub MovePictureBox(ByRef PictureBox As PictureBox)
Tiempo.Tag = PictureBox
AddHandler PictureBox.Parent.KeyDown, AddressOf Parent_KeyDown
AddHandler PictureBox.Parent.KeyUp, AddressOf Parent_KeyUp
AddHandler CType(PictureBox.Parent, Form).Load, AddressOf Parent_Load
End Sub
Private Up, Down, Left, Right As Boolean
WithEvents Tiempo As New Timer() With {.Interval = 1}
Private Sub Tiempo_Tick() Handles Tiempo.Tick
If Up Then Tiempo.Tag.Top -= 2
If Down Then Tiempo.Tag.Top += 2
If Left Then Tiempo.Tag.Left -= 2
If Right Then Tiempo.Tag.Left += 2
End Sub
Private Sub Parent_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Up Then Up = True
If e.KeyCode = Keys.Down Then Down = True
If e.KeyCode = Keys.Left Then Left = True
If e.KeyCode = Keys.Right Then Right = True
Tiempo.Enabled = True
End Sub
Private Sub Parent_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Tiempo.Enabled = False
Up = False : Down = False : Right = False : Left = False
End Sub
Private Sub Parent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
sender.KeyPreview = True
End Sub
End Module