1 Attachment(s)
[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.
Attachment 93101
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
Re: Text Renderer Class For Arabic Script Languages
Re: Text Renderer Class For Arabic Script Languages
Quote:
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
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
Re: Text Renderer Class For Arabic Script Languages
Any one else have some idea please?
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.
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
Re: Text Renderer Class For Arabic Script Languages
Quote:
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?
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?
Re: Text Renderer Class For Arabic Script Languages
Yay! Another double post to add to the collection!
Re: Text Renderer Class For Arabic Script Languages
Quote:
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. :)
1 Attachment(s)
Re: Text Renderer Class For Arabic Script Languages
Quote:
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.
Attachment 93331
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.
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