经过几个小时的文本对齐斗争后,我终于得到了 Zebra 的回复。你必须使用DrawTextEx()
方法并将其传递到对齐参数中。 (请注意,SDK 中未提供此方法,但 DLL 中确实存在此方法!您需要将其添加到您的应用程序中才能使其正常工作)
3 = 左对齐
4 = 中心对齐
5 = 右对齐
将此代码添加到ZBRGraphics.cs file
[DllImport("ZBRGraphics.dll", EntryPoint = "ZBRGDIDrawTextEx", CharSet = CharSet.Auto,
SetLastError = true)]
static extern int ZBRGDIDrawTextEx(int x, int y, int angle, int alignment, byte[] text, byte[] font, int fontSize, int fontStyle, int color, out int err);
public int DrawTextEx(int x, int y, int angle, int alignment, byte[] text, byte[] font, int fontSize, int fontStyle, int color, out int err)
{
return ZBRGDIDrawTextEx(x, y, angle, alignment, text, font, fontSize, fontStyle, color, out err);
}
以下是如何在您的应用程序中使用它。
使用方法(摘自《SDK手册》):
int x = 0;
int y = 0;
int angle = 0; //0 degrees rotation (no rotation)
int alignment = 4; //center justified
string TextToPrint = "Printed Text";
byte[] text = null;
string FontToUse = "Arial";
byte[] font = null;
int fontSise = 12;
int fontStyle = 1; //bold
int color = 0x0FF0000; //black
int err = 0;
int result = 0;
//use the function:
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
text = ascii.GetBytes(TextToPrint);
font = ascii.GetBytes(FontToUse);
result = ZBRGDIDrawTextEx(x, y, angle, alignment, text, font, fontSize,fontStyle, color, out err);