473,785 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clear fillEllipse graphics

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.CreateGrap hics();
this.Show();

graphicGlobal.F illEllipse(brus h, x, y, width, height);

}

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

drawNote(x_glob al, y_global, width_global, height_global,
colorBrush);

drawNote(x_glob al + 15, y_global + 15, width_global,
height_global, colorBrush2);

x_global = x_global + 30;
y_global = y_global + 30;
}
Nov 30 '07
11 6735
Peter:

I have been following this thread, as I have similar problems/issues (as you
may recall).

Since your last round of advice, I have played a lot, and even bought a C#
book, but its still not working. After many hours without luck, I would
really appreciate some more help

In my case, the OnPaint command would be extremely easy to implement as I am
drawing entirely to a graphics buffer (so I have a complete copy of the
image) and all I need to do is execute a MyBuffer.Render () to physically
redraw.

Here is my problem.

I have put this code into my app:

protected override void OnPaint(object sender, PaintEventArgs
pea)
{
MyBuffer.Render ();
}

This actually works, but only sort-of. This OnPaint is triggered by a redraw
of Form1. I start my app, it comes up with a blank PictureBox1. As soon as I
move the mouse off the PictureBox (eg to the button area) it triggers the
above and my image appears. But only (very annoyingly) when the user moves
the mouse to the button area. This is very inconvenient because I can't play
my animation on start up (and it looks tacky).

Clearly, I have wired the OnPaint to the Form, and not to PictureBox1.

My book says that I need to insert the OnPaint override in the control
setup. I can do this for Form1, because the system generates a block of code
to initialise Form1. I can find no equivalent for PictureBox1.

If I click on my PictureBox1 in the designer, it has a Paint method
(member?) listed, but this is Paint but not OnPaint. I can't see where my
On_Paint method has to be inserted in my code to trigger off PictureBox1
instead of Form1.

Somebody suggested that I create a custom control which inherits from
PictureBox but overrides OnPaint. I tried this, but got into a fair amount
of mess. I have abandoned this as it seemed a very complicated solution to a
pretty simple problem, and I got even further out of my depth.

So, is there a simple way of wiring my OnPaint method (which works fine) to
be triggered off a repaint of PictureBox1 instead of Form1? If so, how do I
do it?

Thanks,

Peter Webb

Dec 2 '07 #11
On Sat, 01 Dec 2007 17:59:11 -0800, Peter Webb
<we********@DIE SPAMDIEoptusnet .com.auwrote:
[...]
So, is there a simple way of wiring my OnPaint method (which works fine)
to be triggered off a repaint of PictureBox1 instead of Form1? If so,
how do I do it?
It seems to me that you actually have two different issues. One is, where
to do the drawing? That is, where does your drawing code go? The other
is, how do you cause the drawing to occur?

With respect to the first question...

The PictureBox class is not for people who want to do their own drawing.
It's a convenient control to which you can attach an existing Image, and
let the control itself deal with a variety of display issues. Such as,
when to draw, if and how to scale the image, that sort of thing.

You _could_ certainly derive a new class from PictureBox and override the
OnPaint() method, but that would be sort of pointless. You can easily do
the same thing deriving from the Control class, without having all the
extra PictureBox functionality dragged along.

You could also handle the PictureBox's Paint event, but again it would be
pointless, for the same reasons.

The reason for deriving from PictureBox would be if you want to use and
extend or override functionality that is specific to the PictureBox
class. So far I haven't seen anything that would suggest that's what
you're doing or what you want.

So where should you do the drawing? IMHO, it depends on what your UI is
like, which I don't know. If you intend to manage all of the drawing
inside the form, then drawing in the form class would be a reasonable
place. If, however, you want to be able to use the VS Designer to
implement and maintain the user interface, and you want to be able to
manipulate where you custom drawing happens as part of that maintenance,
then you will probably want to create a custom Control-derived class.
That way, you'll get a custom control added to your Designer toolbox that
you can drag and drop, placing it wherever you like.

Creating a custom control is very simple, practically the same as creating
a new form class. Just add a new item to the project (using the
Project/Add New Item... menu or the Solution Explorer), and select "Custom
Control" from the template list. This will create a new class derived
from Control. In that class, you can override OnPaint() where you want to
draw.

Of course, you will want to move any other code related to managing the
graphics into that control class, or somewhere related to it. That's a
broader design question, and frankly it's much harder to answer those
questions in a newsgroup like this. Providing good advice on design
generally requires a lot of background knowledge of the problem being
solved, and not only is that background knowledge difficult to express in
this context, so too is explaining how a good design would work.

Suffice to say, a good design makes it easy to put all your pieces
together. Conversely, if you're having trouble putting the pieces
together, you should rethink the design.

Now, finally...there 's the question of how to cause the drawing to occur.
The basic mechanism is invalidation of the control. In this context
"invalidati on" means something very specific: to communicate to Windows
that an area of the control no longer has valid graphics and needs to be
redrawn. You use the Control.Invalid ate() method to do this.

I've already explained that in this thread, and I believe that the various
links that have been posted, by myself and others, also explain it
reasonably well. The basic idea is this though: you don't draw in direct
reaction to changes in the data; you design your drawing code so that it
can always draw whatever the current state of the data is, and you
invalidate the control in reaction to changes to data.

Since you're using the BufferedGraphic s class, it seems to me that this
should be especially simple. When you change the BufferedGraphic s by
drawing to it, you need to call Invalidate() on whatever control it is
that you are drawing to (the Form class inherits Control as well). If you
know specifically what area of the BufferedGraphic s has changed, you can
use that information to restrict the invalidated area, passing a rectangle
to the Invalidate() method so that only the part that changed winds up
getting redrawn.

Pete
Dec 2 '07 #12

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

Similar topics

3
3127
by: David Trimboli | last post by:
At http://www.trimboli.name/ I've created a list of the contents of the site, using graphics as the list bullets by including style attributes in the HTML. What I want to do is make the graphic top and the link top line up with each other, then make the description sit immediately underneath the link, with no space between them. The text of the description should remain to the right of the graphic; it should not wrap under the graphic if...
5
2316
by: William Schubert | last post by:
Is there a common defintion of Clear that applies to both objects and collections? If so, where is it documented. My preconceived notion is that Clear means "reset the object to its initial state" and this applies to both collections and objects. The problem is that I cannot find anything in the literature supporting this. That would be ok, but I cannot find anything at all.
2
20967
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
2
1632
by: Daniel | last post by:
how come when i do oGraphics.FillEllipse it draws blury? is there anyway to adjust this default compression to not be blury when drawing a simple ellipse?
7
2055
by: moondaddy | last post by:
I'm painting images onto a windows form using this method: e.Graphics.DrawImageUnscaled(m_ItemImage, x, y) every time I select a product. However, some products don't have an image so when a user selects a different product from a list and that product doesn't have an image, I need to clear the image from the previous product that was painted onto the form. I was thinking of creating a clear image and using the DrawImageUnscaled
3
2127
by: JD | last post by:
Is it possible to have a clear backstyle for a lable control? I want to write some text on a lable and I want the background of the label to match the color of the control I am placing the label on where the color of that control will be changing will be changing. Is this doable? If not, is there a control I can do this with? to have a clear/see through backstyle? Thanks, JD
4
7574
by: =?Utf-8?B?R3VzIENodWNo?= | last post by:
I got a simple line of code that paints on a panel. I would like to add a clear button to clear the panel but I’m not to sure how. Panel.MouseMove Dim g As Graphics = Me.Panel1.CreateGraphics() g.FillEllipse(New SolidBrush(Value), e.X, e.Y, SizePt, SizePt) g.Dispose() cmdClear_Click Me.Panel.?????
5
3472
by: Kid Programmer | last post by:
Hello guys. I was wondering how you can clear the screen in a java program. Here is the code for my program: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; public class GUI {
10
2082
kspiros
by: kspiros | last post by:
I have a picture box which contains an image and some drawn ellipses. while a thread pass by the ellipses increase the alpha of the ellipse but when the tread leaves the ellipse range i can't change the alpha value because it paints it over. how can I erase only the ellipse without touching anything else in the image. image linksimage1 image2 my code public void work() { Graphics xGraph;
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.