Context menu problem on RichTextBox

J

JJ

I'm trying to create the cut/paste/select all context menu on number of
richtextboxes.

On the contextmenu.popup handler, I want to find out what control is
currently displaying the context menu. I thought I could use:

Private Sub KL_ClipboardContMenu_Popup(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles KL_ClipboardContMenu.Popup
'To find out which control is displaying the context menu:
Try
Dim thisControl As Control = KL_ClipboardContMenu.SourceControl
Debug.WriteLine(thisControl.ToString)
Catch ex As Exception
Debug.WriteLine("oops!!!" & ex.Message)
End Try
end sub


- an exception if thrown if the control is a rich text box, and not a
textbox. How am I supposed to do this with a rich text box?

Thanks
 
J

JJ

Ah - I found this. Is there another way of getting the control that is
displaying the context menu?? :

"From your description, you would like to get the
ContextMenu.SourceControl when right click on the Richtextbox.
However, the SourceControl property isn't set by the RTB.

I made a test with a Picturebox and a RTB. When bringing up a
Contextmenu for Picturebox, it has correctly SourceControl set.
However, when bringing up a Contextmenu for RTB, it has nothing if
the first click on the RTB or it shows
System.Windows.Forms.PictureBox if you r_click firstly on the
picturebox then r_click on the RTB.

I checked our bug database. It is a known bug for the RTB. That is
because RichTextBox does not set SourceControl property when the
ContextMenu was brought up.

It is possible that this bug will be fixed in the next version of Visual
Studio, but I can't guarantee a resolution of this issue at this time.

thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top