PC Review


Reply
Thread Tools Rate Thread

clear fillEllipse graphics

 
 
Slickuser
Guest
Posts: n/a
 
      30th Nov 2007
I have this function that will fill the ellipse every 10 seconds with
specific x,y,w,h.

Now I want do the the reverse, to clear the ellipse with given x,y
using Timer at every 30s.
Or I have put these (x,y,w,h) to an array?
Later go back the array and fill ellipse with the same color as
background?

Is there an easy way?

Thanks..

//Sample code that draw with timer

private void drawNote(int x, int y, int width, int height,
SolidBrush brush)
{
Graphics graphicGlobal = this.CreateGraphics();
this.Show();

graphicGlobal.FillEllipse(brush, x, y, width, height);

}

// Timer to draw
private void timer_note_Tick(object sender, EventArgs e)
{
SolidBrush colorBrush = new SolidBrush(Color.Cyan);
SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);

drawNote(x_global, y_global, width_global, height_global,
colorBrush);

drawNote(x_global + 15, y_global + 15, width_global,
height_global, colorBrush2);

x_global = x_global + 30;
y_global = y_global + 30;
}
 
Reply With Quote
 
 
 
 
Hilton
Guest
Posts: n/a
 
      30th Nov 2007
I think you need to dispose of graphicGlobal.

"Slickuser" <(E-Mail Removed)> wrote in message
news:51d8e836-57f5-473c-829d-(E-Mail Removed)...
>I have this function that will fill the ellipse every 10 seconds with
> specific x,y,w,h.
>
> Now I want do the the reverse, to clear the ellipse with given x,y
> using Timer at every 30s.
> Or I have put these (x,y,w,h) to an array?
> Later go back the array and fill ellipse with the same color as
> background?
>
> Is there an easy way?
>
> Thanks..
>
> //Sample code that draw with timer
>
> private void drawNote(int x, int y, int width, int height,
> SolidBrush brush)
> {
> Graphics graphicGlobal = this.CreateGraphics();
> this.Show();
>
> graphicGlobal.FillEllipse(brush, x, y, width, height);
>
> }
>
> // Timer to draw
> private void timer_note_Tick(object sender, EventArgs e)
> {
> SolidBrush colorBrush = new SolidBrush(Color.Cyan);
> SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);
>
> drawNote(x_global, y_global, width_global, height_global,
> colorBrush);
>
> drawNote(x_global + 15, y_global + 15, width_global,
> height_global, colorBrush2);
>
> x_global = x_global + 30;
> y_global = y_global + 30;
> }



 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      30th Nov 2007


"Slickuser" wrote:

> I have this function that will fill the ellipse every 10 seconds with
> specific x,y,w,h.
>
> Now I want do the the reverse, to clear the ellipse with given x,y
> using Timer at every 30s.
> Or I have put these (x,y,w,h) to an array?
> Later go back the array and fill ellipse with the same color as
> background?
>
> Is there an easy way?
>
> Thanks..
>
> //Sample code that draw with timer
>
> private void drawNote(int x, int y, int width, int height,
> SolidBrush brush)
> {
> Graphics graphicGlobal = this.CreateGraphics();
> this.Show();
>
> graphicGlobal.FillEllipse(brush, x, y, width, height);
>
> }
>
> // Timer to draw
> private void timer_note_Tick(object sender, EventArgs e)
> {
> SolidBrush colorBrush = new SolidBrush(Color.Cyan);
> SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);
>
> drawNote(x_global, y_global, width_global, height_global,
> colorBrush);
>
> drawNote(x_global + 15, y_global + 15, width_global,
> height_global, colorBrush2);
>
> x_global = x_global + 30;
> y_global = y_global + 30;
> }
>


Reread the advise to you in your post yesterday. It looks like you are
going back to drawing graphics outside the paint event.

 
Reply With Quote
 
Slickuser
Guest
Posts: n/a
 
      30th Nov 2007
If I use that way, I need some how to pass in a PaintEvents to draw.
That how why I choose doing this way.

On Nov 30, 4:53 am, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.com> wrote:
> "Slickuser" wrote:
> > I have this function that will fill the ellipse every 10 seconds with
> > specific x,y,w,h.

>
> > Now I want do the the reverse, to clear the ellipse with given x,y
> > using Timer at every 30s.
> > Or I have put these (x,y,w,h) to an array?
> > Later go back the array and fill ellipse with the same color as
> > background?

>
> > Is there an easy way?

>
> > Thanks..

>
> > //Sample code that draw with timer

>
> > private void drawNote(int x, int y, int width, int height,
> > SolidBrush brush)
> > {
> > Graphics graphicGlobal = this.CreateGraphics();
> > this.Show();

>
> > graphicGlobal.FillEllipse(brush, x, y, width, height);

>
> > }

>
> > // Timer to draw
> > private void timer_note_Tick(object sender, EventArgs e)
> > {
> > SolidBrush colorBrush = new SolidBrush(Color.Cyan);
> > SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);

>
> > drawNote(x_global, y_global, width_global, height_global,
> > colorBrush);

>
> > drawNote(x_global + 15, y_global + 15, width_global,
> > height_global, colorBrush2);

>
> > x_global = x_global + 30;
> > y_global = y_global + 30;
> > }

>
> Reread the advise to you in your post yesterday. It looks like you are
> going back to drawing graphics outside the paint event.- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      30th Nov 2007
On 2007-11-30 12:03:35 -0800, Slickuser <(E-Mail Removed)> said:

> If I use that way, I need some how to pass in a PaintEvents to draw.


No, you don't. Windows generates the PaintEventArgs. You don't call
OnPaint() yourself, and you don't raise the Paint event yourself. You
use Control.Invalidate() to tell Windows what area of the control needs
to be redrawn, and Windows handles the rest.

> That how why I choose doing this way.


You are doing it wrong. You will continue to have problems as long as
you continue to do it wrong.

You can find a discussion on proper techniques for custom drawing in .NET here:
http://msdn2.microsoft.com/en-us/library/kxys6ytf.aspx

While it focuses on an actual custom control, the concepts are the same
whether you are overriding OnPaint() or just handling the Paint event
of a Control instance.

You may also want to learn more about the underlying Windows drawing
model, which is documented here
http://msdn2.microsoft.com/en-us/library/ms534857.aspx

Note that this model is not unique to Windows. It's a common paradigm,
and so if you learn how to do it in Windows, you will be familiar with
drawing in many different GUI platforms. More importantly, because its
close relationship with the basic .NET drawing model, learning about
the unmanaged Windows paradigm will actually help you understand the
..NET model better as well.

Finally, you may want to consider learning about the Windows
Presentation Foundation (WPF). While I don't know much about it
myself, my understanding is that it's a more declarative paradigm, as
opposed to the event-driven paradigm you're trying to use in a sort of
declarative way.
http://msdn2.microsoft.com/en-us/library/ms754130.aspx

Pete

 
Reply With Quote
 
Slickuser
Guest
Posts: n/a
 
      1st Dec 2007
I am looking through examples right now.

Can you give me example that let call(or not) a function which draw at
x,y,w,h with PaintEventArgs?

I still want to call this function with this argument when I want it
to draw: drawNote(int x, int y, int width, int height, SolidBrush
brush)

private void drawNote(int x, int y, int width, int
height,SolidBrush brush)
{
////PaintEventArg???
//Graphics graphicGlobal = this.CreateGraphics();
/// this.Show();

graphicGlobal.FillEllipse(brush, x, y, width, height);

}


On Nov 30, 1:15 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
> On 2007-11-30 12:03:35 -0800, Slickuser <slick.us...@gmail.com> said:
>
> > If I use that way, I need some how to pass in a PaintEvents to draw.

>
> No, you don't. Windows generates the PaintEventArgs. You don't call
> OnPaint() yourself, and you don't raise the Paint event yourself. You
> use Control.Invalidate() to tell Windows what area of the control needs
> to be redrawn, and Windows handles the rest.
>
> > That how why I choose doing this way.

>
> You are doing it wrong. You will continue to have problems as long as
> you continue to do it wrong.
>
> You can find a discussion on proper techniques for custom drawing in .NET here:http://msdn2.microsoft.com/en-us/library/kxys6ytf.aspx
>
> While it focuses on an actual custom control, the concepts are the same
> whether you are overriding OnPaint() or just handling the Paint event
> of a Control instance.
>
> You may also want to learn more about the underlying Windows drawing
> model, which is documented herehttp://msdn2.microsoft.com/en-us/library/ms534857.aspx
>
> Note that this model is not unique to Windows. It's a common paradigm,
> and so if you learn how to do it in Windows, you will be familiar with
> drawing in many different GUI platforms. More importantly, because its
> close relationship with the basic .NET drawing model, learning about
> the unmanaged Windows paradigm will actually help you understand the
> .NET model better as well.
>
> Finally, you may want to consider learning about the Windows
> Presentation Foundation (WPF). While I don't know much about it
> myself, my understanding is that it's a more declarative paradigm, as
> opposed to the event-driven paradigm you're trying to use in a sort of
> declarative way.http://msdn2.microsoft.com/en-us/library/ms754130.aspx
>
> Pete


 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      1st Dec 2007
On Fri, 30 Nov 2007 17:14:42 -0800, Slickuser <(E-Mail Removed)>
wrote:

> I am looking through examples right now.


Eventually, you should find a discussion of the Paint event and what
PaintEventArgs contains.

> Can you give me example that let call(or not) a function which draw at
> x,y,w,h with PaintEventArgs?


In that discussion, you will find that the PaintEventArgs.Graphics member
provides the Graphics instance to which you need to draw.

> I still want to call this function with this argument when I want it
> to draw: drawNote(int x, int y, int width, int height, SolidBrush
> brush)


Since the PaintEventArgs.Graphics member is the Graphics instance to which
you need to draw, that means that you need to pass the Graphics instance
from PaintEventArgs to any code that wants to draw. The simplest way to
do that would be to include it as a parameter to the method called from
the OnPaint() method or the Paint event handler (however you've decided to
implement it).

So:

> private void drawNote(int x, int y, int width, int
> height,SolidBrush brush)


becomes:

> private void drawNote(Graphics gfx, int x, int y, int width, int
> height,SolidBrush brush)


and the method body:

> {
> ////PaintEventArg???
> //Graphics graphicGlobal = this.CreateGraphics();
> /// this.Show();
>
> graphicGlobal.FillEllipse(brush, x, y, width, height);
>
> }


becomes:

> {
> gfx.FillEllipse(brush, x, y, width, height);
> }


Hope that helps.

Pete
 
Reply With Quote
 
Slickuser
Guest
Posts: n/a
 
      1st Dec 2007
Which in that case, now I need to pass in Graphics as input argument
to call drawNote (5 input arguments)?

How can I achieve with my timer? Thank you so much for your help.

// Timer to draw
private void timer_note_Tick(object sender, EventArgs e)
{
SolidBrush colorBrush = new SolidBrush(Color.Cyan);
SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);

//drawNote(x_global, y_global, width_global,
height_global,colorBrush);

//drawNote(x_global + 15, y_global + 15,
width_global,height_global, colorBrush2);

x_global = x_global + 30;
y_global = y_global + 30;
}


On Nov 30, 5:23 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Fri, 30 Nov 2007 17:14:42 -0800, Slickuser <slick.us...@gmail.com>
> wrote:
>
> > I am looking through examples right now.

>
> Eventually, you should find a discussion of the Paint event and what
> PaintEventArgs contains.
>
> > Can you give me example that let call(or not) a function which draw at
> > x,y,w,h with PaintEventArgs?

>
> In that discussion, you will find that the PaintEventArgs.Graphics member
> provides the Graphics instance to which you need to draw.
>
> > I still want to call this function with this argument when I want it
> > to draw: drawNote(int x, int y, int width, int height, SolidBrush
> > brush)

>
> Since the PaintEventArgs.Graphics member is the Graphics instance to which
> you need to draw, that means that you need to pass the Graphics instance
> from PaintEventArgs to any code that wants to draw. The simplest way to
> do that would be to include it as a parameter to the method called from
> the OnPaint() method or the Paint event handler (however you've decided to
> implement it).
>
> So:
>
> > private void drawNote(int x, int y, int width, int
> > height,SolidBrush brush)

>
> becomes:
>
> > private void drawNote(Graphics gfx, int x, int y, int width, int
> > height,SolidBrush brush)

>
> and the method body:
>
> > {
> > ////PaintEventArg???
> > //Graphics graphicGlobal = this.CreateGraphics();
> > /// this.Show();

>
> > graphicGlobal.FillEllipse(brush, x, y, width, height);

>
> > }

>
> becomes:
>
> > {
> > gfx.FillEllipse(brush, x, y, width, height);
> > }

>
> Hope that helps.
>
> Pete


 
Reply With Quote
 
Slickuser
Guest
Posts: n/a
 
      1st Dec 2007
I should use ??

protected override void OnPaint(PaintEventArgs e)
{
// If there is an image and it has a location,
// paint it when the Form is repainted.
base.OnPaint(e);
//base.Invalidate();

}

On Nov 30, 5:48 pm, Slickuser <slick.us...@gmail.com> wrote:
> Which in that case, now I need to pass in Graphics as input argument
> to call drawNote (5 input arguments)?
>
> How can I achieve with my timer? Thank you so much for your help.
>
> // Timer to draw
> private void timer_note_Tick(object sender, EventArgs e)
> {
> SolidBrush colorBrush = new SolidBrush(Color.Cyan);
> SolidBrush colorBrush2 = new SolidBrush(Color.Magenta);
>
> //drawNote(x_global, y_global, width_global,
> height_global,colorBrush);
>
> //drawNote(x_global + 15, y_global + 15,
> width_global,height_global, colorBrush2);
>
> x_global = x_global + 30;
> y_global = y_global + 30;
> }
>
> On Nov 30, 5:23 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
> wrote:
>
> > On Fri, 30 Nov 2007 17:14:42 -0800, Slickuser <slick.us...@gmail.com>
> > wrote:

>
> > > I am looking through examples right now.

>
> > Eventually, you should find a discussion of the Paint event and what
> > PaintEventArgs contains.

>
> > > Can you give me example that let call(or not) a function which draw at
> > > x,y,w,h with PaintEventArgs?

>
> > In that discussion, you will find that the PaintEventArgs.Graphics member
> > provides the Graphics instance to which you need to draw.

>
> > > I still want to call this function with this argument when I want it
> > > to draw: drawNote(int x, int y, int width, int height, SolidBrush
> > > brush)

>
> > Since the PaintEventArgs.Graphics member is the Graphics instance to which
> > you need to draw, that means that you need to pass the Graphics instance
> > from PaintEventArgs to any code that wants to draw. The simplest way to
> > do that would be to include it as a parameter to the method called from
> > the OnPaint() method or the Paint event handler (however you've decided to
> > implement it).

>
> > So:

>
> > > private void drawNote(int x, int y, int width, int
> > > height,SolidBrush brush)

>
> > becomes:

>
> > > private void drawNote(Graphics gfx, int x, int y, int width, int
> > > height,SolidBrush brush)

>
> > and the method body:

>
> > > {
> > > ////PaintEventArg???
> > > //Graphics graphicGlobal = this.CreateGraphics();
> > > /// this.Show();

>
> > > graphicGlobal.FillEllipse(brush, x, y, width, height);

>
> > > }

>
> > becomes:

>
> > > {
> > > gfx.FillEllipse(brush, x, y, width, height);
> > > }

>
> > Hope that helps.

>
> > Pete


 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      1st Dec 2007
On Fri, 30 Nov 2007 17:48:37 -0800, Slickuser <(E-Mail Removed)>
wrote:

> Which in that case, now I need to pass in Graphics as input argument
> to call drawNote (5 input arguments)?


Yes. If it bothers you and your drawing code is complex enough, you may
find it makes sense to create a class instantiated for each time you draw
and to which you pass the Graphics instance as well as any other
frequently-used data items you might want access to from the drawing code.

> How can I achieve with my timer? Thank you so much for your help.


You don't draw in response to a timer. You can update your data, and then
invalidate the area of the control/form that needs to be redrawn
(depending on the data and what you're drawing, this might just be the
whole control or form).

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnPaint automatically call e.Graphics.Clear()? gilbert@gmail Microsoft Dot NET Framework Forms 4 24th Apr 2007 11:03 AM
Graphics.Clear() in Terminal Services Pete Microsoft Dot NET Framework 0 10th Apr 2007 05:59 PM
Clear Graphics =?Utf-8?B?R3VzIENodWNo?= Microsoft VB .NET 4 7th Mar 2007 01:03 AM
Start menu graphics not clear sher Windows XP General 0 13th Dec 2003 07:26 PM
Graphics displays not clear Dave Windows XP Video 0 17th Sep 2003 04:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:32 PM.