/// <summary> /// 重绘前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; RECT rect = new RECT(0, 0, width, height - 1); long foreColor = CDraw.PCOLORS_WINDOWFORECOLOR; int captionHeight = CaptionHeight; RECT contentRect = rect; contentRect.top += captionHeight; contentRect.bottom -= 6; contentRect.left += 6; contentRect.right -= 6; paint.BeginPath(); paint.AddRect(contentRect); paint.ExcludeClipPath(); paint.ClosePath(); paint.FillGradientRect(CDraw.PCOLORS_BACKCOLOR2, CDraw.PCOLORS_BACKCOLOR2, rect, 6, 0); paint.SetClip(clipRect); paint.FillGradientRect(CDraw.PCOLORS_BACKCOLOR, CDraw.PCOLORS_BACKCOLOR2, new RECT(0, 0, width, captionHeight), 6, 90); paint.DrawRoundRect(COLOR.CONTROLBORDER, 1, 0, rect, 6); if (contentRect.right - contentRect.left > 0 && contentRect.bottom - contentRect.top > 0) { contentRect.top -= 1; contentRect.left -= 1; contentRect.right += 1; contentRect.bottom += 1; paint.FillGradientRect(CDraw.PCOLORS_BACKCOLOR2, CDraw.PCOLORS_BACKCOLOR2, contentRect, 6, 0); //paint.FillRect(CDraw.PCOLORS_WINDOWCONTENTBACKCOLOR, contentRect); } paint.DrawLine(COLOR.CONTROLBORDER, 1, 0, 0, captionHeight - 1, width, captionHeight - 1); CDraw.DrawText(paint, Text, foreColor, Font, 10, 4); }
/// <summary> /// 重绘前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; RECT rect = new RECT(0, 0, width, height); long backColor = CDraw.PCOLORS_WINDOWBACKCOLOR; long foreColor = CDraw.PCOLORS_WINDOWFORECOLOR; if (paint.SupportTransparent()) { backColor = CDraw.PCOLORS_WINDOWBACKCOLOR2; } int captionHeight = CaptionHeight; RECT contentRect = rect; contentRect.top += captionHeight; contentRect.bottom -= 6; contentRect.left += 6; contentRect.right -= 6; paint.BeginPath(); paint.AddRect(contentRect); paint.ExcludeClipPath(); paint.ClosePath(); paint.FillRoundRect(backColor, rect, 6); paint.SetClip(clipRect); if (contentRect.right - contentRect.left > 0 && contentRect.bottom - contentRect.top > 0) { contentRect.top -= 1; contentRect.left -= 1; contentRect.right += 1; contentRect.bottom += 1; paint.FillRect(CDraw.PCOLORS_WINDOWCONTENTBACKCOLOR, contentRect); } CDraw.DrawText(paint, Text, foreColor, Font, 5, 3); }
/// <summary> /// 绘制有下划线的数字 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="value">值</param> /// <param name="digit">保留小数位数</param> /// <param name="font">字体</param> /// <param name="fontColor">文字颜色</param> /// <param name="zeroAsEmpty">0是否为空</param> /// <param name="x">横坐标</param> /// <param name="y">纵坐标</param> /// <returns>绘制的横坐标</returns> public static int DrawUnderLineNum(CPaint paint, double value, int digit, FONT font, long fontColor, bool zeroAsEmpty, int x, int y) { if (zeroAsEmpty && value == 0) { String text = "-"; SIZE size = paint.TextSize(text, font); CDraw.DrawText(paint, text, fontColor, font, x, y); return(size.cx); } else { String[] nbs = CStr.GetValueByDigit(value, digit).Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (nbs.Length == 1) { SIZE size = paint.TextSize(nbs[0], font); CDraw.DrawText(paint, nbs[0], fontColor, font, x, y); return(size.cx); } else { SIZE decimalSize = paint.TextSize(nbs[0], font); SIZE size = paint.TextSize(nbs[1], font); CDraw.DrawText(paint, nbs[0], fontColor, font, x, y); CDraw.DrawText(paint, nbs[1], fontColor, font, x + decimalSize.cx + 1, y); paint.DrawLine(fontColor, 1, 0, x + decimalSize.cx + 1, y + decimalSize.cy, x + decimalSize.cx + size.cx, y + decimalSize.cy); return(decimalSize.cx + size.cx); } } }
/// <summary> /// 绘制背景 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width - 1, height = Height - 1; RECT drawRect = new RECT(0, 0, width, height); paint.FillRect(COLOR.ARGB(0, 0, 0), drawRect); int outSize = 40; int oX = width / 2, oY = height / 2, r = (width - outSize * 2) / 2; long innerBorderColor = COLOR.ARGB(100, 100, 100); int[] angles = new int[] { 240, 180, 120, 60, 0, -60 }; int[] rs = new int[] { r, r * 2 / 3, r / 3 }; for (int i = 0; i < 3; i++) { POINT[] drawPoints = new POINT[6]; for (int j = 0; j < 6; j++) { drawPoints[j] = GetCyclePoint(oX, oY, rs[i], angles[j]); } paint.DrawPolygon(innerBorderColor, 1, 0, drawPoints); } FONT pFont = new FONT("微软雅黑", 16, false, false, false); POINT[] points = GetTitlePoints(); int pointsSize = points.Length; String[] strs = new String[] { "业务", "情商", "学识", "智商", "管理", "技术" }; int[] values = new int[6]; if (m_dimension != null) { values = new int[] { m_dimension.m_business, m_dimension.m_EQ, m_dimension.m_knowledge, m_dimension.m_IQ, m_dimension.m_lead, m_dimension.m_technology }; } POINT [] scopePoints = GetScopePoints(); for (int i = 0; i < pointsSize; i++) { int bSize = 5; POINT bPoint = points[i]; RECT bRect = new RECT(bPoint.x - bSize, bPoint.y - bSize, bPoint.x + bSize, bPoint.y + bSize); SIZE pSize = paint.TextSize(strs[i], pFont); if (i == 0 || i == 5) { bPoint.y -= 20; } CDraw.DrawText(paint, strs[i], m_sysColors[i], pFont, bPoint.x - pSize.cx / 2, bPoint.y - pSize.cy / 2); int iSize = 5; POINT cp = GetCyclePoint(oX, oY, r, angles[i]); paint.DrawLine(innerBorderColor, 1, 0, oX, oY, cp.x, cp.y); paint.FillEllipse(m_sysColors[i], new RECT(cp.x - iSize, cp.y - iSize, cp.x + iSize, cp.y + iSize)); String text = String.Format("({0})", CStr.ConvertIntToStr(values[i])); SIZE sSize = paint.TextSize(text, pFont); CDraw.DrawText(paint, text, m_sysColors[i], pFont, bPoint.x - sSize.cx / 2, bPoint.y + sSize.cy / 2); } if (m_dimension != null) { paint.FillGradientPolygon(COLOR.ARGB(200, 50, 105, 217), COLOR.ARGB(200, 50, 105, 217), scopePoints, 90); paint.DrawPolygon(COLOR.ARGB(100, 255, 255, 255), 1, 0, scopePoints); } }
/// <summary> /// 绘制前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintForeground(CPaint paint, RECT clipRect) { RECT bounds = Bounds; int width = bounds.right - bounds.left; int height = bounds.bottom - bounds.top; if (width > 0 && height > 0) { if (m_ssLatestData != null && m_szLatestData != null && m_cyLatestData != null) { long titleColor = COLOR.ARGB(255, 255, 80); FONT font = new FONT("SimSun", 16, false, false, false); FONT indexFont = new FONT("Arial", 14, true, false, false); long grayColor = CDraw.PCOLORS_FORECOLOR4; //上证指数 long indexColor = CDraw.GetPriceColor(m_ssLatestData.m_close, m_ssLatestData.m_lastClose); int left = 1; CDraw.DrawText(paint, "上证", titleColor, font, left, 3); left += 40; paint.DrawLine(grayColor, 1, 0, left, 0, left, height); String amount = (m_ssLatestData.m_amount / 100000000).ToString("0.0") + "亿"; SIZE amountSize = paint.TextSize(amount, indexFont); CDraw.DrawText(paint, amount, titleColor, indexFont, width / 3 - amountSize.cx, 3); left += (width / 3 - 40 - amountSize.cx) / 4; int length = CDraw.DrawUnderLineNum(paint, m_ssLatestData.m_close, 2, indexFont, indexColor, false, left, 3); left += length + (width / 3 - 40 - amountSize.cx) / 4; length = CDraw.DrawUnderLineNum(paint, m_ssLatestData.m_close - m_ssLatestData.m_lastClose, 2, indexFont, indexColor, false, left, 3); //深证指数 left = width / 3; paint.DrawLine(grayColor, 1, 0, left, 0, left, height); indexColor = CDraw.GetPriceColor(m_szLatestData.m_close, m_szLatestData.m_lastClose); CDraw.DrawText(paint, "深证", titleColor, font, left, 3); left += 40; paint.DrawLine(grayColor, 1, 0, left, 0, left, height); amount = (m_szLatestData.m_amount / 100000000).ToString("0.0") + "亿"; amountSize = paint.TextSize(amount, indexFont); CDraw.DrawText(paint, amount, titleColor, indexFont, width * 2 / 3 - amountSize.cx, 3); left += (width / 3 - 40 - amountSize.cx) / 4; length = CDraw.DrawUnderLineNum(paint, m_szLatestData.m_close, 2, indexFont, indexColor, false, left, 3); left += length + (width / 3 - 40 - amountSize.cx) / 4; length = CDraw.DrawUnderLineNum(paint, m_szLatestData.m_close - m_szLatestData.m_lastClose, 2, indexFont, indexColor, false, left, 3); //创业指数 left = width * 2 / 3; paint.DrawLine(grayColor, 1, 0, left, 0, left, height); indexColor = CDraw.GetPriceColor(m_cyLatestData.m_close, m_cyLatestData.m_lastClose); CDraw.DrawText(paint, "创业", titleColor, font, left, 3); left += 40; paint.DrawLine(grayColor, 1, 0, left, 0, left, height); amount = (m_cyLatestData.m_amount / 100000000).ToString("0.0") + "亿"; amountSize = paint.TextSize(amount, indexFont); CDraw.DrawText(paint, amount, titleColor, indexFont, width - amountSize.cx, 3); left += (width / 3 - 40 - amountSize.cx) / 4; length = CDraw.DrawUnderLineNum(paint, m_cyLatestData.m_close, 2, indexFont, indexColor, false, left, 3); left += (width / 3 - 40 - amountSize.cx) / 4 + length; length = CDraw.DrawUnderLineNum(paint, m_cyLatestData.m_close - m_cyLatestData.m_lastClose, 2, indexFont, indexColor, false, left, 3); paint.DrawRect(grayColor, 1, 0, new RECT(0, 0, width - 1, height - 1)); } } }
/// <summary> /// 绘图方法 /// </summary> /// <param name="sender">调用者</param> /// <param name="paint">绘图</param> /// <param name="clipRect">裁剪区域</param> private void PaintDiv(object sender, CPaint paint, RECT clipRect) { List <DialogInfo> dialogs = DataCenter.DialogService.m_dialogs; int dialogsSize = dialogs.Count; Dictionary <String, int> names = new Dictionary <String, int>(); for (int i = 0; i < dialogsSize; i++) { DialogInfo dialog = dialogs[i]; if (names.ContainsKey(dialog.m_name)) { names[dialog.m_name] = names[dialog.m_name] + 1; } else { names[dialog.m_name] = 1; } } List <DialogData> datas = new List <DialogData>(); foreach (String key in names.Keys) { DialogData data = new DialogData(); data.m_name = key; data.m_times = names[key]; datas.Add(data); } datas.Sort(new DialogDataCompare()); int width = m_divDialogs.Width, height = m_divDialogs.Height; int datasSize = datas.Count; if (datasSize > 0) { int paddingLeft = 50, paddingRight = 50, paddingTop = 20, paddingBottom = 20; int top = paddingTop; int pSize = (height - paddingTop - paddingBottom) / datasSize; double max = 0; for (int i = 0; i < datasSize; i++) { DialogData data = datas[i]; if (i == 0) { max = data.m_times; } int wSize = (int)((width - paddingLeft - paddingRight) * data.m_times / max); CDraw.DrawText(paint, data.m_name, COLOR.ARGB(0, 0, 0), m_divDialogs.Font, 5, top); paint.FillGradientRect(m_sysColors[i % m_sysColors.Length], m_sysColors[(i + 1) % m_sysColors.Length], new RECT(paddingLeft, top + 2, paddingLeft + wSize, top + 12), 2, 0); FONT font = new FONT("微软雅黑", 14, false, false, false); CDraw.DrawText(paint, data.m_times.ToString(), COLOR.ARGB(0, 0, 0), font, paddingLeft + wSize, top); top += pSize; } } }
/// <summary> /// 绘制前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintForeground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; if (width > 0 && height > 0) { FONT font = new FONT("SimSun", 16, false, false, false); FONT lfont = new FONT("SimSun", 14, false, false, false); long wordColor = CDraw.PCOLORS_FORECOLOR5; int top = 32, step = 20; //画买卖盘 CDraw.DrawText(paint, "卖", wordColor, font, 1, (m_lV2 ? 87 : 47)); CDraw.DrawText(paint, "盘", wordColor, font, 1, (m_lV2 ? 140 : 100)); CDraw.DrawText(paint, "买", wordColor, font, 1, (m_lV2 ? 267 : 147)); CDraw.DrawText(paint, "盘", wordColor, font, 1, (m_lV2 ? 310 : 200)); String buySellStr = "5,4,3,2,1,1,2,3,4,5"; if (m_lV2) { step = 16; buySellStr = "总卖量,10,9,8,7,6," + buySellStr + ",6,7,8,9,10,总买量"; font.m_fontSize = 14; } String[] buySellStrs = buySellStr.Split(','); int strsSize = buySellStrs.Length; for (int i = 0; i < strsSize; i++) { CDraw.DrawText(paint, buySellStrs[i], wordColor, font, 25, top); top += step; } font.m_fontSize = 16; top = m_lV2 ? 390 : 232; CDraw.DrawText(paint, "最新", wordColor, font, 1, top); CDraw.DrawText(paint, "升跌", wordColor, font, 1, top + 20); CDraw.DrawText(paint, "幅度", wordColor, font, 1, top + 40); CDraw.DrawText(paint, "总手", wordColor, font, 1, top + 60); CDraw.DrawText(paint, "涨停", wordColor, font, 1, top + 80); CDraw.DrawText(paint, "外盘", wordColor, font, 1, top + 100); CDraw.DrawText(paint, "开盘", wordColor, font, 110, top); CDraw.DrawText(paint, "最高", wordColor, font, 110, top + 20); CDraw.DrawText(paint, "最低", wordColor, font, 110, top + 40); CDraw.DrawText(paint, "换手", wordColor, font, 110, top + 60); CDraw.DrawText(paint, "跌停", wordColor, font, 110, top + 80); CDraw.DrawText(paint, "内盘", wordColor, font, 110, top + 100); font.m_bold = true; //画股票代码 long yellowColor = COLOR.ARGB(255, 255, 80); if (m_latestData.m_code != null && m_latestData.m_code.Length > 0) { double close = m_latestData.m_close, open = m_latestData.m_open, high = m_latestData.m_high, low = m_latestData.m_low, lastClose = m_latestData.m_lastClose; if (close == 0) { if (m_latestData.m_buyPrice1 > 0) { close = m_latestData.m_buyPrice1; open = m_latestData.m_buyPrice1; high = m_latestData.m_buyPrice1; low = m_latestData.m_buyPrice1; } else if (m_latestData.m_sellPrice1 > 0) { close = m_latestData.m_sellPrice1; open = m_latestData.m_sellPrice1; high = m_latestData.m_sellPrice1; low = m_latestData.m_sellPrice1; } } if (lastClose == 0) { lastClose = close; } List <double> plist = new List <double>(); List <double> vlist = new List <double>(); if (m_lV2) { plist.Add(m_latestData.m_sellPrice10); plist.Add(m_latestData.m_sellPrice9); plist.Add(m_latestData.m_sellPrice8); plist.Add(m_latestData.m_sellPrice7); plist.Add(m_latestData.m_sellPrice6); vlist.Add(m_latestData.m_sellVolume10); vlist.Add(m_latestData.m_sellVolume9); vlist.Add(m_latestData.m_sellVolume8); vlist.Add(m_latestData.m_sellVolume7); vlist.Add(m_latestData.m_sellVolume6); } plist.Add(m_latestData.m_sellPrice5); plist.Add(m_latestData.m_sellPrice4); plist.Add(m_latestData.m_sellPrice3); plist.Add(m_latestData.m_sellPrice2); plist.Add(m_latestData.m_sellPrice1); vlist.Add(m_latestData.m_sellVolume5); vlist.Add(m_latestData.m_sellVolume4); vlist.Add(m_latestData.m_sellVolume3); vlist.Add(m_latestData.m_sellVolume2); vlist.Add(m_latestData.m_sellVolume1); plist.Add(m_latestData.m_buyPrice1); plist.Add(m_latestData.m_buyPrice2); plist.Add(m_latestData.m_buyPrice3); plist.Add(m_latestData.m_buyPrice4); plist.Add(m_latestData.m_buyPrice5); vlist.Add(m_latestData.m_buyVolume1); vlist.Add(m_latestData.m_buyVolume2); vlist.Add(m_latestData.m_buyVolume3); vlist.Add(m_latestData.m_buyVolume4); vlist.Add(m_latestData.m_buyVolume5); if (m_lV2) { plist.Add(m_latestData.m_buyPrice6); plist.Add(m_latestData.m_buyPrice7); plist.Add(m_latestData.m_buyPrice8); plist.Add(m_latestData.m_buyPrice9); plist.Add(m_latestData.m_buyPrice10); vlist.Add(m_latestData.m_buyVolume6); vlist.Add(m_latestData.m_buyVolume7); vlist.Add(m_latestData.m_buyVolume8); vlist.Add(m_latestData.m_buyVolume9); vlist.Add(m_latestData.m_buyVolume10); } long color = 0; double max = Max(vlist); font.m_fontSize = m_lV2 ? 14 : 16; if (max > 0) { //绘制买卖盘 int pLength = plist.Count; top = 32; if (m_lV2) { color = CDraw.GetPriceColor(m_latestData.m_avgSellPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestData.m_avgSellPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(0, m_latestData.m_allSellVol); CDraw.DrawUnderLineNum(paint, m_latestData.m_allSellVol, 0, font, yellowColor, false, 130, top); top += step; } for (int i = 0; i < pLength; i++) { color = CDraw.GetPriceColor(plist[i], lastClose); CDraw.DrawUnderLineNum(paint, plist[i], m_digit, font, color, true, m_lV2 ? 80 : 60, top); CDraw.DrawUnderLineNum(paint, vlist[i], 0, font, yellowColor, false, m_lV2 ? 130 : 110, top); paint.FillRect(color, new RECT(width - (int)(vlist[i] / max * 50), top + step / 2 - 2, width, top + step / 2 + 2)); top += step; } if (m_lV2) { color = CDraw.GetPriceColor(m_latestData.m_avgBuyPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestData.m_avgBuyPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(m_latestData.m_allBuyVol, 0); CDraw.DrawUnderLineNum(paint, m_latestData.m_allBuyVol, 0, font, yellowColor, false, 130, top); top += step; } } vlist.Clear(); plist.Clear(); top = m_lV2 ? 390 : 232; //成交 color = CDraw.GetPriceColor(close, lastClose); CDraw.DrawUnderLineNum(paint, close, m_digit, font, color, true, 45, top); //升跌 double sub = 0; if (close == 0) { sub = m_latestData.m_buyPrice1 - lastClose; double rate = 100 * (m_latestData.m_buyPrice1 - lastClose) / lastClose; int pleft = CDraw.DrawUnderLineNum(paint, rate, 2, font, color, false, 45, top + 40); CDraw.DrawText(paint, "%", color, font, pleft + 47, top + 40); } else { sub = close - m_latestData.m_lastClose; double rate = 100 * (close - lastClose) / lastClose; int pleft = CDraw.DrawUnderLineNum(paint, rate, 2, font, color, false, 45, top + 40); CDraw.DrawText(paint, "%", color, font, pleft + 47, top + 40); } CDraw.DrawUnderLineNum(paint, sub, m_digit, font, color, false, 45, top + 20); double volume = m_latestData.m_volume / 100; String unit = ""; if (volume > 100000000) { volume /= 100000000; unit = "亿"; } else if (volume > 10000) { volume /= 10000; unit = "万"; } //总手 int cleft = CDraw.DrawUnderLineNum(paint, volume, unit.Length > 0 ? m_digit : 0, font, yellowColor, true, 45, top + 60); if (unit.Length > 0) { CDraw.DrawText(paint, unit, yellowColor, font, cleft + 47, top + 60); } //换手 double turnoverRate = m_latestData.m_turnoverRate; cleft = CDraw.DrawUnderLineNum(paint, turnoverRate, 2, font, yellowColor, true, 155, top + 60); if (turnoverRate > 0) { CDraw.DrawText(paint, "%", yellowColor, font, cleft + 157, top + 60); } //开盘 color = CDraw.GetPriceColor(open, lastClose); CDraw.DrawUnderLineNum(paint, open, m_digit, font, color, true, 155, top); //最高 color = CDraw.GetPriceColor(high, lastClose); CDraw.DrawUnderLineNum(paint, high, m_digit, font, color, true, 155, top + 20); //最低 color = CDraw.GetPriceColor(low, lastClose); CDraw.DrawUnderLineNum(paint, low, m_digit, font, color, true, 155, top + 40); //涨停 double upPrice = lastClose * 1.1; if (m_securityName != null && m_securityName.Length > 0) { if (m_securityName.StartsWith("ST") || m_securityName.StartsWith("*ST")) { upPrice = lastClose * 1.05; } } CDraw.DrawUnderLineNum(paint, upPrice, m_digit, font, CDraw.PCOLORS_UPCOLOR, true, 45, top + 80); //跌停 double downPrice = lastClose * 0.9; if (m_securityName != null && m_securityName.Length > 0) { if (m_securityName.StartsWith("ST") || m_securityName.StartsWith("*ST")) { downPrice = lastClose * 0.95; } } CDraw.DrawUnderLineNum(paint, downPrice, m_digit, font, CDraw.PCOLORS_DOWNCOLOR, true, 155, top + 80); //外盘 double outerVol = m_latestData.m_outerVol; unit = ""; if (outerVol > 100000000) { outerVol /= 100000000; unit = "亿"; } else if (outerVol > 10000) { outerVol /= 10000; unit = "万"; } cleft = CDraw.DrawUnderLineNum(paint, outerVol, unit.Length > 0 ? m_digit : 0, font, CDraw.PCOLORS_UPCOLOR, false, 45, top + 100); if (unit.Length > 0) { CDraw.DrawText(paint, unit, CDraw.PCOLORS_UPCOLOR, font, cleft + 47, top + 100); } unit = ""; double innerVol = m_latestData.m_innerVol; if (innerVol > 100000000) { innerVol /= 100000000; unit = "亿"; } else if (innerVol > 10000) { innerVol /= 10000; unit = "万"; } //内盘 cleft = CDraw.DrawUnderLineNum(paint, innerVol, unit.Length > 0 ? m_digit : 0, font, CDraw.PCOLORS_DOWNCOLOR, true, 155, top + 100); if (unit.Length > 0) { CDraw.DrawText(paint, unit, CDraw.PCOLORS_DOWNCOLOR, font, cleft + 157, top + 100); } } font.m_bold = false; font.m_fontSize = 20; //股票代码 if (m_securityCode != null && m_securityCode.Length > 0) { CDraw.DrawText(paint, m_securityCode, CDraw.PCOLORS_FORECOLOR3, font, 2, 4); } //股票名称 if (m_securityName != null && m_securityName.Length > 0) { CDraw.DrawText(paint, m_securityName, yellowColor, font, 100, 4); } //画边框 long frameColor = CDraw.PCOLORS_LINECOLOR4; paint.DrawLine(frameColor, 1, 0, 0, 0, 0, height); paint.DrawLine(frameColor, 1, 0, 0, 30, width, 30); paint.DrawLine(frameColor, 1, 0, 24, 30, 24, top - 2); paint.DrawLine(frameColor, 1, 0, 0, m_lV2 ? 208 : 130, width, m_lV2 ? 208 : 130); paint.DrawLine(frameColor, 1, 0, 0, top - 2, width, top - 2); paint.DrawLine(frameColor, 1, 0, width, 0, width, height); paint.DrawLine(frameColor, 1, 0, 0, top + 120, width, top + 120); } }
/// <summary> /// 重绘背景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; if (width > 0 && height > 0) { ChartA chart = m_chart.Chart; //十字线出现时进行绘制 if (chart.ShowCrossLine) { CTable dataSource = chart.DataSource; //获取鼠标停留索引 int crossStopIndex = chart.CrossStopIndex; if (dataSource.RowsCount > 0) { if (crossStopIndex < 0) { crossStopIndex = chart.FirstVisibleIndex; } if (crossStopIndex > chart.LastVisibleIndex) { crossStopIndex = chart.LastVisibleIndex; } } else { crossStopIndex = -1; } //获取K线和成交量 RECT rectangle = new RECT(0, 0, width, height); long win32Color = COLOR.EMPTY; paint.FillRect(GetPaintingBackColor(), rectangle); paint.DrawRect(GetPaintingBorderColor(), 1, 0, rectangle); //画关闭按钮 long lineColor = CDraw.PCOLORS_LINECOLOR; paint.DrawLine(lineColor, 2, 0, width - 6, 4, width - 14, 12); paint.DrawLine(lineColor, 2, 0, width - 6, 12, width - 14, 4); //创建字体 FONT font = new FONT("SimSun", 14, false, false, false); FONT lfont = new FONT("Arial", 12, false, false, false); FONT nfont = new FONT("Arial", 14, true, false, false); //画日期 CDraw.DrawText(paint, "时 间", CDraw.PCOLORS_FORECOLOR4, font, rectangle.left + 25, rectangle.top + 2); DateTime date = DateTime.Now; if (crossStopIndex >= 0) { double dateNum = dataSource.GetXValue(crossStopIndex); if (dateNum != 0) { date = CStr.ConvertNumToDate(dateNum); } String dateStr = ""; int cycle = m_chart.Cycle; if (cycle <= 1) { dateStr = date.ToString("hh:mm"); } else if (cycle >= 5 && cycle <= 60) { dateStr = date.ToString("MM-dd hh:mm"); } else { dateStr = date.ToString("yyyy-MM-dd"); } SIZE dtSize = paint.TextSize(dateStr, lfont); CDraw.DrawText(paint, dateStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - dtSize.cx / 2, rectangle.top + 20); //获取值 double close = 0, high = 0, low = 0, open = 0, amount = 0; if (crossStopIndex >= 0) { close = dataSource.Get2(crossStopIndex, KeyFields.CLOSE_INDEX); high = dataSource.Get2(crossStopIndex, KeyFields.HIGH_INDEX); low = dataSource.Get2(crossStopIndex, KeyFields.LOW_INDEX); open = dataSource.Get2(crossStopIndex, KeyFields.OPEN_INDEX); amount = dataSource.Get2(crossStopIndex, KeyFields.AMOUNT_INDEX); } if (double.IsNaN(close)) { close = 0; } if (double.IsNaN(high)) { high = 0; } if (double.IsNaN(low)) { low = 0; } if (double.IsNaN(open)) { open = 0; } if (double.IsNaN(amount)) { amount = 0; } double rate = 1; double lastClose = 0; if (crossStopIndex > 1) { lastClose = dataSource.Get2(crossStopIndex - 1, KeyFields.CLOSE_INDEX); if (cycle == 0) { lastClose = m_chart.LatestData.m_lastClose; } if (!double.IsNaN(lastClose)) { if (lastClose != 0) { rate = (close - lastClose) / lastClose; } } } //开盘价 String openStr = double.IsNaN(open) ? "" : CStr.GetValueByDigit(open, m_digit).ToString(); SIZE tSize = paint.TextSize(openStr, nfont); CDraw.DrawText(paint, openStr, CDraw.GetPriceColor(open, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 60); //最高价 String highStr = double.IsNaN(high) ? "" : CStr.GetValueByDigit(high, m_digit).ToString(); tSize = paint.TextSize(highStr, nfont); CDraw.DrawText(paint, highStr, CDraw.GetPriceColor(high, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 100); //最低价 String lowStr = double.IsNaN(low) ? "" : CStr.GetValueByDigit(low, m_digit).ToString(); tSize = paint.TextSize(lowStr, nfont); CDraw.DrawText(paint, lowStr, CDraw.GetPriceColor(low, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 140); //最低价 String closeStr = double.IsNaN(close) ? "" : CStr.GetValueByDigit(close, m_digit).ToString(); tSize = paint.TextSize(closeStr, nfont); CDraw.DrawText(paint, closeStr, CDraw.GetPriceColor(close, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 180); //成交量 String unit = ""; if (amount > 100000000) { amount /= 100000000; unit = "亿"; } else if (amount > 10000) { amount /= 10000; unit = "万"; } String amountStr = CStr.GetValueByDigit(amount, 2) + unit; tSize = paint.TextSize(amountStr, lfont); CDraw.DrawText(paint, amountStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 220); //涨幅 String rangeStr = double.IsNaN(rate) ? "0.00%" : rate.ToString("0.00%"); tSize = paint.TextSize(rangeStr, nfont); CDraw.DrawText(paint, rangeStr, CDraw.GetPriceColor(close, lastClose), lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 260); } long whiteColor = CDraw.PCOLORS_FORECOLOR4; CDraw.DrawText(paint, "开 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 40); CDraw.DrawText(paint, "最 高", whiteColor, font, rectangle.left + 25, rectangle.top + 80); CDraw.DrawText(paint, "最 低", whiteColor, font, rectangle.left + 25, rectangle.top + 120); CDraw.DrawText(paint, "收 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 160); CDraw.DrawText(paint, "金 额", whiteColor, font, rectangle.left + 25, rectangle.top + 200); CDraw.DrawText(paint, "涨 幅", whiteColor, font, rectangle.left + 25, rectangle.top + 240); } } }