I want to change the position of the cursor over a particular label. I use:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor.Position = Label17.Location
End Sub
but it doesn't change where I want it. I tried:
Label16.Location = Label17.Location
And this move the label16 properly.
So How do we move the cursor to the location of label17 or any label/object.
The problem is that Label.Location (and any other Control.Location) refers to location relative to the upper-left corner of its container. This mean that you must call the PointToScreen method of the parent container. In a simple application that just have a Form without any other container, it will be:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor.Position = Me.PointToScreen(Label17.Location)
End Sub
A more elegant one:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor.Position = Label17.Parent.PointToScreen(Label17.Location)
End Sub
Related
I am trying to create a program which:
Downloads a web page on a regular interval (every 10 minutes)
Finds a specific element on the page (an HTML div element with an ID of rekto)
Checks the value of that element, and then acts on it (if it's 0, do nothing and wait for the next cycle, and it if it's 1, launch notepad.exe)
Here's the code I have so far:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https://controlry.tr.gg/control.htm")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Me.Hide()
Timer1.Enabled = False
WebBrowser1.Refresh()
WebBrowser1.Document.GetElementById("rekto").GetAttribute("value")
If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
So i've been trying to make a game with arrow keys.
The label is the character, if the label is inside the object, it will do something...
But i got a very hard problem i cannot find on the internet.
How do i check if a label is inside of an object? Example: Picture box, and Panel.
I've tried this one.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Label1.Location.X = Panel1.Location.X And Label1.Location.Y = Panel1.Location.Y Then
Me.Close() 'Any code.
End If
End Sub
Doesn't work,
any help would be appreciated.
I am a beginner by the way, i only make simple applications. Like escape the room, maze... etc.
I would use the label's parent property to see if it is inside the panel.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Label1.Parent IsNot Nothing AndAlso Label1.Parent Is Panel1 Then
Me.Close() 'Any code.
End If
End Sub
If you are looking to see if the Label is over the Panel I would try something like this. The ClientRectangle property is the rectangle the control takes up. I am assuming the panel is bigger than the Label.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Panel1.ClientRectangle.Contains(Label1.ClientRectangle) Then
Me.Close() 'Any code.
End If
End Sub
If it is smaller you can check if a point is in the Panel's rectangle. For example top left corner
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Panel1.ClientRectangle.Contains(new Point(Label1.Left, Label1.Top)) Then
Me.Close() 'Any code.
End If
End Sub
I am trying to click this button in WebBrowser Control
Im trying to make a web automation to purchase from gamestop im using visual basic 2010 express heres what my code looks like
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("mainContentPlaceHolder_dynamicContent_ctl00_RepeaterResultFoundTemplate_ResultFoundPlaceHolder_1_ctl00_1_ctl00_1_StandardPlaceHolderTop_3_ctl00_3_rptResults_3_res_0_btnAddToCart_0").InvokeMember("Click")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Navigate("http://www.gamestop.com/browse?nav=16k-3-wwii,28zu0")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("cartcheckoutbtn").InvokeMember("Click")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Document.GetElementById("buyasguest").InvokeMember("Click")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Document.GetElementById("ShipTo_FirstName").SetAttribute("value", "Rob")
WebBrowser1.Document.GetElementById("ShipTo_LastName").SetAttribute("value", "Horton")
WebBrowser1.Document.GetElementById("ShipTo_City").SetAttribute("value", "San Diego")
WebBrowser1.Document.GetElementById("USStates").InvokeMember("Select")
WebBrowser1.Document.GetElementById("ShipTo_Line1").SetAttribute("value", "9295 PebbleStone Ln")
WebBrowser1.Document.GetElementById("ShipTo_PostalCode").SetAttribute("value", "92128")
WebBrowser1.Document.GetElementById("ShipTo_PhoneNumber").SetAttribute("value", "6194682282")
For Each ee As HtmlElement In WebBrowser1.Document.All
If ee.InnerText Is Nothing Then Continue For
If ee.InnerText = "California" Then ee.SetAttribute("Selected", True)
Next
WebBrowser1.Document.GetElementById("ShipTo_EmailAddress").SetAttribute("value", TextBox1.Text)
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Im trying to click on this button and i inspect elemented it and this is what showed up **
(CONTINUE CHECKOUT ▶)
**
How Do I make it click this i tried Id but it has no id
btw im new to this just trying to make a auto web automation software to purchase games The code thats there when i inspect element it is on the top top top
You are actually trying to click a link and not an input button.
The link has an onclick attribute that contains javascript and returns false.
So you can either find that link or you can just execute the Javascript that the link executes submitshipto()
WebBrowser1.InvokeScript("submitshipto()")
Or:
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next
I edited my question and heres the whole code i used
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GradesDBDataSet.tblGrades' table. You can move, or remove it, as needed.
Me.TblGradesTableAdapter.Fill(Me.GradesDBDataSet.tblGrades)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TblGradesBindingSource.MoveNext()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
TblGradesBindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TblGradesBindingSource.MovePrevious()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TblGradesBindingSource.MoveLast()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TblGradesBindingSource.MoveFirst()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TblGradesBindingSource.AddNew()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
On Error GoTo saveErr
TblGradesBindingSource.EndEdit()
TblGradesTableAdapter.Update(GradesDBDataSet.tblGrades)
MsgBox("Record Save ", MsgBoxStyle.Information)
saveErr:
Exit Sub
End Sub
End Class
Hello Everyone... i have a problem using this code. . to save data to ms access from vb.net
i just follow a tutorial in youtube. it works BUT when i close the program then minutes later I run it again, data doesnt saved. . . Why? .
And can you suggest whats is the best way to Add, DELETE SAVE using vb.net? thanks eveyone ^_^
The most likely answer is that you are using a local data file that is overwritten each time you build.
Read this to learn how local data files are managed:
http://msdn2.microsoft.com/en-us/library/ms246989(VS.80).aspx
The solution in that case is to select the data file in the Solution Explorer, open the Properties window and set the Copy to output directory property to Copy if newer. The source file will only be copied to the output folder if you have changed that source file. That means that you can keep your test data between sessions.
I'm trying to add a new row to a DataGridView from FORM 2 but I can not succeed, the code I tried is as follows:
FORM 2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FORM1.invoice_items.Rows.Add()
End Sub
Looking like it took time but can not find a solution, someone who can help me with my problem would be nice, Thank You.
Try this
This work only if you use a showdialog.
Form 2 :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Pass the value to be added in the datagrid to form 1
Me.DialogResult=Windows.Forms.DialogResult.OK
End Sub
Form 1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form2.ShowDialog = Windows.Forms.DialogResult.OK Then
'Getthe value from form 2
invoice_items.Rows.Add()
End If
End Sub