你怎么在面板上做写意画 [英] how do you do freehand drawing on a panel

查看:74
本文介绍了你怎么在面板上做写意画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我非常喜欢C#新手。


如何在面板上进行徒手绘图一个鼠标在c#?

谢谢,

Don

Hi there,

I''m very much a C# novice.

How do you do freehand drawing on a panel with a mouse in c#?
Thanks,
Don

推荐答案

嗯,这取决于你需要什么,但有一些关键的想法。首先

你需要知道做什么有人在你的面板上拖东西所以

你需要缓冲你绘制的东西所以你可以重绘它

变得可见。


这是关于双缓冲的教程。

http://www.codeproject.com/csharp/DoubleBuffering.asp


你需要知道如何设置一个像素或像素范围,

这里有一些信息:

http://forums.microsoft.com/MSDN/Sho .. .38408& SiteID = 1


但它可以概括为


// _ ourbitmap是对我们缓冲区的引用(System.Drawing.Bitmap)

_ourbitmap.SetPixel(eX,eY,System.Drawing.Color.A zure);

//使用我们学到的东西绘制双缓冲。


这里有一些实际可行的东西。创建一个表单,添加一个面板和一个

按钮。


将其添加到表单的声明中。我正在使用现有的位图来简单地设置位图

private System.Drawing.Bitmap _b = new Bitmap(&C:\\ Somebitmap.bmp");

在按钮中单击事件添加


//确保位图适合面板并分配。

_b = new System.Drawing.Bitmap(_b,panel1.Size);

panel1.BackgroundImage = _b;


在面板的MouseMove事件中添加以下。


//如果按下按钮,绘制一个像素并使其无效以便重新绘制

重新绘制。

if( System.Windows.Forms.MouseButtons.Left == e.Button)

{

_b.SetPixel(eX,eY,System.Drawing.Color.Wheat);

panel1.Invalidate(new System.Drawing.Rectangle(eX,eY,1,1));

}

它不是完美,但它可能会让你开始正确的方向。


1月24日16:14,dongarb ... @ hotmail.com写道:
Well, it depends on what you need, but there are some key ideas. First
you need to know what to do someone drags something over your panel so
you need to buffer what ever you''ve drawn so you can redraw it when it
becomes visible.

Here''s a tutorial on double buffering.

http://www.codeproject.com/csharp/DoubleBuffering.asp

You''ll need to know how to set a single pixel or range of pixels,
there''s a little info on this:

http://forums.microsoft.com/MSDN/Sho...38408&SiteID=1

but it can be summed up as

//_ourbitmap is a reference to our buffer (System.Drawing.Bitmap)
_ourbitmap.SetPixel(e.X,e.Y,System.Drawing.Color.A zure);
//Draw using the stuff we learnt in double buffering.

Here''s something that actually works. Create a form, add a panel and a
button.

Add this to the form''s declarations. I''m using an existing bitmap for
simplicity to set up the bitmap
private System.Drawing.Bitmap _b = new Bitmap("C:\\Somebitmap.bmp");
In the buttons click event add

//ensure bitmap fits panel and assign.
_b = new System.Drawing.Bitmap(_b,panel1.Size);
panel1.BackgroundImage = _b;

In the MouseMove event of the panel add the following.

//if left button down, draw a pixel and invalidate it so it gets
redrawn.
if(System.Windows.Forms.MouseButtons.Left == e.Button)
{
_b.SetPixel(e.X,e.Y,System.Drawing.Color.Wheat);
panel1.Invalidate(new System.Drawing.Rectangle(e.X,e.Y,1,1));
}
It isn''t perfect but it might get you started in the right direction.

On 24 Jan, 16:14, dongarb...@hotmail.com wrote:

你好,


我非常喜欢C#新手。


如何使用c#中的鼠标在面板上进行徒手绘图?

谢谢,

Don
Hi there,

I''m very much a C# novice.

How do you do freehand drawing on a panel with a mouse in c#?

Thanks,
Don





< do ********@hotmail.com写信息

新闻:11 ********************** @ a75g2000cwd。 googlegr oups.com ...


<do********@hotmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...

你好,


我非常喜欢C#新手。 />

如何使用c#中的鼠标在面板上进行徒手绘图?


谢谢,

Don
Hi there,

I''m very much a C# novice.

How do you do freehand drawing on a panel with a mouse in c#?
Thanks,
Don



最好的方法,IMO,是创建一个继承自Panel的新类,并且

覆盖此类中的OnPaint,OnMousexxx等方法....但只是

我的意见:)


HTH,

Mythran

The best way, IMO, is to create a new class that inherits from Panel and
override the OnPaint, OnMousexxx, etc methods inside this class....but just
my opinion :)

HTH,
Mythran


Mythran,


这听起来最简单。当你在OnMouseDown()方法中使用

时如何在面板上绘图?


谢谢,

Don


1月24日下午1:15,Mythran < kip_pot ... @ hotmail.comwrote:
Mythran,

This sounds the simplest. How do you draw on the panel when you''re in
the OnMouseDown() method?

Thanks,
Don

On Jan 24, 1:15 pm, "Mythran" <kip_pot...@hotmail.comwrote:

< dongarb ... @ hotmail.comwrote in messagenews:11 ********* *************@a75g2000cwd.g ooglegroups.com ...
<dongarb...@hotmail.comwrote in messagenews:11**********************@a75g2000cwd.g ooglegroups.com...

你好,
Hi there,


我非常喜欢C#新手。
I''m very much a C# novice.


如何使用c#中的鼠标在面板上进行徒手绘图?
How do you do freehand drawing on a panel with a mouse in c#?


谢谢,

Don最好的方法,IMO,是创建一个继承自Panel和$ b $的新类b
Thanks,
DonThe best way, IMO, is to create a new class that inherits from Panel and



覆盖此类中的OnPaint,OnMousexxx等方法....但只是

我的意见:)


HTH,

Mythran

override the OnPaint, OnMousexxx, etc methods inside this class....but just
my opinion :)

HTH,
Mythran


这篇关于你怎么在面板上做写意画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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