|
-
Nov 11th, 2012, 01:40 AM
#1
Thread Starter
Lively Member
[RESOLVED] Text Renderer Class For Arabic Script Languages
By default .Net Toolstrip control not render the text for RightToLeft languages correctly, I written a class to do so. All is well else after drawing graphics all the menus of toolstrip which are containing "&" not render correctly. Any help will be appreciated.

Here is the class.
PHP Code:
Namespace UrduTextRendrer
Public Class UrduTextRendrer
Inherits ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
Dim sf As New StringFormat()
If (e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If
Using brush = New SolidBrush(e.TextColor)
e.Graphics.DrawString(e.Text, e.TextFont, brush, New RectangleF(e.TextRectangle.Location, e.TextRectangle.Size), sf)
End Using
End Sub
End Class
End Namespace
Usage
PHP Code:
ToolStripManager.Renderer = New UrduTextRendrer.UrduTextRendrer
Last edited by hackerspk; Nov 11th, 2012 at 02:00 AM.
-
Nov 13th, 2012, 07:47 AM
#2
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
-
Nov 13th, 2012, 08:07 AM
#3
Re: Text Renderer Class For Arabic Script Languages
By default .Net Toolstrip control not render the text for RightToLeft languages correctly,
I cannot confirm that, i can show Arabic menu with built-in MenuStrip without any problem?
I think you have to change your system local from control panel> region
-
Nov 13th, 2012, 10:58 AM
#4
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
It works great if you have Windows 7 +, But on windows xp if Asian languages are not installed then text will not shown correctly, if simply while rendering the text we change the string format flags it will work as good as on Windows 7. But you can see while i render the text it works but all the shortcuts and & symbols are not in correct format. I want to fix this issue
-
Nov 15th, 2012, 10:42 PM
#5
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
Any one else have some idea please?
-
Nov 16th, 2012, 06:12 AM
#6
Re: Text Renderer Class For Arabic Script Languages
Is your whole problem the ampersand sign ? If so then why not simply not use it. I don't know too much about foreign glyphs but I wouldn't expect Arabic to have an ampersand.
-
Nov 16th, 2012, 08:13 AM
#7
Re: Text Renderer Class For Arabic Script Languages
You may remove the ampersand from the text, it is dirty solution until you find another one.
Code:
Namespace UrduTextRendrer
Public Class UrduTextRendrer
Inherits ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
Dim sf As New StringFormat
If (e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If
e.Text = e.Text.Replace("&"c, String.Empty) ' Remove the ampersand from the text
Using brush = New SolidBrush(Color.Red) 'e.TextColor)
e.Graphics.DrawString(e.Text, e.TextFont, brush, New RectangleF(e.TextRectangle.Location, e.TextRectangle.Size), sf)
End Using
End Sub
End Class
End Namespace
-
Nov 16th, 2012, 11:07 AM
#8
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
 Originally Posted by 4x2y
You may remove the ampersand from the text, it is dirty solution until you find another one.
Code:
Namespace UrduTextRendrer
Public Class UrduTextRendrer
Inherits ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
Dim sf As New StringFormat
If (e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If
e.Text = e.Text.Replace("&"c, String.Empty) ' Remove the ampersand from the text
Using brush = New SolidBrush(Color.Red) 'e.TextColor)
e.Graphics.DrawString(e.Text, e.TextFont, brush, New RectangleF(e.TextRectangle.Location, e.TextRectangle.Size), sf)
End Using
End Sub
End Class
End Namespace
i thought of that but there is one problem more all the shortcut keys also turn to left so how to adjust these keys?
-
Nov 16th, 2012, 12:03 PM
#9
Re: Text Renderer Class For Arabic Script Languages
I'm still not convinced by the whole premise that "by default .Net Toolstrip control not render the text for RightToLeft languages correctly"! What does that actually mean?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 16th, 2012, 12:08 PM
#10
Re: Text Renderer Class For Arabic Script Languages
Yay! Another double post to add to the collection!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 16th, 2012, 01:05 PM
#11
Re: Text Renderer Class For Arabic Script Languages
 Originally Posted by dunfiddlin
Yay! Another double post to add to the collection!
Even if the page takes a while to change, it doesn't mean that the forum didn't acknowledge the post. You can avoid double posting by keeping that in mind. It took a while to get used to but its practically instinct now...at least for me.
-
Nov 16th, 2012, 11:46 PM
#12
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
 Originally Posted by dunfiddlin
I'm still not convinced by the whole premise that "by default .Net Toolstrip control not render the text for RightToLeft languages correctly"! What does that actually mean?
Windows Vista, 7,8 have good Unicode support when these windows renders Arabic script languages, there is no error. But windows xp if east asian languages are not installed it cannot able to render Arabic script correctly. See picture.
Some of the .net controls supports "UseCompatibleTextRendering". when it is set to true then Windows XP is also render the text as correctly as Windows 7. But toolstrip control has no UseCompatibleTextRendering property. If we render the text using this below method there is no problem with text. But there are some other errors like "&" symbols and shortcuts.
-
Nov 17th, 2012, 09:50 AM
#13
Thread Starter
Lively Member
Re: Text Renderer Class For Arabic Script Languages
Ok problem is resolved by Mick Doherty
PHP Code:
Namespace UrduTextRendrer
Public Class UrduTextRendrer
Inherits ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
Dim sf As New StringFormat()
Dim rtl As Boolean = (e.TextFormat And TextFormatFlags.RightToLeft) = TextFormatFlags.RightToLeft
If rtl Then
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
If (e.TextFormat & TextFormatFlags.Right) Then
e.TextFormat -= TextFormatFlags.Right
Else
e.TextFormat += TextFormatFlags.Right
End If
End If
If (e.TextFormat And TextFormatFlags.Right) = TextFormatFlags.Right Then
sf.Alignment = StringAlignment.Far
End If
If (e.TextFormat And TextFormatFlags.HidePrefix) = TextFormatFlags.HidePrefix Then
sf.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Hide
Else
sf.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
End If
Using brush = New SolidBrush(e.TextColor)
e.Graphics.DrawString(e.Text, e.TextFont, brush, e.TextRectangle, sf)
End Using
End Sub
End Class
End Namespace
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
|