"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