如何在油漆中编写橡皮擦... [英] how to code for an eraser in paint...

查看:129
本文介绍了如何在油漆中编写橡皮擦...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以帮我解决一下橡皮擦和多种颜色的代码(比如ms-paint)吗?

当我们点击时如何将鼠标指针改为笔刷那些相应的按钮?



任何人请回复我,请至少给我一个想法。

解决方案

< blockquote>鼠标指针很简单: Cursor = new Cursor(...); (有关详细信息,请参阅MSDN,根据存储光标形状的方式,有四种不同的构造函数) 。



多种颜色/橡皮擦的编码有点困难,取决于你如何存储和显示你的图像。


图片框中的FillEraser鼠标移动事件



private void FillEraser(对象发送者,MouseEventArgs e)

{

if(pctFundusMain.Image!= null)

{

if(e.Button == MouseButtons.Left)

{

PictureBox thisform =(PictureBox)sender;

Graphics g = thisform.CreateGraphics();

var pen = new Pen(Color.White,5);

pen.Width = FixEraserThickness();

//新的SolidBrush(Color.White);

_bitmap = new Bitmap(pctFundusMain.Image);

g = Graphics.FromImage(_bitmap);

var cursorLocation = new Point(eX + 5,eY + 5);

// g.DrawLine (pen,eX,eY,eX + 5,eY + 5);

g.DrawLine(pen,pe,cursorLocation);

pctFundusMain.Image = _bitmap;

pe = cursorLocation;

}

}

}


Can u please help me out how to code for an eraser and for multiple colors(such as in ms-paint)?
How to change the mouse pointer to pen n brush when we click on those corresponding buttons?

Any one please reply me else please at-least give me an idea.

解决方案

Mouse pointer is easy: Cursor = new Cursor(...); (see MSDN for details, there are four different constructors based on how you store your cursor shape).

Coding for multiple colours / eraser is a bit harder, and depends on how you are storing and dispalying your images.


FillEraser in picture box mouse move event

private void FillEraser(object sender, MouseEventArgs e)
{
if (pctFundusMain.Image != null)
{
if (e.Button == MouseButtons.Left)
{
PictureBox thisform = (PictureBox)sender;
Graphics g = thisform.CreateGraphics();
var pen = new Pen(Color.White, 5);
pen.Width = FixEraserThickness();
// new SolidBrush(Color.White);
_bitmap = new Bitmap(pctFundusMain.Image);
g = Graphics.FromImage(_bitmap);
var cursorLocation = new Point(e.X + 5, e.Y + 5);
// g.DrawLine(pen, e.X, e.Y, e.X + 5, e.Y + 5);
g.DrawLine(pen, pe, cursorLocation);
pctFundusMain.Image = _bitmap;
pe = cursorLocation;
}
}
}


这篇关于如何在油漆中编写橡皮擦...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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