473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

TextBoxes, Context Menus, Copying and Pasting

(Apologies if I've missed the answer someplace else, but ... )

Is it possible in "intercept" the actions of the standard (Cut'n'Paste)
context menu provided by a TextBox (or derived class thereof) to
manipulate the data going to and/or from the Clipboard?

Short of completely recplacing the standard one with a Context
menu of my own, I can't find any way of doing this.

TIA,
Phill W.
Nov 21 '05 #1
1 1077

You can create a derived class and override the WndProc method

The code below will 'double' any code being cut/copied from the textbox
or pasted into it.
i.e.
If the textbox contains STRING and you cut/copy it and paste it else
where you will see STRINGSTRING in the new location.
if you copy VALUE from somewhere else and paste it, you will see
VALUEVALUE in the textbox.
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox

<< #Region " Windows Form Designer generated code ">>

Private Const WM_CUT As Long = &H300
Private Const WM_COPY As Long = &H301
Private Const WM_PASTE As Long = &H302

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)

Select Case m.Msg

Case WM_CUT

Clipboard.SetDataObject(Me.SelectedText +
Me.SelectedText)
Dim startSel As Integer = Me.SelectionStart
Dim startRemain As Integer = startSel +
Me.SelectionLength
Dim lenRemain As Integer = Me.Text.Length - startRemain

Dim strRemain As String = Me.Text.Substring(0,
startSel) + _

Me.Text.Substring(startRemain, lenRemain)

Me.Text = strRemain
Me.SelectionStart = startSel
Me.SelectionLength = 0
Case WM_COPY

Clipboard.SetDataObject(Me.SelectedText +
Me.SelectedText)
Case WM_PASTE

Dim data As IDataObject = Clipboard.GetDataObject()

Dim tmpData As String =
CStr(data.GetData(GetType(String)))
tmpData += tmpData

Me.Text = tmpData
Me.Select(Me.Text.Length, 0)

Case Else

MyBase.WndProc(m)

End Select

End Sub

End Class

Alan.

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rory | last post by:
I have an app that populates a treeview from an XML file. I want to create a few different context menus that pop up depending on which node is selected. I can get one context menu to appear when I...
2
by: Patryk | last post by:
Hi I'm making a web application which is a copy of existing desktop application. I use telerik controlls for MS visual studio I have a little bit complicated situation beacuse I need context...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
0
by: Andrew Baker | last post by:
Have a look at the code below. It's a really simple example where I have added two controls to a form, a textbox and a combo box. Both add owner drawn context menus to the controls, but the...
1
by: Rory | last post by:
Hi - I've seen quite a few posts that almost match this but haven't found a solution that works. I have an explorer-like application with a treeview in the lefthand pane. When I right-click on a...
0
by: Robert Smith | last post by:
Hello, I have written some context menus in my application, however I see lots of nice icons on the menus that microsoft use. It is not obvious how one would add these icons to the menu items....
1
by: bjaeger | last post by:
A few months back I was "playing" with an Access 2000 application I created. I somehow disabled the delete option from all menus, toolbars, and context menus. Now I cannot do any maintenance on...
0
by: tony.spalding | last post by:
I'm having a problem trying to add a link to my add-in to a context menu. I'm trying to add it to the context menu that you get when you right click on a stored procedure within the Server...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.