在开发支持阿拉伯语的应用程序时,开发者经常面临语言编码和文本显示的问题。本文将介绍如何创建一个无需额外软件即可支持阿拉伯语的应用程序。
这个想法诞生于为Symbol手持设备开发货架价格检查器和标签打印软件时。该软件需要在Windows CE5.0系统上检索、显示和打印阿拉伯语(印地语)数字和文本。
以下是一个设计时控件的示例代码。这个项目已经完成,但根据需求可能需要一些修改:
using System.Drawing;
using System.Windows.Forms;
using System.Text;
namespace Ar.Controls
{
public class ArabicButton : System.Windows.Forms.Button
{
private bool m_HindiNumerals;
private string m_LogicalText;
private bool m_RightToLeft;
public bool HindiNumerals
{
get { return this.m_HindiNumerals; }
set
{
this.m_HindiNumerals = value;
this.Text = this.m_LogicalText;
}
}
public new bool RightToLeft
{
get { return this.m_RightToLeft; }
set
{
this.m_RightToLeft = value;
this.Text = this.m_LogicalText;
}
}
public new string Text
{
get { return this.m_LogicalText; }
set
{
if (value != null)
{
this.m_LogicalText = value;
StringBuilder builder1 = new StringBuilder(this.Text.Length + 1);
short num1 = (short)this.m_LogicalText.Length;
ushort[] numArray1 = new ushort[1];
if (this.m_HindiNumerals)
{
numArray1[0] = 1;
}
else
{
numArray1[0] = 0;
}
mArabicCoreWrapper.BuildArabicStringWithLigate(
this.m_RightToLeft,
this.Text, builder1, num1, numArray1);
base.Text = builder1.ToString();
}
}
}
public override System.Drawing.Font Font
{
get { return base.Font; }
set
{
base.Font = value;
Invalidate();
}
}
public ArabicButton()
{
this.Font = new Font("Tahoma", 8f, FontStyle.Regular);
this.m_RightToLeft = true;
this.m_HindiNumerals = true;
}
}
}
这段代码是为Compact Framework 2.0编写的,并在Windows CE5.0和Windows Mobile 5.0上进行了测试。