Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy/paste with single context menu, multiple Rich Text and Text Boxes

Status
Not open for further replies.

ColdPhreze

Programmer
Apr 15, 2002
93
Ok, the subject says most of it. I have an app with multiple rich text boxes and multiple text boxes. I am using the copy, paste, selectall, and clear methods of the RTB and TB.

I have one context menu with the items Select All, Cut, Copy, Paste, and Clear. Following is the code I've attempted for the Select All. It only works in the text boxes. The problem is that the SourceControl of the context menu does NOT update when I use it with a Rich Text Box.

Code:
    Private Sub miSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miSelectAll.Click
        If contextmenu.SourceControl Is txtbox1 Then
            txtbox1.SelectAll()
        ElseIf contextmenu.SourceControl Is txtbox2 Then
            txtbox2.SelectAll()
        ElseIf contextmenu.SourceControl Is rtb1 Then
            rtb1.SelectAll()
        ElseIf contextmenu.SourceControl Is rtb2 Then
            rtb2.SelectAll()
        End If
    End Sub

That all said, I would really prefer to do something like follows so I don't have to code in every text box or RTB. However, the code proposed below does not work because the sender is the context menu, not the textbox or RTB. If you have a solution similar to below (but that actually works ;) ), I would much rather hear it than a solution to the SourceControl problem above.
Code:
    Private Sub miSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miSelectAll.Click
        sender.SelectAll()
    End Sub

Thanks in Advance,
KyferEz

Check out my DeVry Senior Project: and my CarPC Hardware: and my Spam-Fighter forums:
 
I think this will do what you want:

The CallByName function is used at runtime to get a property, set a property, or invoke a method

CallByName(ObjectRef, ProcName, UseCallType, Arg1)
 
techsmith, thank you! That is exactly what I wanted. I used it like this to do a select all:
CallByName(contextmenu.SourceControl, "SelectAll", CallType.Method)

However, I still have my original problem:
As I mentioned before, contextmenu.SourceControl does NOT update when I use the context menu in a rich text box. Instead it retains the previously accessed text box, and nothing happens in the Rich Text Box.

I did some research and found out that this is a known bug of VB .NET. The Rich Text Box does not set SourceControl property when the ContextMenu was brought up. GRRRR!

How can I possibly do what I need to do now???

Thank you,
KyferEz

Check out my DeVry Senior Project: and my CarPC Hardware: and my Spam-Fighter forums:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top