我正在制作高光子,但发生了一些问题 [英] I am making the highligter but some problems happen

查看:66
本文介绍了我正在制作高光子,但发生了一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void canvas_MouseDown(object sender, MouseEventArgs e)
        {
            pt1.X = e.X;
            pt1.Y = e.Y;

        }

  private void canvas_MouseMove(object sender, MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Left)
            {
            
                    pt2.X = e.X;
                    pt2.Y = e.Y;

                    Graphics g = canvas.CreateGraphics();

                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                    Pen mypen = new Pen(Color.FromArgb(40, Color.Blue), 20);
                 
                    mypen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                    
                    
                    g.DrawLine(mypen, pt1, pt2);
                    mypen.Dispose();
                    g.Dispose();
                

                pt1 = pt2;
               
            }
   
        }



我正在制作一个包含钢笔工具功能的绘画程序.
笔工具功能分为两种.
一种是普通笔,其代码与上述代码中的一行不同.
< pen mypen ="new">
所以第一个就可以了.
但是重要的工具(上面的代码)荧光笔无法正常工作.
当我们拖动鼠标点时,某些线被过度套住,有些空间是空的.所以我无法做出完美的高光我不知道如何解决这个问题.帮帮我..它是如此重要. :confused :: confused:



I''m making a paint program which includes pen tool function.
The pen tool fuctios are divided into two kind''s of pens.
one is normal pen which code is different from one line of above code.
<pen mypen="new">
so it''s okay with the first one.
but the important tool(above code), highlighter, is not working properly.
When we drag the mouse point, some lines are overraped and some spaces are vacant. so I can''t make perfect highligter. I don''t know how to solve this problem. Help me.. it''s so important. :confused::confused:

推荐答案

icesky86写道:
icesky86 wrote:

图形g = canvas .CreateGraphics();

Graphics g = canvas.CreateGraphics();



此代码是无用的.别这样您需要处理绘画事件,并在其中传递的图形对象上进行绘制.调用Invalidate()导致绘制事件.

不知道为什么荧光笔不起作用.我会添加一些调试代码,如果您的点序列没有被破坏,那么GDI代码通常会出现问题.否则您使用CreateGraphics会产生绘画问题.



This code is useless. Stop doing this. You need to handle your paint event and do your drawing on the graphics object passed in there. Call Invalidate() to cause a paint event.

Not sure why your highlighter would not work. I''d add some debugging code, if your sequence of points is not broken, then there''s an issue with the GDI code in general. Or your use of CreateGraphics is creating paint issues.


这篇关于我正在制作高光子,但发生了一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆