473,394 Members | 1,717 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,394 software developers and data experts.

Source object on right click

In VB 2005 I have six seperately named picture boxes (arranged in a table
layout control) in which I plot different X/Y data lines. I would like to be
able to right-click on a specific picture box (say, plot #3) and select a
different line color for that one plot.

How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't know which plot to apply to color change to. The
'sender' object does not give me any info from which picture box the click
event originated.

thanks
Jun 22 '06 #1
5 2098
I can think of two ways to do this:

To have a context menu for each picturebox and use the tag property to
write the name of the corresponding picturebox.

or

have one shared context menu among them. Handle the click event of that
menu item. cast the sender to a menu item and menuitem.owner is the
context menu. Now, you can get the location of the context menu and
compare it to the location of the picturebox. ie

if contextmenu.left > picturebox1.left and contextmenu.left <
picturebox1.right and contextmenu.top> picturebox1.top and
contextmenu.top < picturebox1.bottom then
' the right click was over picturebox1
else if ....

end if

I prefer the second way.

Ahmed
wxnut wrote:
In VB 2005 I have six seperately named picture boxes (arranged in a table
layout control) in which I plot different X/Y data lines. I would like to be
able to right-click on a specific picture box (say, plot #3) and select a
different line color for that one plot.

How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't know which plot to apply to color change to. The
'sender' object does not give me any info from which picture box the click
event originated.

thanks


Jun 23 '06 #2
Just tought of a third way,

You can handle the onenter event for each picture box. and once the
mouse enters the picture box you set a variable to the name of the
picture box ie
Private mouse As String

Private Sub NameToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NameToolStripMenuItem.Click
MsgBox(mouse)
End Sub
Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e
As System.EventArgs) Handles PictureBox1.MouseEnter
mouse = CType(sender.name, PictureBox).Name
End Sub
wxnut wrote:
In VB 2005 I have six seperately named picture boxes (arranged in a table
layout control) in which I plot different X/Y data lines. I would like to be
able to right-click on a specific picture box (say, plot #3) and select a
different line color for that one plot.

How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't know which plot to apply to color change to. The
'sender' object does not give me any info from which picture box the click
event originated.

thanks


Jun 23 '06 #3
wxnut wrote:
How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't know which plot to apply to color change to. The
'sender' object does not give me any info from which picture box the click
event originated.


Do all 6 picture boxes share the same click method? If so, then the
sender is the picture box that was clicked. You just need to check
which one it is by casting the sender to PictureBox:

Dim pb As PictureBox = DirectCast(sender, PictureBox)

Or use the 'is' operator:

If sender is PictureBox1 Then
'do something
End If

Jun 23 '06 #4
Your code won't work. The sender is not the picturebox in this case
because he is using a contextmenu. The sender would be a menuitem.

Chris Dunaway wrote:
wxnut wrote:
How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't know which plot to apply to color change to. The
'sender' object does not give me any info from which picture box the click
event originated.


Do all 6 picture boxes share the same click method? If so, then the
sender is the picture box that was clicked. You just need to check
which one it is by casting the sender to PictureBox:

Dim pb As PictureBox = DirectCast(sender, PictureBox)

Or use the 'is' operator:

If sender is PictureBox1 Then
'do something
End If


Jun 23 '06 #5
Ahmed wrote:
Your code won't work. The sender is not the picturebox in this case
because he is using a contextmenu. The sender would be a menuitem.


The ContextMenu class has a SourceControl property which tells which
control the menu was invoked against. That should tell which picture
box the menu was clicked on.

Jun 26 '06 #6

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

Similar topics

8
by: Nancy | last post by:
Hi, Guys, I don't know why I can't view some webpages source code by click "View->Source" menu of Browser. These webpage source code can be viewed in same way by using other computers. My OS is...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
5
by: rogsonl | last post by:
My computer was moved last week, and the company changed the network groups we work on. As a result, one of the main benefits from Whidbey (database connectivity) no longer works. Situation: 1....
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
2
by: Crimson* | last post by:
I've got a table with an entry type as "OLE Object" in Access 2003. In the form that the table is linked to I want to insert an image (BMP) for each record. However, when I attempt to do so the...
2
by: DBC User | last post by:
I have a project staged in source safe. What is the right way to open the project from source safe and get all the depended files on to my local pc? I do not have the project locally in my PC. I am...
12
by: mistral | last post by:
Can anybody tell me how to get source code of page in iframe? (popup window is clickable image). When I right click on this popup border to view source, i see just as follows <html> <head>...
1
by: Coderer | last post by:
I have a project that I've been working on for a while, where several forms use DataGridViews to represent database information. The forms are .NET 2.0, in Studio 2005. For the past couple of...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.