473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why Isn't My Mouse Click Code Working

I have the following code and it returns the x and y coordinates in the text
box, but when I click the mouse on say 362,61 does not bring up form2.Any
suggestions?
Thanks,
Jerry

Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
TextBox1.Text = e.X
TextBox2.Text = e.Y
If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
Form2.Show()
Me.Hide()
End If
End Sub

May 20 '07 #1
3 1772
What are you trying to do with this line of code:

If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
...............
End If

IMO, a code like that should not get complied, but, well, it is VB and it
simply does too much on user's behalf sometimes, so that user was fooled on
what is wrong. In this case, if VB does not do the implicit type conversion,
then you cannot compare TextBox.Text to a non-string value, so that you know
what is wrong.

Since the code seems compiled, then VB actually does is, first compares
341>553, it gets "False", then VB compares TextBox1.Text to False, the
result is False; the same for the next part. The overall result for the
"If..." statement would be False, so, you would never get Form2.Show() to
run.

VB's such behaviour IMO, is doing too much on user's behalf, that is one
reason one should give up VB.NET for C#.
"Jerry" <Je***@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
>I have the following code and it returns the x and y coordinates in the
text
box, but when I click the mouse on say 362,61 does not bring up form2.Any
suggestions?
Thanks,
Jerry

Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
TextBox1.Text = e.X
TextBox2.Text = e.Y
If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
Form2.Show()
Me.Hide()
End If
End Sub

May 20 '07 #2
What my ultimate goal is to have my mouse click on a part of the picture box
top left location 341,22/bottom left location 341,48/top right location
553,22/bottom right location 553,148 and to have the program detect if the
mouse click was anywhere in the square, if so load form2
Thanks,
Jerry

"Norman Yuan" wrote:
What are you trying to do with this line of code:

If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
...............
End If

IMO, a code like that should not get complied, but, well, it is VB and it
simply does too much on user's behalf sometimes, so that user was fooled on
what is wrong. In this case, if VB does not do the implicit type conversion,
then you cannot compare TextBox.Text to a non-string value, so that you know
what is wrong.

Since the code seems compiled, then VB actually does is, first compares
341>553, it gets "False", then VB compares TextBox1.Text to False, the
result is False; the same for the next part. The overall result for the
"If..." statement would be False, so, you would never get Form2.Show() to
run.

VB's such behaviour IMO, is doing too much on user's behalf, that is one
reason one should give up VB.NET for C#.
"Jerry" <Je***@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I have the following code and it returns the x and y coordinates in the
text
box, but when I click the mouse on say 362,61 does not bring up form2.Any
suggestions?
Thanks,
Jerry

Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
TextBox1.Text = e.X
TextBox2.Text = e.Y
If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
Form2.Show()
Me.Hide()
End If
End Sub


May 20 '07 #3
So, the code wuold look like
Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick

If e.X >= 341 AND e.X <= 553 And e.Y >= 22 AND e.Y <= 148 Then

TextBox1.Text=e.X.ToString()
TextBox2.Text=e.Y.ToString()

Form2.Show()
Me.Hide()

End If
End Sub
"Jerry" <Je***@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
What my ultimate goal is to have my mouse click on a part of the picture
box
top left location 341,22/bottom left location 341,48/top right location
553,22/bottom right location 553,148 and to have the program detect if the
mouse click was anywhere in the square, if so load form2
Thanks,
Jerry

"Norman Yuan" wrote:
>What are you trying to do with this line of code:

If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
...............
End If

IMO, a code like that should not get complied, but, well, it is VB and it
simply does too much on user's behalf sometimes, so that user was fooled
on
what is wrong. In this case, if VB does not do the implicit type
conversion,
then you cannot compare TextBox.Text to a non-string value, so that you
know
what is wrong.

Since the code seems compiled, then VB actually does is, first compares
341>553, it gets "False", then VB compares TextBox1.Text to False, the
result is False; the same for the next part. The overall result for the
"If..." statement would be False, so, you would never get Form2.Show() to
run.

VB's such behaviour IMO, is doing too much on user's behalf, that is one
reason one should give up VB.NET for C#.
"Jerry" <Je***@discussions.microsoft.comwrote in message
news:7A**********************************@microso ft.com...
>I have the following code and it returns the x and y coordinates in the
text
box, but when I click the mouse on say 362,61 does not bring up
form2.Any
suggestions?
Thanks,
Jerry

Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y
TextBox1.Text = e.X
TextBox2.Text = e.Y
If TextBox1.Text = 341 553 And TextBox2.Text = 22 148 Then
Form2.Show()
Me.Hide()
End If
End Sub



May 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Csaba2000 | last post by:
I have set onmousedown to change the cursor, but this setting is ignored (IE 5.5; NN 6.1 on Win 2K Pro) until the mouse is either moved or the mouse button is released. On Opera 7.01, the setting...
9
by: punkin | last post by:
I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. My code only works for IEs but not any Netscape or Gecko-based browsers. The...
4
by: masantha wee | last post by:
Hi all, I am using Firefox and embedding Javascript in html. I understand that we can use mouse events by coding them in the body of html (by creating a button or anything and by adding in the...
3
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events....
2
by: KarenP | last post by:
In my Windows Forms application, while executing a process that takes some time, I am changing the cursor to the hourglass by setting Cursor.Current = Cursors.WaitCursor. This is working just...
0
by: 6tc1 | last post by:
Hi all, I've got a UserControl that contains a few PictureBox objects. If I click on outside of the Picture in the UserControl, the scrolling with the mouse button works - however, no amount of...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
3
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim...
4
by: flplini | last post by:
I want to ask how to use C++ to simulate the mouse control? ex:Let the mouse double-click the left key functions,thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.