|
-
Dec 7th, 2006, 05:50 AM
#1
Thread Starter
Addicted Member
[RESOLVED] code without pressing keys
how can i write a code for this
select all
ctrl+right shift
in a richtextbox
is it possible?
-
Dec 7th, 2006, 06:04 AM
#2
Re: code without pressing keys
VB Code:
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
ShiftTest = Shift And 7
If ShiftTest = 3 Then
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SetFocus
End If
End Sub
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 7th, 2006, 06:57 AM
#3
Re: code without pressing keys
 Originally Posted by ganeshmoorthy
VB Code:
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
ShiftTest = Shift And 7
If ShiftTest = 3 Then
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SetFocus
End If
End Sub
What is "ShiftTest"?
-
Dec 7th, 2006, 07:06 AM
#4
Re: code without pressing keys
Im sorry, dint include the declaration part, here is the full code
VB Code:
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ShiftTest As Integer
ShiftTest = Shift And 7
If ShiftTest = 3 Then
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SetFocus
End If
End Sub
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 7th, 2006, 09:10 AM
#5
Thread Starter
Addicted Member
Re: code without pressing keys

this code can applyed for mouse down and i need it in form load
also i need it to be active without pressing any key in keyboard or mouse
how?
-
Dec 7th, 2006, 10:38 AM
#6
Re: code without pressing keys
 Originally Posted by om-yousif
this code can applyed for mouse down
Yes, It can be applied to your Keyboard or Mouse Down events.
 Originally Posted by om-yousif
i need it to be active without pressing any key in keyboard or mouse
??????????
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 7th, 2006, 11:08 AM
#7
Hyperactive Member
Re: code without pressing keys
Or:
VB Code:
Private Sub RichTextBox1_GotFocus()
SendKeys "^+a"
End Sub
But why every second time GotFocus the text turn to UPPERCASE?
-
Dec 7th, 2006, 11:41 AM
#8
Thread Starter
Addicted Member
Re: code without pressing keys
OK ganeshmoorthy
let me tell you what i need
i have a richtextbox includes an Arabic Text
this text will be loaded in Form_Load()
what i need is to change the Alignment of the richtext to right automatically
without pressing anything in keyboard or mouse
these two steps in pressing the keyboard will do this
select all
ctrl+right shift
but i need to convert it to a code in VB so the text's alignment will be changed just when form loaded
-
Dec 7th, 2006, 11:58 AM
#9
Re: code without pressing keys
You can use the keybd_event() API function. Are you sure pressing CTRL+Right Shift aligns the text to the right? It's not working for me.
VB Code:
Option Explicit
Private Const VK_SHIFT = &H10
Private Const VK_CONTROL = &H11
Private Const VK_RSHIFT = &HA1
Private Const VK_A As Integer = 65
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private intActivate As Integer
Private Sub Form_Activate()
If intActivate = 0 Then
'Press down control key.
keybd_event VK_CONTROL, 0, 0, 0
'Press right shift.
keybd_event VK_RSHIFT, 0, 0, 0
'Release right shift key.
keybd_event VK_RSHIFT, 0, KEYEVENTF_KEYUP, 0
'Release control key.
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
intActivate = 1
End If
End Sub
Private Sub Form_Load()
rtb.SelText = "fjdslkfkj" & vbNewLine & "jflksdfjslkjfd" & vbNewLine & "fjlsdfj"
'select all
'ctrl+right shift
With rtb
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
-
Dec 7th, 2006, 01:19 PM
#10
Thread Starter
Addicted Member
Re: code without pressing keys
yes DigiRev
(Ctrl+right shift) will do it
-
Dec 7th, 2006, 03:04 PM
#11
Re: code without pressing keys
 Originally Posted by om-yousif
...but i need to convert it to a code in VB so the text's alignment will be changed just when form loaded...
VB Code:
Private Sub Form_Load()
With RichTextBox1
.SelStart = 0
.SelLength = Len (.Text)
.SelAlignment = 1
End With
End Sub
??
-
Dec 8th, 2006, 03:15 AM
#12
Thread Starter
Addicted Member
Re: code without pressing keys
thanks for all
and special thanks for gavio
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|