473,779 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1092

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.SetDa taObject(Me.Sel ectedText +
Me.SelectedText )
Dim startSel As Integer = Me.SelectionSta rt
Dim startRemain As Integer = startSel +
Me.SelectionLen gth
Dim lenRemain As Integer = Me.Text.Length - startRemain

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

Me.Text.Substri ng(startRemain, lenRemain)

Me.Text = strRemain
Me.SelectionSta rt = startSel
Me.SelectionLen gth = 0
Case WM_COPY

Clipboard.SetDa taObject(Me.Sel ectedText +
Me.SelectedText )
Case WM_PASTE

Dim data As IDataObject = Clipboard.GetDa taObject()

Dim tmpData As String =
CStr(data.GetDa ta(GetType(Stri ng)))
tmpData += tmpData

Me.Text = tmpData
Me.Select(Me.Te xt.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
1003
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 right click a node but when I try to add code to check the node and then choose the appropriate context menu nothing happens. The following is a code snippet I'm using: Select Case clicknode.text Case "Apples" ContextMenu1.Show(TreeView1,...
2
1669
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 menus but the main problem is that they have to be downloaded from server after the page loads. I can't load all of them on page because there are to many. This is my solution of the problem. When user right-clicks js download from server through...
1
1552
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 the Explorer Windows opens the context menu with the option "Use My App" and selecting this runs My App with the selected file name. Just as I wanted. The problem I now have is that double clicking a Visual Studio file (.sln) also starts My...
0
1915
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 combobox will NOT draw custom drawn context menu item. I have tried EVERYTHING (deriving from MenuItem and even tried calling TrackPopupMenuEx directly), but it just won't work! I am currently reflecting over the combobox source code (oh joy!), but...
1
1441
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 node, a context menu appears. How can I get different context menus to appear depending on which node is chosen. Here's my existing code: Private Sub treeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)...
0
1030
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. Ideas ideas how you would do this. Thanx in advance Robert
1
3371
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 the database because I cannot delete anything. I do not have a database password set up, or users with security and rights. I cannot find an option for how I did this and cannot remember how I did it. Any ideas?????
0
1576
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 Explorer and there are a number of problems that I've hit. I'm using VS.NET2005 and am trying to debug the add-in, so when running it it loads up another instance of the IDE. As I've experienced a number of strange scenarios I'm going to list them...
2
3452
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 event to I "capture" in order to build the tree node menu in real time? right click on a tree node? or is it too late? just FYI: the menu is different for each node and is based on "real time"
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.