开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 2039|回复: 0

[求助] 求助一个drawLine的问题

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
4
软币
96
在线时间
3 小时
注册时间
2019-12-12
发表于 2019-12-13 16:51:15 | 显示全部楼层 |阅读模式
大家好,本人是C#的初学者,现在碰到个DrawLine的问题。

1.我如果直接调用DrawLine没有任何问题,主要代码如下:
               foreach (var lines in marchingSquares.contourData)
                {
                    foreach (var line in lines.Value)
                    {
                        int cur_startY = Convert.ToInt32(line.startPoint.Y * length);
                        int cur_startX = Convert.ToInt32(image.Height - line.startPoint.X * length);
                        int cur_endY = Convert.ToInt32(line.endPoint.Y * length);
                        int cur_endX = Convert.ToInt32(image.Height - line.endPoint.X * length);                                       
                        g.DrawLine(pen, cur_startY, cur_startX, cur_endY, cur_endX);
                                                     
                    }
                }
2.但是现在为了实现线条的可编辑,自己定义了一个控件,在控件中drawLine,主要代码如下:
   List<Line_EXT> lineExtList = new List<Line_EXT>();
                foreach (var lines in marchingSquares.contourData)
                {
                    foreach (var line in lines.Value)
                    {
                        int cur_startY = Convert.ToInt32(line.startPoint.Y * length);
                        int cur_startX = Convert.ToInt32(image.Height - line.startPoint.X * length);
                        int cur_endY = Convert.ToInt32(line.endPoint.Y * length);
                        int cur_endX = Convert.ToInt32(image.Height - line.endPoint.X * length);

                        lineExtList.Add(new Line_EXT(cur_startY,cur_startX,cur_endY,cur_endX));               
                    }
                }
                                mouseDragCurveImpl = new MouseDragCurve(g,pen,lineExtList);
                mouseDragCurveImpl.Location = new Point(0, 0);
                mouseDragCurveImpl.Dock = System.Windows.Forms.DockStyle.Fill;
                this.contourMap.Controls.Add(mouseDragCurveImpl);

lineExtList保存了所有线段的起点和终点。MouseDragCurve class定义如下:
class MouseDragCurve : Control
    {
        // client rectangle
        Rectangle clientRect;

        //flag
        bool mouseDown = false;
                private Graphics g;
                private Pen pen;
                List<Line_EXT> lineExtList;
        #region Inits
        public MouseDragCurve(Graphics g,Pen pen,List<Line_EXT> lineExtList)
        {
                this.g = g;
               this.pen = pen;
                this.lineExtList = lineExtList;               
               this.BackColor = Color.White;
               this.DoubleBuffered = true; // 双缓冲,避免闪烁
        }


        void drawCurve()
        {

            for(int i = 0;i < lineExtList.Count;i++)
            {
                   g.DrawLine(pen,lineExtList[i].startY,lineExtList[i].startX,lineExtList[i].endY,lineExtList[i].endX);
             }  
        }


         protected override void OnPaint(PaintEventArgs e)
        {
            drawCurve();
        }

       经过调试OnPaint,drawCurve都调用到了,为什么图没显示出来,请大家指教,谢谢。不胜感激!

回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-5-5 04:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表