override void OnPaint(PaintEventArgs pe)

X

Xarky

Hi,

I am overriding the method given to draw ellipses on my window,
using the following code. My problem is that I have a button that
every time it is pressed, a variable is inremented, indicating that a
new ellipse is to be drawn. What should I do to refresh the window to
draw the new ellipse.

Thanks in Advance

private void Form1_Load(object sender, System.EventArgs e)
{
tot=1;
}

protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics ;
Pen pn = new Pen( Color.Crimson);
Rectangle rect;

for (int x=0; x<tot; x++)
{
rect= new Rectangle (25,(80*x)+5,40,40);
g.DrawEllipse( pn, rect );
} // end for loop
}

private void button1_Click(object sender, System.EventArgs e)
{
tot++;
}
 
N

Nicholas Paldino [.NET/C# MVP]

Xarky,

You should call the Invalidate method on your control to indicate that
it should be repainted. You can do this after you set the variables when
the button is clicked.

Hope this helps.
 
K

Kai Brinkmann [MSFT]

Simply call the Refresh() method for your form [this.Refresh()] in your
button click event handler. That will force the form to redraw itself.

Hope this helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
X

Xarky

As told, I did the Refresh method and it worked.

Now I need to add all the ellipses to some type of component having
both the veritcal and horizontal scrollbars. I was thinking of a
RichTextBox, but I have no idea how to add ellipses within the
RichTextBox. Can you give me some help how to do it, or some other
suitable component that I should use.

Thanks in Advance




Kai Brinkmann said:
Simply call the Refresh() method for your form [this.Refresh()] in your
button click event handler. That will force the form to redraw itself.

Hope this helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

Xarky said:
Hi,

I am overriding the method given to draw ellipses on my window,
using the following code. My problem is that I have a button that
every time it is pressed, a variable is inremented, indicating that a
new ellipse is to be drawn. What should I do to refresh the window to
draw the new ellipse.

Thanks in Advance

private void Form1_Load(object sender, System.EventArgs e)
{
tot=1;
}

protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics ;
Pen pn = new Pen( Color.Crimson);
Rectangle rect;

for (int x=0; x<tot; x++)
{
rect= new Rectangle (25,(80*x)+5,40,40);
g.DrawEllipse( pn, rect );
} // end for loop
}

private void button1_Click(object sender, System.EventArgs e)
{
tot++;
}
 

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