473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Graphics rendering to a Panel is immediately cleared ???

I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.

Here are the important code fragments ...

public class MyPanel : Panel
{
.............................

public MyPanel () : base ()
{
this.SetStyle (ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle (ControlStyles.UserPaint, true);
}

protected override void OnPaintBackground (PaintEventArgs pe)
{
return;
}

protected override void OnPaint (PaintEventArgs pe)
{
using (Graphics g = this.CreateGraphics ())

.............
..........................................

The "OnPaint ()" routine uses the graphics context to draw some graphs etc.

Now, I have added the override to "OnPaintBackground ()" in order to see the
order of events which take place. In reality I do NOT override this method as
the standard Panel implementation does all I need it to do.

What happens is OnPaintBackground is entered and when exited On Paint is
entered.. So far so good.

When I simply let the app fly, every second I call Refresh () on the single
instance of the MyPanel object, this in turn ultimately invokes my On Paint
method which redraws my graphs. HOWEVER, the graph appears very quickly, then
is cleared again and the standard Form grey background replaces the graph
drawn in the panel.

Why is my Panel data displayed correctly but then instantly cleared. I send
the Refresh call directly to the MyPanel instance and not to the parent form.

I have moved the code logic from a combination that ALMOST worked perfectly,
ie the double buffering worked but wanted to remove the initial erase flicker.
In this previous working scneario, I had a Panel (not a derived Panel, ie
MyPanel), which sat directly on a CustomControl. Then the Refresh () produced
the graph data that persisted on the display until the second timer fired and
the data (plus flicker) was then redisplayed. WHY BY USING MY DERIVED PANEL
ON A FORM DOES MY CODE BEHAVE SO DIFFERENTLY TO THAT OF DISPLAYING A NATICE
PANEL ON A CUSTOMCONTROL.

So, once again, my graph appears for an instant, then is overwritten by the
standard Form Grey background colour. I do NOT have an active
OnPaintBackground and do NOT handle the associated event.

Many thanks for your time.
May 12 '06 #1
6 6431
Since you don't handle the OnPaintBackground, perhaps the base class
event is firing and that is what is erasing your background? Perhaps
you should handle the OnPaintBackground and then NOT call the base
class handler.

Also, you might check the Control.SetStyle command and use the
AllPaintingInWmPaint enum. I think that prevents the background from
being erased.

One last thought, does you OnPaint call the base class OnPaint? Where
does this happen?

May 12 '06 #2
Whoops! I re-read your post and that you are calling SetStyle so
ignore that part of my reply.

May 12 '06 #3
The OnPaint method passes the Graphics instnace to your app via the
PaintEventArgs. You're not using it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Paul_Madden" <u21795@uwe> wrote in message news:602397c79829c@uwe...
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.

Here are the important code fragments ...

public class MyPanel : Panel
{
.............................

public MyPanel () : base ()
{
this.SetStyle (ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle (ControlStyles.UserPaint, true);
}

protected override void OnPaintBackground (PaintEventArgs pe)
{
return;
}

protected override void OnPaint (PaintEventArgs pe)
{
using (Graphics g = this.CreateGraphics ())
.............
.........................................

The "OnPaint ()" routine uses the graphics context to draw some graphs
etc.

Now, I have added the override to "OnPaintBackground ()" in order to see
the
order of events which take place. In reality I do NOT override this method
as
the standard Panel implementation does all I need it to do.

What happens is OnPaintBackground is entered and when exited On Paint is
entered.. So far so good.

When I simply let the app fly, every second I call Refresh () on the
single
instance of the MyPanel object, this in turn ultimately invokes my On
Paint
method which redraws my graphs. HOWEVER, the graph appears very quickly,
then
is cleared again and the standard Form grey background replaces the graph
drawn in the panel.

Why is my Panel data displayed correctly but then instantly cleared. I
send
the Refresh call directly to the MyPanel instance and not to the parent
form.

I have moved the code logic from a combination that ALMOST worked
perfectly,
ie the double buffering worked but wanted to remove the initial erase
flicker.
In this previous working scneario, I had a Panel (not a derived Panel, ie
MyPanel), which sat directly on a CustomControl. Then the Refresh ()
produced
the graph data that persisted on the display until the second timer fired
and
the data (plus flicker) was then redisplayed. WHY BY USING MY DERIVED
PANEL
ON A FORM DOES MY CODE BEHAVE SO DIFFERENTLY TO THAT OF DISPLAYING A
NATICE
PANEL ON A CUSTOMCONTROL.

So, once again, my graph appears for an instant, then is overwritten by
the
standard Form Grey background colour. I do NOT have an active
OnPaintBackground and do NOT handle the associated event.

Many thanks for your time.

May 12 '06 #4
Hoi Kevin. You are indeed correct. I am in the UK now and will return to my
office in Zeurich late Monday . I will try using the graphics context passed
via "pe". I was assuming te "this.CreateGraphics" would point to one and the
same.

This is the first time I have used this forum and am absolutely astonished at
just how many threads are started each day. Shame the rest of the world can't
colaborate so eagerly in all matters political.

I'll let you know how things pan out when I give it a go.

Many thanks Kevin.

Paul.

Kevin Spencer wrote:
The OnPaint method passes the Graphics instnace to your app via the
PaintEventArgs. You're not using it.
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.

[quoted text clipped - 71 lines]

Many thanks for your time.


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200605/1
May 12 '06 #5
What I have noticed is that when I do not override, the base class
OnPaintBackground fires, followed by my OnPaint routine. Things are fine up
to here. However, after the OnPaint call, the background is again cleared.
The call stack which results from my original call to myPanel.Refresh () is
pretty deep and I believe something is happening as I travers back up the
stack, after my OnPaint () routine has been called.

Paul_Madden wrote:
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.

Here are the important code fragments ...

public class MyPanel : Panel
{
.............................

public MyPanel () : base ()
{
this.SetStyle (ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle (ControlStyles.UserPaint, true);
}

protected override void OnPaintBackground (PaintEventArgs pe)
{
return;
}

protected override void OnPaint (PaintEventArgs pe)
{
using (Graphics g = this.CreateGraphics ())

.............
.........................................

The "OnPaint ()" routine uses the graphics context to draw some graphs etc.

Now, I have added the override to "OnPaintBackground ()" in order to see the
order of events which take place. In reality I do NOT override this method as
the standard Panel implementation does all I need it to do.

What happens is OnPaintBackground is entered and when exited On Paint is
entered.. So far so good.

When I simply let the app fly, every second I call Refresh () on the single
instance of the MyPanel object, this in turn ultimately invokes my On Paint
method which redraws my graphs. HOWEVER, the graph appears very quickly, then
is cleared again and the standard Form grey background replaces the graph
drawn in the panel.

Why is my Panel data displayed correctly but then instantly cleared. I send
the Refresh call directly to the MyPanel instance and not to the parent form.

I have moved the code logic from a combination that ALMOST worked perfectly,
ie the double buffering worked but wanted to remove the initial erase flicker.
In this previous working scneario, I had a Panel (not a derived Panel, ie
MyPanel), which sat directly on a CustomControl. Then the Refresh () produced
the graph data that persisted on the display until the second timer fired and
the data (plus flicker) was then redisplayed. WHY BY USING MY DERIVED PANEL
ON A FORM DOES MY CODE BEHAVE SO DIFFERENTLY TO THAT OF DISPLAYING A NATICE
PANEL ON A CUSTOMCONTROL.

So, once again, my graph appears for an instant, then is overwritten by the
standard Form Grey background colour. I do NOT have an active
OnPaintBackground and do NOT handle the associated event.

Many thanks for your time.


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200605/1
May 12 '06 #6
Hoi Kevin, many many thanks. This was indeed the problem. I assumed the
Graphics context returned by this.CreateGraphics would be OK. Don't
understand why pe.Graphics passed to the Paint routine differs but it sure
does.

Now have flicker free graphics which persist.

Many many thanks once again.

Paul.
Kevin Spencer wrote:
The OnPaint method passes the Graphics instnace to your app via the
PaintEventArgs. You're not using it.
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.

[quoted text clipped - 71 lines]

Many thanks for your time.


--
Message posted via http://www.dotnetmonster.com
May 15 '06 #7

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

Similar topics

0
by: Brian K | last post by:
I am new to Apache Batik and I am now doing a SVG Editor for my project. I use Java as programming language. I use Batik to generate the SVG from Java Graphics2D, as I would like to transform...
2
by: Christian Soltenborn | last post by:
Hi guys, I have a question to VB .NET: I add a Graphics object to a panel and use a bunch of DrawLine methods etc (it's really nice and convenient). But: As soon as I send my form (which...
12
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet...
11
by: achiever | last post by:
I am a IIIrd electronics Engg student i want to know what is the role of graphics in c is it ok to spend a lot of time on learning c graphic or to start the new language like JAVA. Thanks in...
9
by: she_prog | last post by:
Dear All, I need to save the content of a panel to a bitmap. The panel can have many child controls which also need to be saved. The problem would be solved if I could have the panel saved to a...
5
by: Andy | last post by:
Hi, I am using the following code to render a text string in a new bitmap file. The code works, but the text looks, well, crappy, even though I told it to use ClearType hints. Any idea how to...
12
by: gsal | last post by:
What would be the easiest way to go about offering 3D graphics for the purpose of rendering geometry? Suppose engineers (my co-workes) have to design some enclosure, nozzle, bracket, or whatever...
4
by: Jon Harrop | last post by:
I am writing a 3D graphing component built upon WPF and would like to have 2D vector graphics (e.g. typeset mathematics) as labels laid out from 3D coordinates. For example, a tick on an axis has a...
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.