Exemple #1
0
 /// <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);
         }
     }
 }
Exemple #2
0
        /// <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 = CDraw.PCOLORS_FORECOLOR2;
                    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));
                }
            }
        }
Exemple #3
0
        /// <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 hRect         = new RECT(0, 0, width, captionHeight);

            paint.FillRect(backColor, hRect);
            RECT lRect = new RECT(0, captionHeight, 5, height);

            paint.FillRect(backColor, lRect);
            RECT rRect = new RECT(width - 5, captionHeight, width, height);

            paint.FillRect(backColor, rRect);
            RECT bRect = new RECT(0, height - 5, width, height);

            paint.FillRect(backColor, bRect);
            RECT contentRect = rect;

            contentRect.top    += captionHeight;
            contentRect.bottom -= 5;
            contentRect.left   += 5;
            contentRect.right  -= 5;
            if (contentRect.right - contentRect.left > 0 && contentRect.bottom - contentRect.top > 0)
            {
                paint.FillRect(CDraw.PCOLORS_WINDOWCONTENTBACKCOLOR, contentRect);
            }
            CDraw.DrawText(paint, Text, foreColor, Font, 5, 5);
        }
Exemple #4
0
        /// <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);
            }
        }
Exemple #5
0
        /// <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);
            }
        }
Exemple #6
0
        /// <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);
                }
            }
        }