RonQ Posted January 5, 2004 Posted January 5, 2004 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. Quote
TechnoTone Posted March 15, 2004 Posted March 15, 2004 I also want to add to the default context menu of a textbox. Any suggestions? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
TechnoTone Posted March 15, 2004 Posted March 15, 2004 Forget it - I duplicated the standard textbox context menu functionality in my own context menu. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
RonQ Posted March 15, 2004 Author Posted March 15, 2004 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. Quote
*Experts* Nerseus Posted March 15, 2004 *Experts* Posted March 15, 2004 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 Quote "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* DiverDan Posted March 15, 2004 *Experts* Posted March 15, 2004 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 Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
RonQ Posted March 15, 2004 Author Posted March 15, 2004 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. Quote
TechnoTone Posted March 16, 2004 Posted March 16, 2004 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 Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.