Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

Is there a way to inherit the textbox default context menu? I want to add a few items, like char count, etc.

 

Thanks,

Ronq.

  • 2 months later...
Posted
I also want to add to the default context menu of a textbox. Any suggestions?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted
Forget it - I duplicated the standard textbox context menu functionality in my own context menu.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted
Forget it - I duplicated the standard textbox context menu functionality in my own context menu.

 

Did you duplicated also the "Undo" function?? can you send me that code?

 

Bye,

Ronq.

  • *Experts*
Posted

You can use:

textBox1.Undo();

 

or

 

textBox1.Undo()

 

For the record, it's probably easier to make your own menu from scratch. I suppose you could try and subclass the window itself with a LOT of work and add your own menu items. But creating the new menu yourself in an hour or two seems easier.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Adding to Nerseus's statement of programming your own context menu, here's a simple context menu example:

 

   Private Sub CmnuMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   CmnuUndo.Click, CmnuCut.Click, CmnuCopy.Click, CmnuPaste.Click, CmnuExit.Click

       Select Case DirectCast(sender, MenuItem).Text
           Case "Undo"
               DirectCast(Me.ActiveControl, TextBox).Undo()
           Case "Cut"
               DirectCast(Me.ActiveControl, TextBox).Cut()
           Case "Copy"
               DirectCast(Me.ActiveControl, TextBox).Copy()
           Case "Paste"
               Dim data As IDataObject = Clipboard.GetDataObject()
               If (data.GetDataPresent(DataFormats.Text)) Then
                   DirectCast(Me.ActiveControl, TextBox).Paste()
               End If
           Case "Exit"
               Me.Close()
       End Select
   End Sub

 

Hopefully that will cut the time down a bit.

Dan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Thank you very much... that code is great, that's exactly what i needed....

two months ago... :p just kiding.

 

I can still use it! Thanks again..

 

Bye,

Ronq.

Posted

In case your interested, my menu has the following items:

 

        myMenu.MenuItems.Add("Undo", AddressOf MenuClickHandler)
       myMenu.MenuItems.Add("-")
       myMenu.MenuItems.Add("Cut", AddressOf MenuClickHandler)
       myMenu.MenuItems.Add("Copy", AddressOf MenuClickHandler)
       myMenu.MenuItems.Add("Paste", AddressOf MenuClickHandler)
       myMenu.MenuItems.Add("-")
       myMenu.MenuItems.Add("Select All", AddressOf MenuClickHandler)

 

 

I've also used the following code to enable/disable the different options on the context menu:

 

    Private Sub txtEdit_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtEdit.MouseDown
       If e.Button = MouseButtons.Right Then
           txtEdit.ContextMenu.MenuItems(0).Enabled = txtEdit.CanUndo
           txtEdit.ContextMenu.MenuItems(2).Enabled = txtEdit.SelectionLength > 0
           txtEdit.ContextMenu.MenuItems(3).Enabled = txtEdit.SelectionLength > 0
           txtEdit.ContextMenu.MenuItems(4).Enabled = Clipboard.GetDataObject.GetDataPresent("System.String", True)
           txtEdit.ContextMenu.MenuItems(6).Enabled = txtEdit.TextLength <> txtEdit.SelectionLength
       End If
   End Sub

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...