/// <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 = CDraw.PCOLORS_FORECOLOR2; if (m_latestData.m_securityCode != null && m_latestData.m_securityCode.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_latestDataLV2.m_sellPrice10); plist.Add(m_latestDataLV2.m_sellPrice9); plist.Add(m_latestDataLV2.m_sellPrice8); plist.Add(m_latestDataLV2.m_sellPrice7); plist.Add(m_latestDataLV2.m_sellPrice6); vlist.Add(m_latestDataLV2.m_sellVolume10); vlist.Add(m_latestDataLV2.m_sellVolume9); vlist.Add(m_latestDataLV2.m_sellVolume8); vlist.Add(m_latestDataLV2.m_sellVolume7); vlist.Add(m_latestDataLV2.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_latestDataLV2.m_buyPrice6); plist.Add(m_latestDataLV2.m_buyPrice7); plist.Add(m_latestDataLV2.m_buyPrice8); plist.Add(m_latestDataLV2.m_buyPrice9); plist.Add(m_latestDataLV2.m_buyPrice10); vlist.Add(m_latestDataLV2.m_buyVolume6); vlist.Add(m_latestDataLV2.m_buyVolume7); vlist.Add(m_latestDataLV2.m_buyVolume8); vlist.Add(m_latestDataLV2.m_buyVolume9); vlist.Add(m_latestDataLV2.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_latestDataLV2.m_avgSellPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestDataLV2.m_avgSellPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(0, m_latestDataLV2.m_allSellVol); CDraw.DrawUnderLineNum(paint, m_latestDataLV2.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_latestDataLV2.m_avgBuyPrice, lastClose); CDraw.DrawUnderLineNum(paint, m_latestDataLV2.m_avgBuyPrice, m_digit, font, color, false, 80, top); color = CDraw.GetPriceColor(m_latestDataLV2.m_allBuyVol, 0); CDraw.DrawUnderLineNum(paint, m_latestDataLV2.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="args">参数</param> public override void OnInvoke(object args) { base.OnInvoke(args); if (args != null) { CMessage message = (CMessage)args; if (message.m_requestID == m_requestID) { //分时数据 if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATA) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestData latestData = datas[0]; if (latestData != null && latestData.m_securityCode == m_securityCode && !latestData.Equal(m_latestData)) { m_latestData = latestData; //设置保留小数的位数 int digit = 2; if (m_latestData.m_securityCode.StartsWith("1") || m_latestData.m_securityCode.StartsWith("5")) { digit = 3; } m_chart.Digit = digit; m_chart.RefreshData(); } } //LV2分时数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATALV2) { LatestDataInfoLV2 dataInfo = new LatestDataInfoLV2(); List <SecurityLatestDataLV2> datas = new List <SecurityLatestDataLV2>(); QuoteService.GetLatestDatasLV2(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestDataLV2 latestDataLV2 = datas[0]; if (latestDataLV2 != null && latestDataLV2.m_securityCode == m_securityCode && !latestDataLV2.Equal(m_latestDataLV2)) { m_latestDataLV2 = latestDataLV2; } } //成交数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHTRANSACTIONDATA) { String securityCode = ""; List <TransactionData> transactionDatas = new List <TransactionData>(); QuoteService.GetTransactionDatas(ref securityCode, transactionDatas, message.m_body, message.m_bodyLength); int transactionDatasSize = transactionDatas.Count; for (int i = 0; i < transactionDatasSize; i++) { TransactionData transactionData = transactionDatas[i]; DateTime date = m_chart.Chart.ConvertNumToDate(transactionData.m_date); GridRow row = new GridRow(); m_gridTransaction.InsertRow(0, row); TransactionDateCell dateCell = new TransactionDateCell(); dateCell.Text = date.ToString("HH:mm:ss"); row.AddCell(0, dateCell); GridCellStyle dateCellStyle = new GridCellStyle(); dateCellStyle.BackColor = COLOR.EMPTY; dateCellStyle.Font = new FONT("SimSun", 14, true, false, false); dateCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR2; dateCell.Style = dateCellStyle; TransactionDataDoubleCell priceCell = new TransactionDataDoubleCell(); priceCell.Digit = 2; priceCell.SetDouble(transactionData.m_price); row.AddCell(1, priceCell); GridCellStyle priceCellStyle = new GridCellStyle(); priceCellStyle.BackColor = COLOR.EMPTY; priceCellStyle.Font = new FONT("SimSun", 14, true, false, false); priceCellStyle.ForeColor = CDraw.GetPriceColor(transactionData.m_price, m_latestData.m_lastClose); priceCell.Style = priceCellStyle; TransactionDataDoubleCell volumeCell = new TransactionDataDoubleCell(); volumeCell.SetDouble(transactionData.m_volume); row.AddCell(2, volumeCell); GridCellStyle volumeCellStyle = new GridCellStyle(); volumeCellStyle.BackColor = COLOR.EMPTY; volumeCellStyle.Font = new FONT("SimSun", 14, true, false, false); if (transactionData.m_type == 0) { volumeCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (transactionData.m_type == 1) { volumeCellStyle.ForeColor = CDraw.PCOLORS_UPCOLOR; } else { volumeCellStyle.ForeColor = CDraw.PCOLORS_DOWNCOLOR; } volumeCell.Style = volumeCellStyle; } m_gridTransaction.Update(); } } Invalidate(); } }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">矩形</param> /// <param name="clipRect">裁剪矩形</param> /// <param name="isAlternate">是否交替行</param> public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate) { int clipW = clipRect.right - clipRect.left; int clipH = clipRect.bottom - clipRect.top; if (clipW > 0 && clipH > 0) { GridA grid = Grid; GridRow row = Row; GridColumn column = Column; if (grid != null && row != null && column != null) { //判断选中 String text = "-"; bool selected = false; List <GridRow> selectedRows = grid.SelectedRows; int selectedRowsSize = selectedRows.Count; for (int i = 0; i < selectedRowsSize; i++) { if (selectedRows[i] == row) { selected = true; break; } } //获取颜色 FONT font = null; long foreColor = COLOR.EMPTY; GridCellStyle style = Style; if (style != null) { foreColor = style.ForeColor; if (style.Font != null) { font = style.Font; } } SecurityFilterInfo info = (row as SecurityFilterResultRow).Info; double value = GetDouble(); if (!double.IsNaN(value)) { if (m_fieldName != null && m_fieldName.Length > 0) { if (m_fieldName == "FILTER") { if (value == 1) { foreColor = CDraw.PCOLORS_FORECOLOR9; text = "是"; } else { foreColor = CDraw.PCOLORS_FORECOLOR7; text = "否"; } } else { foreColor = CDraw.GetPriceColor(value, 0); text = value.ToString("0.0000"); } } else { SecurityLatestData data = info.LatestData; String columnName = column.Name; int dataSize = data != null ? data.m_securityCode.Length : 0; if (columnName == "colNo") { foreColor = CDraw.PCOLORS_FORECOLOR7; text = ((int)value + 1).ToString(); } else if (columnName == "colAmount" || columnName == "colVolume") { if (dataSize > 0) { foreColor = CDraw.PCOLORS_FORECOLOR9; text = ((long)value).ToString(); } } else if (columnName == "colDiff") { if (dataSize > 0) { foreColor = CDraw.GetPriceColor(value, 0); text = value.ToString("0.00"); } } else if (columnName == "colDiffRange") { if (dataSize > 0) { foreColor = CDraw.GetPriceColor(data.m_close, data.m_lastClose); text = value.ToString("0.00") + "%"; } } else if (columnName == "colLastClose") { if (dataSize > 0) { foreColor = CDraw.PCOLORS_FORECOLOR9; text = value.ToString("0.00"); } } else { if (dataSize > 0) { foreColor = CDraw.GetPriceColor(value, data.m_lastClose); text = value.ToString("0.00"); } } } } if (info.GetValue("FILTER") != 1) { foreColor = CDraw.PCOLORS_FORECOLOR8; } SIZE tSize = paint.TextSize(text, font); POINT tPoint = new POINT(rect.right - tSize.cx, rect.top + clipH / 2 - tSize.cy / 2); RECT tRect = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy); paint.DrawText(text, foreColor, font, tRect); if (selected) { paint.DrawLine(CDraw.PCOLORS_LINECOLOR, 2, 0, rect.left, rect.bottom - 1, rect.right, rect.bottom - 1); } } } }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaint(CPaint paint, RECT clipRect) { int width = Width, height = Height; RECT rect = new RECT(1, 1, width, height); int cornerRadius = 10; int cLeft = 1, cTop = 1; bool isDragging = IsDragging, isEditing = m_list.IsEditing; if (!isDragging && isEditing) { Random rd = m_list.m_rd; rect.left += rd.Next(0, 15); rect.top += rd.Next(0, 15); rect.right -= rd.Next(0, 15); rect.bottom -= rd.Next(0, 15); cornerRadius = rd.Next(10, 20); cLeft += rd.Next(0, 5); cTop += rd.Next(0, 5); } paint.DrawGradientRect(COLOR.ARGB(200, 0, 0, 0), COLOR.ARGB(200, 0, 0, 0), rect, cornerRadius, 0); if (this == m_list.SelectedCell) { paint.DrawRoundRect(CDraw.PCOLORS_LINECOLOR, 1, 0, rect, cornerRadius); } else { paint.DrawRoundRect(CDraw.PCOLORS_LINECOLOR3, 1, 0, rect, cornerRadius); } SecurityServiceEx securityService = DataCenter.SecurityService; Security security = new Security(); if (securityService.GetSecurityByCode(m_securityCode, ref security)) { String securityName = security.m_name; FONT font = new FONT("微软雅黑", 20, false, false, false); FONT font2 = new FONT("Arial", 18, false, false, false); if (m_index >= 2 && m_index <= 5) { font.m_fontSize = 18; font2.m_fontSize = 16; } else if (m_index >= 6) { font.m_fontSize = 16; font2.m_fontSize = 14; } String drawCode = m_securityCode.Substring(0, m_securityCode.IndexOf(".")); int left = rect.left + 10; SIZE tSize = paint.TextSize(securityName, font); SIZE tSize2 = paint.TextSize(drawCode, font2); int top = (height - tSize.cy - tSize2.cy) / 2; int mid = left + Math.Max(tSize.cx, tSize2.cx) / 2; CDraw.DrawText(paint, drawCode, CDraw.PCOLORS_FORECOLOR, font2, mid - tSize2.cx / 2, top); CDraw.DrawText(paint, securityName, CDraw.PCOLORS_FORECOLOR, font, mid - tSize.cx / 2, top + tSize2.cy); left += Math.Max(tSize.cx, tSize2.cx) + 20; if (m_list.m_latestDatas.ContainsKey(m_securityCode)) { SecurityLatestData latestData = m_list.m_latestDatas[m_securityCode]; double close = latestData.m_close, lastClose = latestData.m_lastClose; if (lastClose == 0) { lastClose = latestData.m_close; } //升跌 double diff = 0; double rate = 0; if (close == 0) { diff = latestData.m_buyPrice1 - lastClose; rate = 100 * (latestData.m_buyPrice1 - lastClose) / lastClose; } else { diff = close - latestData.m_lastClose; rate = 100 * (close - lastClose) / lastClose; } long color = CDraw.GetPriceColor(close, lastClose); String strRate = rate.ToString("0.00") + "%", strClose = close.ToString("0.00"); if (rate > 0) { strRate = "+" + strRate; } tSize = paint.TextSize(strRate, font2); tSize2 = paint.TextSize(strClose, font2); if (m_index > 1) { mid = left + Math.Max(tSize.cx, tSize2.cx) / 2; CDraw.DrawText(paint, strClose, color, font2, mid - tSize2.cx / 2, top); CDraw.DrawText(paint, strRate, color, font2, mid - tSize.cx / 2, top + tSize2.cy + 5); } else { CDraw.DrawText(paint, strClose, color, font2, left, top); CDraw.DrawText(paint, strRate, color, font2, left + tSize.cx, top); } } } //绘制图标 if (m_index <= 1) { int iLeft = 100, iTop = 45, iSize = 30; if (!isDragging && isEditing) { Random rd = m_list.m_rd; iLeft += rd.Next(0, 10); iTop += rd.Next(0, 10); } List <String> images = new List <String>(); images.Add("attention.png"); images.Add("search.png"); images.Add("note.png"); images.Add("news.png"); for (int i = 0; i < 4; i++) { paint.DrawImage(images[i], new RECT(iLeft, iTop, iLeft + iSize, iTop + iSize)); iLeft += iSize + 20; } images.Clear(); } //是否正在关闭 if (!isDragging && isEditing) { FONT font = new FONT("微软雅黑", 16, false, false, false); SIZE cSize = new SIZE(30, 30); long lineColor = CDraw.PCOLORS_LINECOLOR; RECT ellipseRect = new RECT(cLeft, cTop, cLeft + cSize.cx, cTop + cSize.cy); paint.FillEllipse(CDraw.PCOLORS_UPCOLOR, ellipseRect); SIZE tSize = paint.TextSize("删", font); CDraw.DrawText(paint, "删", COLOR.CONTROLTEXT, font, ellipseRect.left + (cSize.cx - tSize.cx) / 2, ellipseRect.top + (cSize.cy - tSize.cy) / 2); paint.DrawEllipse(lineColor, 1, 0, ellipseRect); } }
/// <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_FORECOLOR, font, rectangle.left + 25, rectangle.top + 2); DateTime date = DateTime.Now; if (crossStopIndex >= 0) { double dateNum = dataSource.GetXValue(crossStopIndex); if (dateNum != 0) { date = chart.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_FORECOLOR; 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); } } }