31/5000 mouse position is not right in webbrowser [closed] - vb.net

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have start to build a bot and i have try to get the mouse position store on a variable x and y and then wen i click start move the mouse to the location but wen i start the bot the location its not right.
How can i get the true position of it.
I have try like this but i cant get the correct position of mouse x,y inside of a webbrowser
I have made a gif image of the problem imgur link https://imgur.com/a/QQLQX
I have also edit my code and try a different way but i can not get the correct position
This is my code
Public Class Form1
Dim horas
Dim minutos
Dim segundos
Dim milesimos
Dim ratobutao
Dim tipoclick
Dim repetir
Dim currentelocal
Dim xmouse
Dim ymouse
Dim WithEvents htmldoc As HtmlDocument
Private Sub htmldoc_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseMove
'TextBox5.Text = e.MousePosition.X.ToString
'TextBox6.Text = e.MousePosition.Y.ToString
'xmouse = e.MousePosition.X.ToString
'ymouse = e.MousePosition.Y.ToString
End Sub
Private Sub htmldoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseDown
'xmouse = e.MousePosition.X.ToString
'ymouse = e.MousePosition.Y.ToString
'TextBox5.Text = e.MousePosition.X.ToString
'TextBox6.Text = e.MousePosition.Y.ToString
xmouse = Me.Width / WebBrowser1.Width
ymouse = Me.Height / WebBrowser1.Height
TextBox5.Text = e.MousePosition.X.ToString
TextBox6.Text = e.MousePosition.Y.ToString
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.google.com")
For Each c As Control In Controls
AddHandler c.MouseClick, AddressOf ClickHandler
Next
End Sub
Private Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
Select Case e.Button
Case MouseButtons.Left
MsgBox("left mouse")
TextBox5.Text = xmouse
TextBox6.Text = ymouse
Label2.Text = "Left"
Case MouseButtons.Right
Label2.Text = "Right"
Case MouseButtons.Middle
Label2.Text = "Middle"
Case Else
Label2.Text = "Some other button"
End Select
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
htmldoc = WebBrowser1.Document
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox5.Text = xmouse
TextBox6.Text = ymouse
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Windows.Forms.Cursor.Position = New Point(xmouse, ymouse)
Timer1.Stop()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.Start()
End Sub
End Class

When programming with graphical interfaces, there are three different coordinate sets you need to be aware of: Screen, Window, and Client. Different contexts provide coordinates from different areas. You need to know what type of coordinates you have, and how to convert between the others. This image illustrates:
In multi-monitor situations there may even be a fourth, to differentiate between a specific monitor and the entire desktop. Different windowing systems may also argue about what section counts as the client area, but the main thing is it's not the same as the others.
Figure out what coordinates you have in each situation in your code, and then look up how to convert between them.

In fact after to try many different ways to get it .
I have solve the mystery :)
It is easy but there not that many information out there about, and well English its not my native Language and the way i try to search maybe not that efficient.
But i get it work perfect.
This is the working code
Private Sub htmldoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseDown
xmouse = Control.MousePosition.X.ToString()
ymouse = Control.MousePosition.Y.ToString()
TextBox5.Text = xmouse
TextBox6.Text = ymouse
End Sub

Related

Use ComboBox to Display Specific ImageList

I have a program I created in VisualBasic that is very similar to a slideshow image viewer. On the left side the user is able to select an image from a location and display it. On the right side I would like them to be able to use the combo box to select a category which would only display images in that category.
I am currently able to get an image list loaded in the right side and the user can cycle through that list, but I am having trouble figuring out how to connect the combobox and imagelist. Maybe there is another route I should try?
Public Class Form1
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
btnPrev.Enabled = True
Static i As Integer
Dim incp As String
incp = +1
i += 1
PictureBox2.Image = ImageList1.Images(i)
If i = ImageList1.Images.Count - 1 Then
i = -1
End If
End Sub
Private Sub Btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
Static i As Integer
Dim incp As String
incp = +1
i += 1
PictureBox2.Image = ImageList1.Images(i)
If i = ImageList1.Images.Count - 1 Then
i = -incp
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
End Class
So you're saying that you have multiple ImageList objects and you want the user to select one using the ComboBox? If so then you do it like you would for selecting from any other list of objects using a ComboBox, e.g.
category1ImageList.Tag = "Category 1"
category2ImageList.Tag = "Category 2"
categoriesComboBox.DisplayMember = "Tag"
categoriesComboBox.DataSource = {category1ImageList, category2ImageList}
The user selects from the Tag values and then the SelectedItem of the ComboBox is the selected ImageList.

Trouble with displaying numbers in labels. Visual Basic

I am currently enrolled in a visual basic class through my university and I am having trouble with one of the exercises assigned to me. I need to display the cost of an item for a company and I cannot get anything to display in a label.
This is the code
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
Private Sub BtnCalc_Click(sender As Object, e As EventArgs) Handles BtnCalc.Click
Dim intCost As Double
If RadTwin.Checked Then
intCost = 39.99
ElseIf RadFull.Checked Then
intCost = 49.99
ElseIf RadQueen.Checked Then
intCost = 49.99
ElseIf RadKing.Checked Then
intCost = 69.99
End If
lblCost.Text = intCost.ToString("n")
End Sub
Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub RadTwin_CheckedChanged(sender As Object, e As EventArgs) Handles RadTwin.CheckedChanged
lblCost.Text = String.Empty
End Sub
Private Sub RadFull_CheckedChanged(sender As Object, e As EventArgs) Handles RadFull.CheckedChanged
lblCost.Text = String.Empty
End Sub
Private Sub RadQueen_CheckedChanged(sender As Object, e As EventArgs) Handles RadQueen.CheckedChanged
lblCost.Text = String.Empty
End Sub
Private Sub RadKing_CheckedChanged(sender As Object, e As EventArgs) Handles RadKing.CheckedChanged
lblCost.Text = String.Empty
End Sub
End Class
I need to display the cost of each item in the lblCost when the radio button is chosen. I have worked at getting this to work for hours but I am not knowledgeable enough to know what to do. If anyone has any ideas on how to make this code work I would greatly appreciate it. It is likely something stupid simple that I am missing but I want to learn how to solve this problem if it happens again in the future.

Using real time tooltip in VB.NET

Many developer can write real time tooltip for him self.
So, if you don't understanding my question, here is example
I want the tooltip following my cursor with smooth, can anybody tell me the code?
This will do what you asked for. As I said, you simply have to show the ToolTip yourself and not rely on the system to do it for you.
Private Sub Button1_MouseMove(sender As Object, e As MouseEventArgs) Handles Button1.MouseMove
Dim text = e.Location.ToString()
If text <> Me.ToolTip1.GetToolTip(Me.Button1) Then
Me.ToolTip1.Show(e.Location.ToString(), Me.Button1, New Point(e.X + 20, e.Y + 20))
End If
End Sub
Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave
Me.ToolTip1.Hide(Me.Button1)
End Sub
If you want the tooltip to follow the mouse, maybe use a timer and something like this
Public Class Form1
Private toolTipMsg As String = "Busy, Please Wait..." & vbCrLf & "Line2 Blah bla bla."
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ToolTip1.Active = True
ToolTip1.IsBalloon = False
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
' get cursor position
Dim cp = Cursor.Position
' offset Y so tooltip is under mouse
cp.Y += CInt(Cursor.Size.Height * 1.5)
' show tooltip
ToolTip1.Show(toolTipMsg, Me, PointToClient(cp))
End Sub

How to make a picturebox hide when dragged over another picturebox?

So I nailed the ability to drag a picturebox around the Windows form. I need it to hide itself when it's dragged and dropped over another picture. I've tried a few methods but none seem to work and I am now back at square one, the only code I have is so that I can move the picturebox around the form.
I Solved Your Problem
Here Is How The Form Should Look Like
And Here Is The Code I Made:
Private Sub CheckTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckTimer.Tick
CheckTimer.Stop()
CheckTimer.Interval = 1
If PictureBox2.Location = New System.Drawing.Point(TextBox1.Text, TextBox2.Text) Then
PictureBox2.Visible = False
End If
CheckTimer.Start()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = PictureBox1.Location.X
TextBox2.Text = PictureBox1.Location.Y
CheckTimer.Start()
End Sub
Hope This Code Was Helpful To You.
I made an better code than the old one, try it.
Here Is How The Form Should Look Like:
and here is the code :
Public Class Form1
Dim Point As New Point
Dim X, Y As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
Timer1.Interval = 1
Point = Cursor.Position
PictureBox2.Location = New System.Drawing.Point(Point.X - X, Point.Y - Y)
Timer1.Start()
End Sub
Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
X = Cursor.Position.X - PictureBox2.Location.X
Y = Cursor.Position.Y - PictureBox2.Location.Y
Timer1.Start()
End Sub
Private Sub PictureBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseUp
Timer1.Stop()
If PictureBox2.Location.X < PictureBox1.Size.Width Then
PictureBox2.Visible = False
End If
End Sub
End Class
I hope this code was useful to you.

Multiple Buttons keypad in VB.net

I have been battling with this for three days and asked a LOT of people the question, but maybe I'm asking it wrong. The project that I'm working , is to create a digital safe lock. I need to achieve the following:
I created a keypad with six buttons in a group box. When one click on the buttons, then the digit being clicked must be displayed in the listbox. As you press the rest (up to six digits max) the all have to be displayed in the listbox, next to each other in sequence like the way one will press the buttons on a calculator and then the listbox must display them in the same way. Here is whet I have figured out up to date:
Public Class Form1
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
If pinlst.Items.Count = 0 Then
pinlst.Items.Add(btn1.Text)
Else
pinlst.Items(0).SubItems.Add(btn1.Text)
End If
End Sub
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
If pinlst.Items.Count = 1 Then
pinlst.Items.Add(btn2.Text)
Else
pinlst.Items(1).SubItems.Add(btn2.Text)
End If
End Sub
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
If pinlst.Items.Count = 2 Then
pinlst.Items.Add(btn3.Text)
Else
pinlst.Items(2).SubItems.Add(btn3.Text)
End If
End Sub
Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
pinlst.Text = btn4.Text
End Sub
Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
pinlst.Text = btn5.Text
End Sub
Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
pinlst.Text = btn6.Text
End Sub
Private Sub btngp_Enter(sender As Object, e As EventArgs) Handles btngp.Enter
pinlst.Text = pinlst.Text & btn1.Text
pinlst.Text = pinlst.Text & btn2.Text
pinlst.Text = pinlst.Text & btn3.Text
pinlst.Text = pinlst.Text & btn4.Text
pinlst.Text = pinlst.Text & btn5.Text
pinlst.Text = pinlst.Text & btn6.Text
End Sub
End Class
It's best to assign every button to a character being pressed or a function being performed, in design time. For this to work, you need to have every button as a custom control, based off a regular button of course, exposing a property "CharPressed" or something like that. Then you can have a single static handler for all buttons, which you will wire dynamically in Sub New, after InitializeComponent. If this does not make sense, please feel free to ask a question in comments.