By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

Copy, Cut, Paste

P: n/a
Hi

How can I implement cut or copy or paste in code?

Thanks

Regards
Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Hi, this is a very broad question... Please tell us what you'd like to
Cut/Copy/Paste...

e.g. Files/Images/Text/etc

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
Hi

How can I implement cut or copy or paste in code?

Thanks

Regards

Nov 20 '05 #2

P: n/a
Sorry, I just want to provide the Edit menu's copy, cut paste functionality.

Thanks

Regards
"Tom Spink" <thomasdotspinkat@ntlworlddotcom> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Hi, this is a very broad question... Please tell us what you'd like to
Cut/Copy/Paste...

e.g. Files/Images/Text/etc

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
Hi

How can I implement cut or copy or paste in code?

Thanks

Regards


Nov 20 '05 #3

P: n/a
"John" <jo**@nospam.infovis.co.uk> schrieb

How can I implement cut or copy or paste in code?

System.Windows.Forms.Clipboard.*
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

P: n/a
If I want to implement it in the generic way (Edit->Copy) what would be the
value of data in System.Windows.Forms.Clipboard.SetDataObject(data) ?
Thanks

Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb

How can I implement cut or copy or paste in code?

System.Windows.Forms.Clipboard.*
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
Hi, what do you want in there?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:#1*************@TK2MSFTNGP12.phx.gbl...
If I want to implement it in the generic way (Edit->Copy) what would be the value of data in System.Windows.Forms.Clipboard.SetDataObject(data) ?
Thanks

Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb

How can I implement cut or copy or paste in code?

System.Windows.Forms.Clipboard.*
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #6

P: n/a
Whatever test the user has selected at the time (it is a database app). I
would not know which field it would be beforehand.

Thanks

Regards

"Tom Spink" <thomasdotspinkat@ntlworlddotcom> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi, what do you want in there?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:#1*************@TK2MSFTNGP12.phx.gbl...
If I want to implement it in the generic way (Edit->Copy) what would be

the
value of data in System.Windows.Forms.Clipboard.SetDataObject(data) ?
Thanks

Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
"John" <jo**@nospam.infovis.co.uk> schrieb
>
> How can I implement cut or copy or paste in code?
System.Windows.Forms.Clipboard.*
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



Nov 20 '05 #7

P: n/a
"John" <jo**@nospam.infovis.co.uk> schrieb
Whatever test the user has selected at the time (it is a database
app). I would not know which field it would be beforehand.


You can get the active Form using Form.ActiveForm or ActiveMdiChild in an
Mdi container. The ActiveControl returns the active control, and depending
on the type of the active control you can copy the selected text or
whatever. For example, if the active control is a Datagrid, you can copy the
selected text of the active cell.

In all Forms I'd probably implement an Interface that handles the clipboard
features for the Form.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

P: n/a
* "John" <jo**@nospam.infovis.co.uk> scripsit:
How can I implement cut or copy or paste in code?


For example, for the RichTextBox:

<http://www.mvps.org/dotnet/dotnet/samples/controls/downloads/RichTextBoxContext.zip>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

P: n/a
when I right click in a text field it gives me the cut/copy/paste context
menu. cannot I tap into this built-in functionality?

Regards

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bu************@ID-208219.news.uni-berlin.de...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
How can I implement cut or copy or paste in code?
For example, for the RichTextBox:

<http://www.mvps.org/dotnet/dotnet/sa...RichTextBoxCon
text.zip>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #10

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
"John" <jo**@nospam.infovis.co.uk> schrieb
Whatever test the user has selected at the time (it is a
database app). I would not know which field it would be
beforehand.


You can get the active Form using Form.ActiveForm or ActiveMdiChild
in an Mdi container. The ActiveControl returns the active control,
and depending on the type of the active control you can copy the
selected text or whatever. For example, if the active control is a
Datagrid, you can copy the selected text of the active cell.

In all Forms I'd probably implement an Interface that handles the
clipboard features for the Form.


Some example code for you.... attention: Untested! :)
Public Interface ISupportsClipboard
Enum Action
Copy
Cut
Delete
Paste
End Enum

Function ActionAvailable(ByVal Action As Action) As Boolean
Sub PerformAction(ByVal Action As Action)
End Interface
In the Form, implement ISupportsClipboard:

Public Function ActionAvailable( _
ByVal Action As ISupportsClipboard.Action) As Boolean _
Implements ISupportsClipboard.ActionAvailable

Return TypeOf Me.ActiveControl Is TextBox AndAlso _
DirectCast(Me.ActiveControl, TextBox).SelectionLength > 0 AndAlso _
(Action <> ISupportsClipboard.Action.Paste OrElse _
Clipboard.GetDataObject.GetDataPresent(GetType(Str ing)))

End Function

Public Sub PerformAction( _
ByVal Action As ISupportsClipboard.Action) _
Implements ISupportsClipboard.PerformAction

If Not Me.ActionAvailable(Action) Then
Throw New InvalidOperationException( _
"The clipboard action '" & Action.ToString & "' is not available."
_
)
End If

Dim txt As TextBox
txt = DirectCast(Me.ActiveControl, TextBox)

If Action = ISupportsClipboard.Action.Copy OrElse _
Action = ISupportsClipboard.Action.Cut Then

Clipboard.SetDataObject(txt.SelectedText)
End If

If Action = ISupportsClipboard.Action.Cut OrElse _
Action = ISupportsClipboard.Action.Delete Then
txt.SelectedText = ""
ElseIf Action = ISupportsClipboard.Action.Paste Then
txt.SelectedText =
Clipboard.GetDataObject.GetData(GetType(String)).T oString
End If

End Sub


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #11

P: n/a
* "John" <jo**@nospam.infovis.co.uk> scripsit:
when I right click in a text field it gives me the cut/copy/paste context
menu. cannot I tap into this built-in functionality?


Please be more specific. What exactly do you want to do for which
type(s) of control(s)?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #12

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bu************@ID-208219.news.uni-berlin.de...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
when I right click in a text field it gives me the cut/copy/paste context menu. cannot I tap into this built-in functionality?


Please be more specific. What exactly do you want to do for which
type(s) of control(s)?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


I think he is referring to the fact that most windows controls natively
support cut/copy/paste messages - all you have to do is send the appropriate
message with the win32 api. Like this:

http://www.geocities.com/practicalvb...extboxops.html

I'm a bit surprised MS only implements this functionality in
TextBoxBase, and not at a higher level...

Erik
Nov 20 '05 #13

P: n/a
Cor
Hi John,

Strange you did not get this link from Armin, I got it while by looking at
an answer from him

http://msdn.microsoft.com/library/en...ardSupport.asp

I hope this helps?

Cor
Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.