[c#]橡皮擦命令,可显示框架仅显示但不绘制 [英] [c#] eraser command, reverible frame only showing but not to draw it

查看:133
本文介绍了[c#]橡皮擦命令,可显示框架仅显示但不绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于擦除命令的代码:

I have a code for erase command:

  public void MyMouseDown(Object sender, MouseEventArgs e)
        {
Graphics graphics = CreateGraphics();
int linh = System.Int32.Parse(textBox3.Text);

graphics.FillRectangle(new SolidBrush(Color.White), e.X, e.Y, linh, linh);

SelectRect.Width = 0;
SelectRect.Height = 0;
SelectRect.X = e.X;
SelectRect.Y = e.Y;

SelectRect.Width = linh;
SelectRect.Height = linh;
}


public void MyMouseMove(Object sender, MouseEventArgs e)
        {
Graphics graphics = CreateGraphics();
int linh = System.Int32.Parse(textBox3.Text);

graphics.FillRectangle(new SolidBrush(Color.White), e.X, e.Y,linh,linh);

SelectRect.Width = 0;
SelectRect.Height = 0;
SelectRect.X = e.X;
SelectRect.Y = e.Y;

SelectRect.Width = linh;
SelectRect.Height = linh;

Form thisform = (Form)sender;
ControlPaint.DrawReversibleFrame(thisform.RectangleToScreen(SelectRect), Color.Black, FrameStyle.Dashed);
}


在这里看到产生的图像:

http://www63.zippyshare.com/v/17151299/file .html [ ^ ]

如何解决此问题,使擦除命令就像在MS Paint中一样?仅显示橡皮擦的矩形,但不绘制它.


Picture what this produces is here:

http://www63.zippyshare.com/v/17151299/file.html[^]

How to fix this, so the erase command would be just like in MS Paint? Only to show the rectangle for the eraser but not to draw it.

推荐答案

您严重滥用了Graphics.原则上,在某些情况下可以做您正在做的事情,但是您不能期望这样的渲染将永久显示.您确实不应该创建和创建System.Windows.Graphics实例,应该处理System.Windows.Control.Paint事件或重写System.Windows.Control.OnPaint和事件参数中传递的Graphics实例.

我解释了我过去的所有答案:
Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [在mdi子表单之间画线 [在面板上捕获图形 [
You heavily misuse Graphics. In principle, in some cases it''s possible to do what you are doing, but you cannot expect that such rendering will be shown permanently. You really should not create and instance of System.Windows.Graphics, you should handle System.Windows.Control.Paint event or override System.Windows.Control.OnPaint and the instance of Graphics passed in the event arguments.

I explained everything in my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^].

—SA


这篇关于[c#]橡皮擦命令,可显示框架仅显示但不绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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