public DialogResult Show() { canExit = false; int[] widths = new int[3]; widths[0] = XingKongScreen.MeasureStringWidth(Caption, lbCaption.FontSize); widths[1] = XingKongScreen.MeasureStringWidth(Title, lbTitle.FontSize); widths[2] = 128 * 2 + 40; int maxWidth = widths[0]; foreach (int w in widths) { if (w > maxWidth) { maxWidth = w; } } int actWidth = maxWidth + 150; int actHeight = actWidth * 3 / 4; int left = (800 - actWidth) / 2; int top = (600 - actHeight) / 2; lbCaption.Left = (short)(20 + left); lbCaption.Top = (short)(20 + top); Point pLeftTopOfBox = new Point(left, top); Point pRightButtomOfBox = new Point(left + actWidth, top + actHeight); XingKongScreen.SetColor(XingKongScreen.XColor.White); XingKongScreen.FillSquare(pLeftTopOfBox, pRightButtomOfBox); XingKongScreen.SetColor(); XingKongScreen.DrawSquare(pLeftTopOfBox, pRightButtomOfBox); int lbCaptionFontHeight = getFontHeightPixel(lbCaption.FontSize); int lbTitleFontHeight = getFontHeightPixel(lbTitle.FontSize); XingKongScreen.DrawLine(new Point(left, 40 + top + lbCaptionFontHeight), new Point(left + actWidth, 40 + top + lbTitleFontHeight)); lbTitle.Top = (short)((actHeight / 5) + 40 + top + lbCaptionFontHeight); lbTitle.Left = (short)(((actWidth - XingKongScreen.MeasureStringWidth(lbTitle.Text, lbTitle.FontSize)) / 2) + left); int btOkFontHeight = getFontHeightPixel(btOk.FontSize); int btCancelFontHeight = getFontHeightPixel(btCancel.FontSize); if (DialogStyle == Style.OkCancel) { btOk.Left = (actWidth - widths[2]) / 2 + left; btOk.Top = (short)((actHeight * 3 / 5) + top + btCancelFontHeight); btCancel.Left = btOk.Left + btOk.Width + 40; btCancel.Top = btOk.Top; btOk.Draw(); btCancel.Draw(); } else { btOk.Left = (actWidth - btOk.Width) / 2 + left; btOk.Top = (short)((actHeight * 3 / 5) + top + btCancelFontHeight); btOk.Draw(); } lbCaption.Draw(); lbTitle.Draw(); XingKongScreen.FreshScreen(); if (btOk.IsChecked) { result = DialogResult.OK; } else { result = DialogResult.Cancel; } keyboard = XingKongScreen.GetKeyboard(); keyboard.KeyPressed += Keyboard_KeyPressed; while (!canExit) { Thread.Sleep(10); } keyboard.KeyPressed -= Keyboard_KeyPressed; return(result); }
public void Draw() { if (bitmap == null) { return; } setLastPoint(); if (!SkipPreProceed) { try { getGrayBitmap(); } catch (Exception) { bitmap = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb); getGrayBitmap(); } } object asyncLockObj = XingKongScreen.AsyncLockObj; lock (asyncLockObj) { //初始化判断颜色是否相同的临时变量 colorCount = 0; lastColor = 0x03; for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { byte color = GetPixelColor(bitmap.GetPixel(x, y).R, !SkipPreProceed); if (lastColor != color) { colorCount++; if (colorCount % 2 == 1) { //线的开始,记录点 lastPoint = new Point(x, y); lastColor = color; XingKongScreen.SetColor((XingKongScreen.XColor)color); } else if (colorCount != 0 && lastColor != 0x03) { //线的结束,画线 XingKongScreen.DrawLine(getOffsetPoint(lastPoint), getOffsetPoint(new Point(x, y))); } } } if (colorCount % 2 != 0 && lastColor != 0x03) { XingKongScreen.DrawLine(getOffsetPoint(lastPoint), getOffsetPoint(new Point(x, bitmap.Height))); colorCount = 0; lastColor = 0x03; } } XingKongScreen.SetColor();//恢复初始调色板 NeedDraw = false; } }