public XingKongMessageBox() { lbCaption = new XingKongLabel(); lbTitle = new XingKongLabel(); btOk = new XingKongButton(); btCancel = new XingKongButton(); if (XingKongScreen.IsRunningOnMono()) { btOk.TextXoffset = -9; btCancel.TextXoffset = -9; } else { btOk.TextXoffset = -2; btCancel.TextXoffset = -2; } btOk.Text = "确定"; btCancel.Text = "取消"; btOk.Width = 128; btOk.Height = 60; btCancel.Width = 128; btCancel.Height = 60; btOk.IsChecked = true;; btCancel.IsChecked = false; DialogStyle = Style.OkCancel; }
public void Draw() { //先生成文本 int fontHeight = 32; switch (FontSize) { case XingKongScreen.XFontSize.Normal: fontHeight = 32; break; case XingKongScreen.XFontSize.Large: fontHeight = 48; break; case XingKongScreen.XFontSize.ExtraLarge: fontHeight = 64; break; default: break; } int fontWidth = XingKongScreen.MeasureStringWidth(Text, FontSize); int fontLeft = 10; switch (TextAlign) { case XingKongScreen.TextAlign.Left: fontLeft = 10 + left; break; case XingKongScreen.TextAlign.Center: fontLeft = (Width - fontWidth) / 2 + Left + TextXoffset; break; case XingKongScreen.TextAlign.Right: fontLeft = Width - fontWidth - 10; break; default: break; } int fontTop = (Height - fontHeight) / 2 + Top + TextYoffset; XingKongLabel ltemp = new XingKongLabel(); ltemp.Text = Text; ltemp.Left = (short)fontLeft; ltemp.Top = (short)fontTop; ltemp.FontSize = FontSize; //计算矩形位置 Point p1 = new Point(Left, Top); Point p2 = new Point(Left + Width, Top + Height); object asyncLockObj = XingKongScreen.AsyncLockObj; lock (asyncLockObj) { if (isChecked) { XingKongScreen.SetColor(XingKongScreen.XColor.Gray); XingKongScreen.FillSquare(p1, p2); //设置文字为白色,背景为黑色 XingKongScreen.SetColor(XingKongScreen.XColor.White, XingKongScreen.XColor.Gray); ltemp.Draw(); //恢复默认调色板 XingKongScreen.SetColor(); } else { XingKongScreen.SetColor(XingKongScreen.XColor.White); XingKongScreen.FillSquare(p1, p2); XingKongScreen.SetColor(); //先画文本 ltemp.Draw(); //再画矩形 XingKongScreen.DrawSquare(p1, p2); } } NeedDraw = false; }