Why can't I use either in a multiline text box. Cntl-A is most important for me, rather than having to click at the top and scroll down the whole text.
The &&, == represents logical operator in VB. '&&' - AND, '==' would just be plain =. You can place it in the KeyDown event of your textbox. So to translate the code:
If e.Control AND e.KeyCode = Keys.A Then TextBox.SelectAll() End If
But the documentation clearly states that by enabling the ShortcutsEnabled property of a textbox the ctrl+a function would readily be used. Heres the doc http://msdn2.microsoft.com/en-us/library/1y92bbh2. I suggest you report this to Microsoft Feedback Center...
However, the a still showed. Let's see if I had that code right.
Private Sub txtGeneralText_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtGeneralText.KeyDown If e.Control And e.KeyCode = Keys.A Then 'If e.Control And e.KeyCode = Keys.Control Then
Pressing "A" before ctrl would indeed show the letter a. If you will press ctrl first, then the letter a won't show. But if in some case that you really wouldn't want the user to enter a letter "A" then you can also handle that. Try adding this code on the keydown event...
I just copy pasted your control in a new vb project and it works perfectly fine. This puzzles me. BTW, when is the "a" showing before or after the highlight
I only know visual basic. && and == don't show up in the documentation.
I also don't know where to place the code. MouseDown
Thanks for your answer.
dennist685
edit. The example they give in the October msdn is
Public Sub CopyAllMyText() ' Determine if any text is selected in the TextBox control. If textBox1.SelectionLength = 0 Then ' Select all text in the text box. textBox1.SelectAll() End If ' Copy the contents of the control to the Clipboard. textBox1.Copy() End Sub
edit. I tried it. The trouble is, the 'a' actually appears in the text before the shortcut works.
dennist685
Things are even stranger.
I tried Private Sub txtGeneralText_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtGeneralText.DoubleClick If e.Control Then
txtGeneralText.SelectAll()
txtGeneralText.Copy()
End If End Sub
And got control is not an member of system.events.arg. Why is it OK for KeyDown but not double click
I tried
If e.Control And e.KeyCode = Keys.Control Then but that doesn't work. Why
This is much trickier that Ctrl+A. Try pasting this code in the KeyDown event of the textbox. Just after the ctrl+A statement...
If e.Control And e.KeyCode = Keys.F Then Dim searchString As String Dim pos As Integer searchString = InputBox("Place search String") If searchString <> "" Then pos = InStr(TextBox1.Text, searchString) TextBox1.Select(pos - 1, searchString.Length) End If End If
Cntl - A or Cntl-F in a multiline text box
Ernest Wilkerson
Hi,
The &&, == represents logical operator in VB. '&&' - AND, '==' would just be plain =. You can place it in the KeyDown event of your textbox. So to translate the code:
If e.Control AND e.KeyCode = Keys.A Then
TextBox.SelectAll()
End If
But the documentation clearly states that by enabling the ShortcutsEnabled property of a textbox the ctrl+a function would readily be used. Heres the doc http://msdn2.microsoft.com/en-us/library/1y92bbh2. I suggest you report this to Microsoft Feedback Center...
cheers,
Paul June A. Domag
Roel van Lisdonk
The double-click worked.
However, the a still showed. Let's see if I had that code right.
Private Sub txtGeneralText_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtGeneralText.KeyDown If e.Control And e.KeyCode = Keys.A Then 'If e.Control And e.KeyCode = Keys.Control Then
txtGeneralText.SelectAll()
txtGeneralText.Copy()
e.Handled =
True End If
End Subdennist685
BigGamer
Hi,
Pressing "A" before ctrl would indeed show the letter a. If you will press ctrl first, then the letter a won't show. But if in some case that you really wouldn't want the user to enter a letter "A" then you can also handle that. Try adding this code on the keydown event...
If e.KeyCode = Keys.A Then
e.Handle = True
End If
cheers,
Paul June A. Domag
mabadica
Eventually I would have figured out if e.control and keycode.F then...
but I wouldn't have included the rest.
dennist685
edit: As it turns out this doesn't work. The search dialog doesn't appear. Furthermore, only the first searchstring is highlighted.
Nim Chu
Hi,
I just copy pasted your control in a new vb project and it works perfectly fine. This puzzles me. BTW, when is the "a" showing before or after the highlight
cheers,
Paul June A. Domag
GreenHorse
I only know visual basic. && and == don't show up in the documentation.
I also don't know where to place the code. MouseDown
Thanks for your answer.
dennist685
edit. The example they give in the October msdn is
Public Sub CopyAllMyText()
' Determine if any text is selected in the TextBox control.
If textBox1.SelectionLength = 0 Then
' Select all text in the text box.
textBox1.SelectAll()
End If
' Copy the contents of the control to the Clipboard.
textBox1.Copy()
End Sub
But how do I call that sub
Isaacchung
How do I implement cntl-F
In the keydown event I tried no code at all. Didn't work.
tried e.KeyCode = Keys.F. Message - property keycode is read-only.
How do I do it
dennist685
Rocinante8
if ( (e.Control) && (e.KeyCode==Keys.A))
{
TextBox.SelectAll();
}
JPB
Hi,
I just sent you a mail containing the project that I tinkered with. Try tweaking it and to find out what part of your code is missing...
BTW, got a problem on sending a rar file to gmail. So I removed the extension. Just rename the file to .rar upon downloading.
cheers,
Paul June A. Domag
Rick Wong
dennist685
majellao
dennist685
edit. I tried it. The trouble is, the 'a' actually appears in the text before the shortcut works.
dennist685
Things are even stranger.
I tried
Private Sub txtGeneralText_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtGeneralText.DoubleClick If e.Control Then
txtGeneralText.SelectAll()
txtGeneralText.Copy()
End If End SubAnd got control is not an member of system.events.arg. Why is it OK for KeyDown but not double click
I tried
If e.Control And e.KeyCode = Keys.Control Then but that doesn't work. Why
ddubya
worked fine. thanks.
Whew!
I'll skip preventing the user from typing in whatever letters he wants, but thanks for that information as well.
dennist685
Cornelius Wolf
Hi,
Yes, the routine that was posted would never work on double click. (Is double click on textbox defaults to highlight all-text )
In your other inquiry, about the letter a showing in the textbox. You could override this by placing e.Handled = true before the end if declaration...
Place Directly in DoubleClick event to work:
txtGeneralText.SelectAll()
txtGeneralText.Copy()
remove the if e.control statement....
cheers,
Paul June A. Domag
Sriram Subramanian - MSFT
Hi,
This is much trickier that Ctrl+A. Try pasting this code in the KeyDown event of the textbox. Just after the ctrl+A statement...
If e.Control And e.KeyCode = Keys.F Then
Dim searchString As String
Dim pos As Integer
searchString = InputBox("Place search String")
If searchString <> "" Then
pos = InStr(TextBox1.Text, searchString)
TextBox1.Select(pos - 1, searchString.Length)
End If
End If
cheers,
Paul June A. Domag