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
Related
I'm trying to make a tableLayoutPanel by code in Windows Form VB which can later be coded to add on extra rows and columns also by coding
When the form starts:
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _MyBase.Load
Dim TLP As New TableLayoutPanel
'Edit all your properties: name, size, location, etc.
End Sub
Say when you click a button1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Controls.Add(TLP)
End Sub
Hope that helps.
I have some farmiliaraty with VB.net, but as of yeaterday only 1 day experiance with DevExpress. The functions seam quite easy but the occasional question is bound to pop-up.
My first question is:
How can I create a toggel button which toggels the timer on or off using the DevExpress "Check button" control. the code I have currently in use will only stop my timmer but not restart it when I click my Checkbutton control a second time?
Private Sub CheckButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckButton1.CheckedChanged
If True Then
Timer1.Stop()
Else
Timer1.Start()
End If
End Sub
Just use the CheckButton.Checked property as follows:
Private Sub CheckButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckButton1.CheckedChanged
If CheckButton1.Checked Then
Timer1.Stop()
Else
Timer1.Start()
End If
End Sub
I'm trying to view youtube captcha in my vb application but I don't know how to refresh/redraw the picture box. The youtube captcha is in http://www.youtube.com/cimg and the captcha is changing everytime I refresh the page. How can I do that using button or timer in vb.net to change the captcha. Here is the code I used to load the captcha to picturebox.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
i try to use captchaBox.Refresh() but it's not working. I hope someone can help me. thx
Refresh just redraws the control, it doesn't retrieve the image again. You need to reset the ImageLocation property for it to work. For example with a timer:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
captchaBox.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Try this:
Private Sub Form1_Load() Handles MyBase.Load
Timer1.Start()
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Image = Nothing
PictureBox1.ImageLocation = "http://www.youtube.com/cimg"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser.Show()
WebBrowser.WebBrowser1.Navigate("www.carsonmap.com/hidalgo/login.cfm")
WebBrowser.WebBrowser1.Document.GetElementById("UserName").SetAttribute("value", "lrgvdc")
WebBrowser.WebBrowser1.Document.GetElementById("PW").SetAttribute("value", WebBrowser.TextBox2.Text)
End Sub
I need help with this code I keep getting an error saying Null Reference.
I got the idea from this Youtube Video check out to see what I am trying to accomplish.
https://www.youtube.com/watch?v=9EJXzWasTq4&list=PL42055376AE25291E&index=41
They used two buttons to enter to the website I am trying to enter to a website By using one button any ideas why doesnt it work.
When you use WebBrowser1.Navigate - it just begins to load document, the document is not available right away.
You need to use WebBrowser.DocumentCompleted Event to place your code that works on document's elements. E.g. something like
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser.Show()
WebBrowser.WebBrowser1.Navigate("www.carsonmap.com/hidalgo/login.cfm")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser.WebBrowser1.Document.GetElementById("UserName").SetAttribute("value", "lrgvdc")
WebBrowser.WebBrowser1.Document.GetElementById("PW").SetAttribute("value", WebBrowser.TextBox2.Text)
End Sub
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