PC Review


Reply
Thread Tools Rate Thread

How Do I? Determine Which Button was Right-Clicked, Pass to ContextMenu

 
 
Patrick A
Guest
Posts: n/a
 
      13th Nov 2009
All,

I am using the code below (started from a sample from this group,
I think) to programmatically create a series of buttons in a vertical
strip on a form on Form Open.

I have a context menu which appears when the user right-clicks any
button on the form.

How do I "tell" the context menu (really a function on the context
menu) which button was right-clicked? I know how to get button
attributes when the user left-clicks...but that's not what I need...

Is there a way to do this?

Thanks,

Patrick


Code::: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :


Me.QRY_ButtonsTableAdapter.Fill(Me.SRTimerDataSet.QRY_Buttons)
Dim Row As Integer = 0
Dim ButLbls = SRTimerDataSet.Tables
("QRY_Buttons").AsEnumerable
()
Dim sortedButLbls = From tp In ButLbls _
Select tp _
Order By tp("TimerPos")
For Each tp In sortedButLbls
Row = Row + 1 'Increment up.
Dim NewButton As New MyButton() ' Sets a new button
NewButton.Width = 123 ' Sets the width.
NewButton.Height = 42 ' Sets the height.
NewButton.Top = 1 + (42 * Row - 1) ' Positions the top
of the button.
Me.Controls.Add(NewButton) 'Adds the new button to the
form.
NewButton.Name = (tp!TimerPos)
NewButton.Text = (tp!butLabel)
AddHandler NewButton.Click, AddressOf ButtonResponder
oTimeSliceCollection.Add(NewButton, tp
("TimerPos").ToString)
Next

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      13th Nov 2009
As explained in the dotnet.framework group reply:

Create one common event handler that handles the mousedown (not click) event
for each
of the buttons that has a context menu.

In that event handler, simply cast the sender argument to the button type
and you will be able to use sender as a reference to the actual button that
fired the mousedown event in the first place. You can then access the Name
property of the button via the sender reference and use that in a Select
(VB) or switch (C#) block to act accordingly.

-Scott



"Patrick A" <(E-Mail Removed)> wrote in message
news:4f9fd93d-c97c-4bc0-b7f9-(E-Mail Removed)...
> All,
>
> I am using the code below (started from a sample from this group,
> I think) to programmatically create a series of buttons in a vertical
> strip on a form on Form Open.
>
> I have a context menu which appears when the user right-clicks any
> button on the form.
>
> How do I "tell" the context menu (really a function on the context
> menu) which button was right-clicked? I know how to get button
> attributes when the user left-clicks...but that's not what I need...
>
> Is there a way to do this?
>
> Thanks,
>
> Patrick
>
>
> Code::: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
> :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :
>
>
> Me.QRY_ButtonsTableAdapter.Fill(Me.SRTimerDataSet.QRY_Buttons)
> Dim Row As Integer = 0
> Dim ButLbls = SRTimerDataSet.Tables
> ("QRY_Buttons").AsEnumerable
> ()
> Dim sortedButLbls = From tp In ButLbls _
> Select tp _
> Order By tp("TimerPos")
> For Each tp In sortedButLbls
> Row = Row + 1 'Increment up.
> Dim NewButton As New MyButton() ' Sets a new button
> NewButton.Width = 123 ' Sets the width.
> NewButton.Height = 42 ' Sets the height.
> NewButton.Top = 1 + (42 * Row - 1) ' Positions the top
> of the button.
> Me.Controls.Add(NewButton) 'Adds the new button to the
> form.
> NewButton.Name = (tp!TimerPos)
> NewButton.Text = (tp!butLabel)
> AddHandler NewButton.Click, AddressOf ButtonResponder
> oTimeSliceCollection.Add(NewButton, tp
> ("TimerPos").ToString)
> Next
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine which button was clicked dhstein Microsoft Access 3 19th Feb 2009 02:21 AM
Re: Determine which button was clicked on a sheet Norman Jones Microsoft Excel Programming 1 4th Jan 2007 02:54 PM
How do I determine which button was clicked dbuchanan Microsoft Dot NET Framework Forms 8 15th Nov 2005 05:09 PM
Determine if X Button was Clicked John Smith Microsoft C# .NET 1 29th Jul 2005 12:16 AM
how to determine which item of a contextmenu within a form was clicked? Karl-thomas.schmidt@web.de Microsoft Excel Programming 1 12th Mar 2004 04:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:00 AM.