[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Urgent... .RichTextBox ,Changing direction to RTL

Posted on 2006-05-22
10
Medium Priority
?
671 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:fadloun
  • 5
  • 4
10 Comments
 
LVL 8

Expert Comment

by:List244
ID: 16736179
Do you mean:
RichTextBox1.SelAlignment = 1
?
0
 
LVL 1

Expert Comment

by:Brownhead
ID: 16738044
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?
0
 
LVL 1

Expert Comment

by:Brownhead
ID: 16738053
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//
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:fadloun
ID: 16739826
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
0
 
LVL 1

Expert Comment

by:Brownhead
ID: 16739867
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...
0
 
LVL 5

Author Comment

by:fadloun
ID: 16740001
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
0
 
LVL 1

Expert Comment

by:Brownhead
ID: 16740025
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//
0
 
LVL 5

Author Comment

by:fadloun
ID: 16740174
Your code works very fine on normal textbox
but on RichTextBox it did not. ....I am confused
0
 
LVL 1

Accepted Solution

by:
Brownhead earned 1600 total points
ID: 16740532
Hehe, I should have just used google. Found an answer in 30 seconds of searching. The code was extremly badly spaced and was nearly impossible to read and execute, but I fixed it up for you, see if this is wat your looking for, worked perfectly for me :D

'//Code\\
'This code requires nothing, place it in a module.
Option Explicit
Public Const WM_USER = &H400
Public Const EM_SETPARAFORMAT = WM_USER + 71
Public Const EM_SETBIDIOPTIONS = WM_USER + 200
Public Const PFM_DIR = &H10000 'Direction mask bit
Public Const PFE_RTLPAR = &H1 'RTL paragraph style bit
Public Const BOM_DEFPARADIR = &H1 'Default direction mask
Public Const BOE_RTLDIR = &H1 'Default RTL para style
Type vbParaFormat
    cbSize As Long
    dwMask As Long
    wNumbering As Integer
    wEffects As Integer
    dxStrtIndent As Long
    dxRightIndent As Long
    dxOffset As Long
    wAlignment As Integer
    cTabCount As Integer
    rgxTabs(31) As Long
End Type
Public vbPF As vbParaFormat
Public Declare Function SendPFMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As vbParaFormat) As Long
Type vbBiDiOptions
    cbSize As Long
    wMask As Integer
    wEffects As Integer
End Type
Public vbBO As vbBiDiOptions
Public Declare Function SendBOMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As vbBiDiOptions) As Long

Public Function SetParaDirection(Direction As Integer) As Boolean
vbPF.cbSize = LenB(vbPF) 'Size
vbPF.dwMask = PFM_DIR 'Attribute to set
vbPF.wEffects = Direction 'New direction
SetParaDirection = SendPFMessage(Form1.RichTextBox1.hWnd, EM_SETPARAFORMAT, 0, vbPF)
End Function
'\\Code//

'//Code\\
'This code requires a rich text box control. Buttons named btnLTR and btnRTL are supported but not necassarily needed
Option Explicit
Private Sub btnLTR_Click()
SetParaDirection (Not PFE_RTLPAR)
RichTextBox1.SetFocus
End Sub
Private Sub btnRTL_Click()
SetParaDirection (PFE_RTLPAR)
RichTextBox1.SetFocus
End Sub

Private Sub Form_Load()
Dim Result As Long
SetParaDirection (PFE_RTLPAR)
vbBO.cbSize = LenB(vbBO) 'Size
vbBO.wMask = BOM_DEFPARADIR 'Attribute to set
vbBO.wEffects = BOE_RTLDIR 'Default direction
Result = SendBOMessage(RichTextBox1.hWnd, EM_SETBIDIOPTIONS, 0, vbBO)
RichTextBox1.RightMargin = 2000
End Sub
'\\Code//

I hope this works, G'day to ya :D
0
 
LVL 5

Author Comment

by:fadloun
ID: 16740900
YES YES YES
BrownHead ,thank you very much. You saved me
goodDay to you too

best regards
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question