private void AppendFormat(HCCanvas aCanvas, DateTimeArea aArea, ref RECT aRect) { aRect.SetEmpty(); int vIndex = 0, vCount = -1; switch (aArea) { case DateTimeArea.dtaYear: GetAreaPosition("y", false, ref vIndex, ref vCount); break; case DateTimeArea.dtaMonth: GetAreaPosition("M", true, ref vIndex, ref vCount); break; case DateTimeArea.dtaDay: GetAreaPosition("d", false, ref vIndex, ref vCount); break; case DateTimeArea.dtaHour: GetAreaPosition("H", true, ref vIndex, ref vCount); // 12、24小时制 break; case DateTimeArea.dtaMinute: GetAreaPosition("m", false, ref vIndex, ref vCount); break; case DateTimeArea.dtaSecond: GetAreaPosition("s", false, ref vIndex, ref vCount); break; } if (vCount > 0) { string vs = ""; if (vIndex > 0) { vs = FFormat.Substring(0, vIndex); } aRect.Left = FPaddingLeft; if (vs != "") { aRect.Left += aCanvas.TextExtent(vs).cx; } SIZE vSize = aCanvas.TextExtent(FFormat.Substring(vIndex, vCount)); aRect.Top = (Height - vSize.cy) / 2; aRect.Right = aRect.Left + vSize.cx; aRect.Bottom = aRect.Top + vSize.cy; } }
protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo) { base.DoPaint(aStyle, aDrawRect, aDataDrawTop, aDataDrawBottom, aDataScreenTop, aDataScreenBottom, aCanvas, aPaintInfo); if (this.IsSelectComplate) { aCanvas.Brush.Color = aStyle.SelColor; } else if (FDown) { aCanvas.Brush.Color = HC.clHighlight; } else if (FMouseIn) { aCanvas.Brush.Color = HC.clBtnFace; } else { aCanvas.Brush.Color = HC.clMedGray; } aCanvas.FillRect(aDrawRect); aCanvas.Brush.Style = HCBrushStyle.bsClear; aStyle.TextStyles[TextStyleNo].ApplyStyle(aCanvas, aPaintInfo.ScaleY / aPaintInfo.Zoom); SIZE vSize = aCanvas.TextExtent(FText); aCanvas.TextOut(aDrawRect.Left + (aDrawRect.Width - vSize.cx) / 2, aDrawRect.Top + (aDrawRect.Height - vSize.cy) / 2, FText); }
public void PaintTo(HCCanvas canvas, RECT rect) { int vX = 0, vHeight = this.Height, vW = 0; HCCodeLineType vLineType = HCCodeLineType.White; if (this.FTextVisible) { vHeight -= 12; } RECT vRect = new RECT(); for (int i = 0, vLen = this.FCode.Length; i < vLen; i++) { vLineType = HCCodeLineType.White; this.OneBarProps(this.FCode[i], ref vW, ref vLineType); if (vLineType != HCCodeLineType.White) { canvas.Brush.Color = Color.Black; } else { canvas.Brush.Color = Color.White; } vRect.Left = vX; vRect.Top = 0; vRect.Right = vX + vW * this.FZoom; vRect.Bottom = vHeight; vX = vRect.Right; vRect.Offset(rect.Left, rect.Top); canvas.FillRect(vRect); } if (this.FCode == "") { canvas.Pen.BeginUpdate(); try { canvas.Pen.Width = 1; canvas.Pen.Color = Color.Black; } finally { canvas.Pen.EndUpdate(); } canvas.Rectangle(rect); } if (this.FTextVisible) { canvas.Font.BeginUpdate(); try { canvas.Font.Size = 8; canvas.Font.FontStyles.Value = 0; canvas.Font.Family = "Arial"; canvas.Font.Color = Color.Black; } finally { canvas.Font.EndUpdate(); } canvas.Brush.Style = HCBrushStyle.bsClear; if (this.FCode != "") { canvas.TextOut(rect.Left + (rect.Width - canvas.TextWidth(this.FText)) / 2, rect.Top + vHeight + 2, this.FText); } else { SIZE vSize = canvas.TextExtent("无效条码" + this.FText); canvas.TextOut(rect.Left + (rect.Width - vSize.cx) / 2, rect.Top + (rect.Height - vSize.cy) / 2, "无效条码" + this.FText); } } }