G
Graf
Hello Everyone,
the .net cf 2.0 supports the clipboard directly, but is there any easy
way to find out, which textbox has the focus? Here is the code, that I
have at the moment and as you can see I have to check for every textbox
if it has the focus. Any ideas how to make this work for every textbox
easier?
Thanks in advance!
Regards,
Andreas
Private Sub miPaste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miPaste.Click, miPaste2.Click
Dim strTextToInsert As String
Dim strTextInForm As String
Dim strNewInForm As String
Dim intPosition As Int16
Dim activeTextbox As TextBox
Dim bolNoAction As Boolean = False
'Welche Textbox hat den Fokus? (keine Activecontrol Eigenschaft
in CF.net?)
If txtDecryptText.Focused Then
activeTextbox = DirectCast(txtDecryptText, TextBox)
ElseIf txtExpression.Focused Then
activeTextbox = DirectCast(txtExpression, TextBox)
ElseIf txtExpression2.Focused Then
activeTextbox = DirectCast(txtExpression2, TextBox)
ElseIf txtResult.Focused Then
activeTextbox = DirectCast(txtResult, TextBox)
ElseIf txtResult2.Focused Then
activeTextbox = DirectCast(txtResult2, TextBox)
ElseIf txtInput.Focused Then
activeTextbox = DirectCast(txtInput, TextBox)
Else
bolNoAction = True
End If
If bolNoAction = False Then
'Ist beim Einfügen Text markiert, diesen vorher löschen
If activeTextbox.SelectedText <> "" Then
activeTextbox.SelectedText = ""
End If
'Wo steht der Cursor? Dort den Text einfügen
intPosition = CShort(activeTextbox.SelectionStart)
strTextInForm = activeTextbox.Text
If
Windows.Forms.Clipboard.GetDataObject.GetData(DataFormats.Text) IsNot
Nothing Then
strTextToInsert =
Windows.Forms.Clipboard.GetDataObject.GetData(DataFormats.Text).ToString
strNewInForm = strTextInForm.Insert(intPosition,
strTextToInsert)
activeTextbox.Text = strNewInForm
End If
End If
End Sub
the .net cf 2.0 supports the clipboard directly, but is there any easy
way to find out, which textbox has the focus? Here is the code, that I
have at the moment and as you can see I have to check for every textbox
if it has the focus. Any ideas how to make this work for every textbox
easier?
Thanks in advance!
Regards,
Andreas
Private Sub miPaste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miPaste.Click, miPaste2.Click
Dim strTextToInsert As String
Dim strTextInForm As String
Dim strNewInForm As String
Dim intPosition As Int16
Dim activeTextbox As TextBox
Dim bolNoAction As Boolean = False
'Welche Textbox hat den Fokus? (keine Activecontrol Eigenschaft
in CF.net?)
If txtDecryptText.Focused Then
activeTextbox = DirectCast(txtDecryptText, TextBox)
ElseIf txtExpression.Focused Then
activeTextbox = DirectCast(txtExpression, TextBox)
ElseIf txtExpression2.Focused Then
activeTextbox = DirectCast(txtExpression2, TextBox)
ElseIf txtResult.Focused Then
activeTextbox = DirectCast(txtResult, TextBox)
ElseIf txtResult2.Focused Then
activeTextbox = DirectCast(txtResult2, TextBox)
ElseIf txtInput.Focused Then
activeTextbox = DirectCast(txtInput, TextBox)
Else
bolNoAction = True
End If
If bolNoAction = False Then
'Ist beim Einfügen Text markiert, diesen vorher löschen
If activeTextbox.SelectedText <> "" Then
activeTextbox.SelectedText = ""
End If
'Wo steht der Cursor? Dort den Text einfügen
intPosition = CShort(activeTextbox.SelectionStart)
strTextInForm = activeTextbox.Text
If
Windows.Forms.Clipboard.GetDataObject.GetData(DataFormats.Text) IsNot
Nothing Then
strTextToInsert =
Windows.Forms.Clipboard.GetDataObject.GetData(DataFormats.Text).ToString
strNewInForm = strTextInForm.Insert(intPosition,
strTextToInsert)
activeTextbox.Text = strNewInForm
End If
End If
End Sub