|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ContextMenuI am trying to show the shortcut menu on a richtextbox control by adding the contextmenu component onto the form. The richtextbox property is assigned to the contextmenu. I created my shorcuts, copy, paste, etc. However, on the form I have a datagrid which is also assigned to the same contextmenu and contextmenupopup event as follows: .... If ContextMenu1.SourceControl Is richtextbox1Then ' Add MenuItems to display for the TextBox. ContextMenu1.MenuItems.Add(menuItem1) ContextMenu1.MenuItems.Add(menuItem2) ElseIf ContextMenu1.SourceControl Is datagrid1 Then ' Add the MenuItem ContextMenu1.MenuItems.Add(menuItem3) End If .... when I right-click on the richtext control I get the sourcecontrol = Nothing, but r-click on grid i get the control name. I droped the richtext control and added another one and set the cmenu property and still nothing. Any idea? Thanks in advance Need some more code, like the event handler sub declaration and what it
handles. -- Show quoteHide quoteDennis in Houston "wandii" wrote: > Hi, > I am trying to show the shortcut menu on a richtextbox control by > adding the contextmenu component onto the form. The richtextbox > property is assigned to the contextmenu. I created my shorcuts, copy, > paste, etc. However, on the form I have a datagrid > which is also assigned to the same contextmenu and contextmenupopup > event as follows: > .... > If ContextMenu1.SourceControl Is richtextbox1Then > ' Add MenuItems to display for the TextBox. > ContextMenu1.MenuItems.Add(menuItem1) > ContextMenu1.MenuItems.Add(menuItem2) > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > ' Add the MenuItem > ContextMenu1.MenuItems.Add(menuItem3) > End If > .... > when I right-click on the richtext control I get the sourcecontrol = > Nothing, but r-click on grid > i get the control name. I droped the richtext control and added another > one and set the > cmenu property and still nothing. Any idea? > > Thanks in advance > > Dennis wrote:
Show quoteHide quote > Need some more code, like the event handler sub declaration and what it Thanks for your time Dennis. Here you go... I have the property of> handles. > -- > Dennis in Houston > > > "wandii" wrote: > > > Hi, > > I am trying to show the shortcut menu on a richtextbox control by > > adding the contextmenu component onto the form. The richtextbox > > property is assigned to the contextmenu. I created my shorcuts, copy, > > paste, etc. However, on the form I have a datagrid > > which is also assigned to the same contextmenu and contextmenupopup > > event as follows: > > .... > > If ContextMenu1.SourceControl Is richtextbox1Then > > ' Add MenuItems to display for the TextBox. > > ContextMenu1.MenuItems.Add(menuItem1) > > ContextMenu1.MenuItems.Add(menuItem2) > > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > > ' Add the MenuItem > > ContextMenu1.MenuItems.Add(menuItem3) > > End If > > .... > > when I right-click on the richtext control I get the sourcecontrol = > > Nothing, but r-click on grid > > i get the control name. I droped the richtext control and added another > > one and set the > > cmenu property and still nothing. Any idea? > > > > Thanks in advance > > > > datagrid and richtext are assigned to contextmenu. Works fine for the datagrid and I get nothing for the rtext. Thanks Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup ' Define the MenuItem objects to display for the TextBox. Dim menuItem1 As New MenuItem("&Copy") Dim menuItem2 As New MenuItem("&Find and Replace") ' Define the MenuItem object to display for the PictureBox. Dim menuItem3 As New MenuItem("C&hange Picture") ' Clear all previously added MenuItems. ContextMenu1.MenuItems.Clear() If ContextMenu1.SourceControl Is richtextbox1Then ' Add MenuItems to display for the TextBox. ContextMenu1.MenuItems.Add(menuItem1) ContextMenu1.MenuItems.Add(menuItem2) ElseIf ContextMenu1.SourceControl Is datagrid1 Then ' Add the MenuItem to display for the PictureBox. ContextMenu1.MenuItems.Add(menuItem3) End If Your code looks fine. Are you able to type information into the richtextbox
to be sure it can get the focus? Also, does the contextmenu1 appear when you right click on the richtextbox? -- Show quoteHide quoteDennis in Houston "wandii" wrote: > > Dennis wrote: > > Need some more code, like the event handler sub declaration and what it > > handles. > > -- > > Dennis in Houston > > > > > > "wandii" wrote: > > > > > Hi, > > > I am trying to show the shortcut menu on a richtextbox control by > > > adding the contextmenu component onto the form. The richtextbox > > > property is assigned to the contextmenu. I created my shorcuts, copy, > > > paste, etc. However, on the form I have a datagrid > > > which is also assigned to the same contextmenu and contextmenupopup > > > event as follows: > > > .... > > > If ContextMenu1.SourceControl Is richtextbox1Then > > > ' Add MenuItems to display for the TextBox. > > > ContextMenu1.MenuItems.Add(menuItem1) > > > ContextMenu1.MenuItems.Add(menuItem2) > > > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > > > ' Add the MenuItem > > > ContextMenu1.MenuItems.Add(menuItem3) > > > End If > > > .... > > > when I right-click on the richtext control I get the sourcecontrol = > > > Nothing, but r-click on grid > > > i get the control name. I droped the richtext control and added another > > > one and set the > > > cmenu property and still nothing. Any idea? > > > > > > Thanks in advance > > > > > > > > Thanks for your time Dennis. Here you go... I have the property of > datagrid and richtext > are assigned to contextmenu. Works fine for the datagrid and I get > nothing for the rtext. Thanks > > Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal > e As System.EventArgs) Handles ContextMenu1.Popup > > ' Define the MenuItem objects to display for the TextBox. > Dim menuItem1 As New MenuItem("&Copy") > Dim menuItem2 As New MenuItem("&Find and Replace") > ' Define the MenuItem object to display for the PictureBox. > Dim menuItem3 As New MenuItem("C&hange Picture") > > ' Clear all previously added MenuItems. > ContextMenu1.MenuItems.Clear() > > If ContextMenu1.SourceControl Is richtextbox1Then > ' Add MenuItems to display for the TextBox. > ContextMenu1.MenuItems.Add(menuItem1) > ContextMenu1.MenuItems.Add(menuItem2) > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > ' Add the MenuItem to display for the PictureBox. > ContextMenu1.MenuItems.Add(menuItem3) > End If > > Sorry Dennis I could not get back to you soon. Yes I tried to setfocus
to richtext on form load and can type into richtext, however, no contextmenu appears when I r-click on it. I put a breakpoint please see below: > > bp> > If ContextMenu1.SourceControl Is richtextbox1Then ' Add MenuItems to display for the TextBox.ContextMenu1.MenuItems.Add(menuItem1) ContextMenu1.MenuItems.Add(menuItem2) ElseIf ContextMenu1.SourceControl Is datagrid1 Then ' Add the MenuItem ContextMenu1.MenuItems.Add(menuItem3) End If and sourcecontrol is nothing. Plan B: deleted the old richtext control and added a new one still sourcecontrol is nothing. I tried on a button, datagrid and sourcecontrol is not null. Richtext's contextmenu property is to the contextmenu2. This is very strange? I am not sure if I need to set another property. Any other suggestions. Thanks Dennis wrote: Show quoteHide quote > Your code looks fine. Are you able to type information into the richtextbox > to be sure it can get the focus? Also, does the contextmenu1 appear when you > right click on the richtextbox? > -- > Dennis in Houston > > > "wandii" wrote: > > > > > Dennis wrote: > > > Need some more code, like the event handler sub declaration and what it > > > handles. > > > -- > > > Dennis in Houston > > > > > > > > > "wandii" wrote: > > > > > > > Hi, > > > > I am trying to show the shortcut menu on a richtextbox control by > > > > adding the contextmenu component onto the form. The richtextbox > > > > property is assigned to the contextmenu. I created my shorcuts, copy, > > > > paste, etc. However, on the form I have a datagrid > > > > which is also assigned to the same contextmenu and contextmenupopup > > > > event as follows: > > > > .... > > > > If ContextMenu1.SourceControl Is richtextbox1Then > > > > ' Add MenuItems to display for the TextBox. > > > > ContextMenu1.MenuItems.Add(menuItem1) > > > > ContextMenu1.MenuItems.Add(menuItem2) > > > > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > > > > ' Add the MenuItem > > > > ContextMenu1.MenuItems.Add(menuItem3) > > > > End If > > > > .... > > > > when I right-click on the richtext control I get the sourcecontrol = > > > > Nothing, but r-click on grid > > > > i get the control name. I droped the richtext control and added another > > > > one and set the > > > > cmenu property and still nothing. Any idea? > > > > > > > > Thanks in advance > > > > > > > > > > > > Thanks for your time Dennis. Here you go... I have the property of > > datagrid and richtext > > are assigned to contextmenu. Works fine for the datagrid and I get > > nothing for the rtext. Thanks > > > > Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal > > e As System.EventArgs) Handles ContextMenu1.Popup > > > > ' Define the MenuItem objects to display for the TextBox. > > Dim menuItem1 As New MenuItem("&Copy") > > Dim menuItem2 As New MenuItem("&Find and Replace") > > ' Define the MenuItem object to display for the PictureBox. > > Dim menuItem3 As New MenuItem("C&hange Picture") > > > > ' Clear all previously added MenuItems. > > ContextMenu1.MenuItems.Clear() > > > > If ContextMenu1.SourceControl Is richtextbox1Then > > ' Add MenuItems to display for the TextBox. > > ContextMenu1.MenuItems.Add(menuItem1) > > ContextMenu1.MenuItems.Add(menuItem2) > > ElseIf ContextMenu1.SourceControl Is datagrid1 Then > > ' Add the MenuItem to display for the PictureBox. > > ContextMenu1.MenuItems.Add(menuItem3) > > End If > > > > Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles ContextMenu1.Popup ' Define the MenuItem objects to display for the TextBox. Dim menuItem1 As New MenuItem("&Copy") Dim menuItem2 As New MenuItem("&Find and Replace") ' Define the MenuItem object to display for the PictureBox. Dim menuItem3 As New MenuItem("C&hange Picture") ' Clear all previously added MenuItems. ContextMenu1.MenuItems.Clear() If Sender Is richtextbox1Then ' Add MenuItems to display for the TextBox. ContextMenu1.MenuItems.Add(menuItem1) ContextMenu1.MenuItems.Add(menuItem2) ElseIf Sender Is datagrid1 Then ' Add the MenuItem to display for the PictureBox. ContextMenu1.MenuItems.Add(menuItem3) End If -- Dennis in Houston Nope - didn't work. The reason is that the sender listed below is
looking at the contextmenu (1, 2, ...) controls. Dennis wrote: Show quoteHide quote > Try this code (note the "sender" in the if statments: > > > Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _ > e As System.EventArgs) Handles ContextMenu1.Popup > > ' Define the MenuItem objects to display for the TextBox. > Dim menuItem1 As New MenuItem("&Copy") > Dim menuItem2 As New MenuItem("&Find and Replace") > ' Define the MenuItem object to display for the PictureBox. > Dim menuItem3 As New MenuItem("C&hange Picture") > > ' Clear all previously added MenuItems. > ContextMenu1.MenuItems.Clear() > > If Sender Is richtextbox1Then > ' Add MenuItems to display for the TextBox. > ContextMenu1.MenuItems.Add(menuItem1) > ContextMenu1.MenuItems.Add(menuItem2) > ElseIf Sender Is datagrid1 Then > ' Add the MenuItem to display for the PictureBox. > ContextMenu1.MenuItems.Add(menuItem3) > End If > > -- > Dennis in Houston Sorry, I don't know what to try next. Are you sure you spelled the name of
the richtext box correctly? You might want to add a second contextmenu dedicated to your richtextbox. -- Show quoteHide quoteDennis in Houston "wandii" wrote: > Nope - didn't work. The reason is that the sender listed below is > looking at the contextmenu (1, 2, ...) controls. > > > Dennis wrote: > > Try this code (note the "sender" in the if statments: > > > > > > Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _ > > e As System.EventArgs) Handles ContextMenu1.Popup > > > > ' Define the MenuItem objects to display for the TextBox. > > Dim menuItem1 As New MenuItem("&Copy") > > Dim menuItem2 As New MenuItem("&Find and Replace") > > ' Define the MenuItem object to display for the PictureBox. > > Dim menuItem3 As New MenuItem("C&hange Picture") > > > > ' Clear all previously added MenuItems. > > ContextMenu1.MenuItems.Clear() > > > > If Sender Is richtextbox1Then > > ' Add MenuItems to display for the TextBox. > > ContextMenu1.MenuItems.Add(menuItem1) > > ContextMenu1.MenuItems.Add(menuItem2) > > ElseIf Sender Is datagrid1 Then > > ' Add the MenuItem to display for the PictureBox. > > ContextMenu1.MenuItems.Add(menuItem3) > > End If > > > > -- > > Dennis in Houston > >
VB.NET Express speed issue
Newbie and 2005 Concurrecny Reading Items in an ArrayList SQL query to Excel file Wait for all ThreadPool workers to complete MS Access Reports and VB.NET Program RE: TO LEARN PROGRAMMING Desktop Application Culture Setting VB 2005 Email Programming Preventing button code being run twice |
|||||||||||||||||||||||