Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing code for right to left language

Status
Not open for further replies.

kulfanumber

Programmer
Jun 24, 2009
21
PK
I am designing an Urdu editor. Urdu language is written from right to left. Now I implemented justification using some code from net. I tried it on english editor, it works fine. But when I use it for my Urdu editor the text alignment changes to left. The code is here
Enum TextAlign
Left = 1
Right = 2
Center = 3
Justify = 4
End Enum

<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByRef lp As PARAFORMAT) As Integer
End Function


<StructLayout(LayoutKind.Sequential)> _
Private Structure PARAFORMAT
Public cbSize As Integer
Public dwMask As UInteger
Public wNumbering As Short
Public wReserved As Short
Public dxStartIndent As Integer
Public dxRightIndent As Integer
Public dxOffset As Integer
Public wAlignment As Short
Public cTabCount As Short
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
Public rgxTabs() As Integer

' PARAFORMAT2 from here onwards.
Public dySpaceBefore As Int32
Public dySpaceAfter As Int32
Public dyLineSpacing As Int32
Public sStyle As Short
Public bLineSpacingRule As Byte
Public bOutlineLevel As Byte
Public wShadingWeight As Short
Public wShadingStyle As Short
Public wNumberingStart As Short
Public wNumberingStyle As Short
Public wNumberingTab As Short
Public wBorderSpace As Short
Public wBorderWidth As Short
Public wBorders As Short
End Structure

Private updating As Int32 = 0
Private oldEventMask As Int32 = 0

'Constants from the Platform SDK.
Private Const EM_SETEVENTMASK As Integer = 1073
Private Const EM_GETPARAFORMAT As Integer = 1085
Private Const EM_SETPARAFORMAT As Integer = 1095
Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
Private Const WM_SETREDRAW As Integer = 11
Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
Private Const PFM_ALIGNMENT As Integer = 8
Private Const SCF_SELECTION As Integer = 1

Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)

MyBase.OnHandleCreated(e)

'Enable support for justification.
SendMessage(New HandleRef(Me, Handle), _
EM_SETTYPOGRAPHYOPTIONS, _
TO_ADVANCEDTYPOGRAPHY, _
TO_ADVANCEDTYPOGRAPHY)
End Sub

Public Overloads Property SelectionAlignment() As TextAlign

Get

Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)

' Get the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_GETPARAFORMAT, _
SCF_SELECTION, fmt)

' Default to Left align.
If ((fmt.dwMask & PFM_ALIGNMENT) = 0) Then
Return TextAlign.Left
End If
If fmt.wAlignment = 1 Then
Return TextAlign.Left
ElseIf fmt.wAlignment = 2 Then
Return TextAlign.Right
ElseIf fmt.wAlignment = 3 Then
Return TextAlign.Center
ElseIf fmt.wAlignment Then
Return TextAlign.Justify
End If
End Get
Set(ByVal value As TextAlign)

Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)
fmt.dwMask = PFM_ALIGNMENT
fmt.wAlignment = CShort(value)

' Set the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_SETPARAFORMAT, _
SCF_SELECTION, fmt)
End Set
End Property
I tried with this change
If ((fmt.dwMask & PFM_ALIGNMENT) = 0) Then
Return TextAlign.Right
End If
But it doesn’t work. Can anyone plz tell me how to make it work for urdu language?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top