Home All Groups Group Topic Archive Search About
Author
16 Aug 2006 10:57 PM
wandii
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

Author
16 Aug 2006 11:18 PM
Dennis
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston


Show quoteHide quote
"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
>
>
Author
17 Aug 2006 3:06 PM
wandii
Dennis wrote:
Show quoteHide quote
> 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
Author
18 Aug 2006 11:18 PM
Dennis
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


Show quoteHide quote
"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
>
>
Author
2 Sep 2006 11:27 PM
wandii
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
> >
> >
Author
3 Sep 2006 1:42 PM
Dennis
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
Author
5 Sep 2006 4:42 PM
wandii
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
Author
5 Sep 2006 8:36 PM
Dennis
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.
--
Dennis in Houston


Show quoteHide quote
"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
>
>