about drawing

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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.
 
Back
Top