Link to home
Start Free TrialLog in
Avatar of fadloun
fadloun

asked on

Urgent... .RichTextBox ,Changing direction to RTL

Hello

How to change writing direction to right-to-left programmatically in RichTextBox
manually if I press right Ctrl+Shift ,the direction will be changed but how to automate it.
I have tried SendKeys but I don't know how to pass R.Ctrl Key.
what about API ,can I do it using one of API Declaration

best regards
Avatar of List244
List244

Do you mean:
RichTextBox1.SelAlignment = 1
?
I'm not sure what your asking... but heres what you suggested.. it simulates the keystrokes for you.

'//Code\\
'This code requires nothing
keybd_event VK_CONTROL, 0, 0, 0 'Press down the control key
keybd_event 16, 0, &H1, 0 'Press down the shift key
keybd_event VK_RIGHT, 0, 0, 0 'Press down the right key
keybd_event VK_CONTROL, 0, &H2, 0 'Release the control key
keybd_event 16, 0, &H1 Or &H2, 0 'Release the shift key
keybd_event VK_RIGHT, 0, &H2, 0 'Release the right key
'\\Code//

Does this help?
Oh, and heres the constants you'll need.

'//Code\\
'This code requires nothing. Place it in the declarations section of your code
Const VK_CONTROL As Long = &H11
Const VK_RIGHT As Long = &H27
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'\\Code//
Avatar of fadloun

ASKER

Hello All
List
No ,SelAlignment will set alignment only,what I am looking for is setting Text alignment to Right side+(Insertion Right-To-Left) ,
 Arabic + Hebrew are RTL Language ,if you write in a textbox using english +arbaic Language setting direction to RTL is a Must to display the paragraph properly.
in normal VB Textbox this property available by defualt ,

BrownHead
I have tried your code ,but it didn't work ... nothing happen
I replaced shift para with Rshift
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  keybd_event(VK_RSHIFT, 0, 0, 0)
  keybd_event(VK_CONTROL, 0, 0, 0)
  keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
  keybd_event(VK_RSHIFT, 0, KEYEVENTF_KEYUP, 0)
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
this code doesn't do what actually pressing(Rshift+Control) DO


Regards
When I press the Right Shift key on my keyboad, and the control key, and then type things in, nothing changes... thus i'm still not sure what your trying to accomplish. Maybe someone else does though. And the VK_Right is the right directional pad key.. which is what I thought you said, but now I see I misinterpreted it. 16 is actually the keycode for shift...
Avatar of fadloun

ASKER

if you have bilingual System,English + Rtl Language( Arabic or Hebrew) enabled
pressing Ctrl + Rshift will do the following
 change the language to To arabic
 align the text to right
 correct insert direction to RTL
Pressing Ctrl +LShift will reverse this

regards
Let me take another wack at simulating the keystrokes... try this:

'//Code\\
'This code requires nothing
keybd_event &H11, 0, 0, 0 'Press down the control key
keybd_event &HA1, 0, 0, 0 'Press down the shift key
DoEvents
keybd_event &H11, 0, &H2, 0 'Press down the control key
keybd_event &HA1, 0, &H2, 0 'Press down the shift key
'\\Code//
Avatar of fadloun

ASKER

Your code works very fine on normal textbox
but on RichTextBox it did not. ....I am confused
ASKER CERTIFIED SOLUTION
Avatar of Brownhead
Brownhead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fadloun

ASKER

YES YES YES
BrownHead ,thank you very much. You saved me
goodDay to you too

best regards