473,414 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

A question about delegates of Mouse Events...

Hello,

I have a panel that I have used as a control to be drawn on.
I want to handle say OnMouseHover or OnMouseDown events. To do this I used
Visual C# and it created a delegate called: panel1_OnMouseDown. I have
provided a snipet from the delegate:
private void panel1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs mea)

{

if (mea.Button == MouseButtons.Left)

{

Graphics grfx = CreateGraphics();

Pen pen = new Pen(Color.AliceBlue, 20);

grfx.DrawLine(pen, 100, 100, 3000, 3000);

grfx.Dispose();

}
}

The problem I have (and as you can see from the very large pen and line
size) is that, while the code excutes, there is no visible line drawn. This
makes me think about the CreateGraphics method. Does the returned graphics
object(grfx) alow me to draw on the panel's client area or somewhere else?
If not on the panel, then how do I draw on the panel?

Thank you in advance,

Eric
Nov 16 '05 #1
1 1394
In order to draw on a Panel you have to place the code in the Panel.Paint()
event. then get the Graphics object from the
System.Windows.Forms.PaintEventArgs e Object.

So in you mouseDown code set the points you need and say panel1.Refresh();
then in the panel1_Paint do something like
{
e.Graphics.DrawLine(pen, 100, 100, 3000, 3000);
}

"Beringer" <bo*********@invalid.com> wrote in message
news:t8Rnc.21447$ph.21274@fed1read07...
Hello,

I have a panel that I have used as a control to be drawn on.
I want to handle say OnMouseHover or OnMouseDown events. To do this I used Visual C# and it created a delegate called: panel1_OnMouseDown. I have
provided a snipet from the delegate:
private void panel1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs mea)

{

if (mea.Button == MouseButtons.Left)

{

Graphics grfx = CreateGraphics();

Pen pen = new Pen(Color.AliceBlue, 20);

grfx.DrawLine(pen, 100, 100, 3000, 3000);

grfx.Dispose();

}
}

The problem I have (and as you can see from the very large pen and line
size) is that, while the code excutes, there is no visible line drawn. This makes me think about the CreateGraphics method. Does the returned graphics object(grfx) alow me to draw on the panel's client area or somewhere else?
If not on the panel, then how do I draw on the panel?

Thank you in advance,

Eric

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: news.microsoft.com | last post by:
In one of my books called "Mastering C#" there is a statement that reads "All event handler delegates must return void and accept two parameters. The first parameter is an object, and it represents...
6
by: Flare | last post by:
Hi i have a qusstion about events and delegates. Especially the precis role of the Event. Eg. We have a class wich want to fire events so we declare: public delegate void...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
3
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
2
by: hangaround | last post by:
I used delegates recently, It seemed the delegates was like function_call very much, and we couldn't use delegates to mimic the system events( ex, button_click), so didn't think the delegates...
2
by: kristian.freed | last post by:
Hi, I currently work in a project written fully in C# where we make extensive use of delegates and events. We have a model where a "state", an object holding data but not much code but which...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.