about drawing

T

Tony Johansson

Is it just a matter of taste which one of methods 1 and 2 I use when I want
to draw something.
I mean doeas any of them give any advantage compared to the other.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

1 private void Form1_Paint(object sender, PaintEventArgs e)
{

}

2 protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}

//Tony
 
W

Willem van Rumpt

Is it just a matter of taste which one of methods 1 and 2 I use when I want
to draw something.
I mean doeas any of them give any advantage compared to the other.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

1 private void Form1_Paint(object sender, PaintEventArgs e)
{

}

2 protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}

First, it would be nice if you post complete code. I *think* I can
assume that Form1_Paint is an event handler, added somewhere in
InitializeComponent(), but without code to prove it, it could be just a
method.

Now for the answer: The end result may very well be the same, depending
on how you implement things, but the road towards it is *very* different.

In (1) you're handling an event, in (2) you're overriding a method of
the base class.

Which one is to be preferred is depends completely on whatever else
you're trying to achieve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top