473,511 Members | 15,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Panel Painting ghost

When the application I'm working on is run it creates a panel with a Paint
event customized to draw primitives (circles, rectangles, etc.), places the
panel on a form, and then launches the form.

The weird part is, the panel, in the instant it becomes visible, seems to
have an image of what this panel had in it the LAST TIME THE APPLICATION WAS
RUN! Since this panel is created anew every time the application is run
('natch), this seems odd to me. I call this the 'ghost image'.

Context, some of which might help:

(*) VS C++.NET 2005 Express
(*) Panel DoubleBuffered = true ;
(*) Panel created in stack syntax in main()
(*) Form created in stack syntax in main()
(*) Custom Paint handler is += to Panel
(*) Custom Paint handler just draws primitives

I've also noticed that everytime the form is moved the panel's Paint event
fires twice. But, it looks like when the form/panel are first shown the
panel's Paint event only fires once. When the form is moved it doesn't
exhibit this behavior (the painted image remains solid and doesn't flicker).

It also (visually) seems to be a 3-part entry. It shows the 'ghost' image,
then it clears (black in my case), then shows my graphics (shows what paint
says). That is, it flickers. If it only showed the 'ghost image' and then my
graphics it would not flicker, as my graphics are static (don't animate at
all)..

It does this in both release and debug, both inside the GUI and stand-alone
exe's.

As all I do is create the panel, set-up panel graphics (paint handler), add
to form, and then show form (in that order), it can't be my code setting
things up 'late' after the form has been shown causing this behavior.

Is this possibly a known bug, or what? I can't imagine there is any code I
could write that could intentionally cause this behavior without it being
some problem in the system somehow.

Any comments? Thanks in advance for responses! : )

[==P==]
Nov 27 '05 #1
2 2141
JAL
Peteroid... First, just use main to unit test or launch your app, not to
actually create an application. For a winforms c++/cli project main just
creates an object as in:

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(fal se);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

So create your application in a class and create an instance of the class in
main.

Second, I usually just override OnPaint as in:

protected override void OnPaint(PaintEventArgs e)
{
Graphics g= e.Graphics;
foreach (IDrawableShape ds in drawHistory)
{
ds.DrawYourself(g);
}
}

Apologies for the C# code.

Third, in general unless you need RAII behaviour, I would use gcnew for
reference types and let the garbage disposer manage releasing managed
resources. So outside of classes with an explicitly declared destructor use
gcnew. Use stack semantics for value types and classes with an explicitly
declared destructor which now in C++/cli maps to Dispose.

Personally, I see no problem with letting the wizard create the basic
winforms project and then adding your logic to project.

Hope that helps.

"Peteroid" wrote:
When the application I'm working on is run it creates a panel with a Paint
event customized to draw primitives (circles, rectangles, etc.), places the
panel on a form, and then launches the form.

The weird part is, the panel, in the instant it becomes visible, seems to
have an image of what this panel had in it the LAST TIME THE APPLICATION WAS
RUN! Since this panel is created anew every time the application is run
('natch), this seems odd to me. I call this the 'ghost image'.

Context, some of which might help:

(*) VS C++.NET 2005 Express
(*) Panel DoubleBuffered = true ;
(*) Panel created in stack syntax in main()
(*) Form created in stack syntax in main()
(*) Custom Paint handler is += to Panel
(*) Custom Paint handler just draws primitives

I've also noticed that everytime the form is moved the panel's Paint event
fires twice. But, it looks like when the form/panel are first shown the
panel's Paint event only fires once. When the form is moved it doesn't
exhibit this behavior (the painted image remains solid and doesn't flicker).

It also (visually) seems to be a 3-part entry. It shows the 'ghost' image,
then it clears (black in my case), then shows my graphics (shows what paint
says). That is, it flickers. If it only showed the 'ghost image' and then my
graphics it would not flicker, as my graphics are static (don't animate at
all)..

It does this in both release and debug, both inside the GUI and stand-alone
exe's.

As all I do is create the panel, set-up panel graphics (paint handler), add
to form, and then show form (in that order), it can't be my code setting
things up 'late' after the form has been shown causing this behavior.

Is this possibly a known bug, or what? I can't imagine there is any code I
could write that could intentionally cause this behavior without it being
some problem in the system somehow.

Any comments? Thanks in advance for responses! : )

[==P==]

Nov 27 '05 #2
Hi JAL,

I think you're talking more about programming style than the problem I'm
talking about. But ,that being said...

I like to create console C++ projects because I use the console to put debug
helpers (I can use the console to display info in real time without having
to stop and inspect with the debugger). However, I do create my own Form
class (derived from System::Form) and launch it, so this is somewhat
equivalent to your suggestion of putting my application in a class and
creating an instance of it. It just happenes to also be a form! : ) I also
don't really like Winform projects since I like as much control of the
source as possible, and Winform adds its own stuff based on GUI interface
modifications.

As I'm using '/clr:pure', ALL of my code is garbage collected. The only
thing close to unmanaged code is I use '*' type pointers to doubles. I've
tried the 'clr/safe' setting. That generates over 6000 errors, so I'm not
going there... lol

I do, indeed, overrride the Paint event and put in my handler, one that
looks remarkable like the one you provided (basically, draw the graphic
primitives in a list). It is prefaced by an 'update' method to make sure
what it is shown reflects the current state of the application.

Now I have to assume anything that can be done in a winform project can be
done in a console project with the proper setup.

All of this does not explain how the state on a new Panel in a new
application run could possible start with the image of what was in 'this'
Panel the last time the application was executed. That just shouldn't happen
for ANY reason...

[==P==]

"JAL" <JA*@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Peteroid... First, just use main to unit test or launch your app, not to
actually create an application. For a winforms c++/cli project main just
creates an object as in:

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(fal se);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

So create your application in a class and create an instance of the class
in
main.

Second, I usually just override OnPaint as in:

protected override void OnPaint(PaintEventArgs e)
{
Graphics g= e.Graphics;
foreach (IDrawableShape ds in drawHistory)
{
ds.DrawYourself(g);
}
}

Apologies for the C# code.

Third, in general unless you need RAII behaviour, I would use gcnew for
reference types and let the garbage disposer manage releasing managed
resources. So outside of classes with an explicitly declared destructor
use
gcnew. Use stack semantics for value types and classes with an explicitly
declared destructor which now in C++/cli maps to Dispose.

Personally, I see no problem with letting the wizard create the basic
winforms project and then adding your logic to project.

Hope that helps.

"Peteroid" wrote:
When the application I'm working on is run it creates a panel with a
Paint
event customized to draw primitives (circles, rectangles, etc.), places
the
panel on a form, and then launches the form.

The weird part is, the panel, in the instant it becomes visible, seems to
have an image of what this panel had in it the LAST TIME THE APPLICATION
WAS
RUN! Since this panel is created anew every time the application is run
('natch), this seems odd to me. I call this the 'ghost image'.

Context, some of which might help:

(*) VS C++.NET 2005 Express
(*) Panel DoubleBuffered = true ;
(*) Panel created in stack syntax in main()
(*) Form created in stack syntax in main()
(*) Custom Paint handler is += to Panel
(*) Custom Paint handler just draws primitives

I've also noticed that everytime the form is moved the panel's Paint
event
fires twice. But, it looks like when the form/panel are first shown the
panel's Paint event only fires once. When the form is moved it doesn't
exhibit this behavior (the painted image remains solid and doesn't
flicker).

It also (visually) seems to be a 3-part entry. It shows the 'ghost'
image,
then it clears (black in my case), then shows my graphics (shows what
paint
says). That is, it flickers. If it only showed the 'ghost image' and then
my
graphics it would not flicker, as my graphics are static (don't animate
at
all)..

It does this in both release and debug, both inside the GUI and
stand-alone
exe's.

As all I do is create the panel, set-up panel graphics (paint handler),
add
to form, and then show form (in that order), it can't be my code setting
things up 'late' after the form has been shown causing this behavior.

Is this possibly a known bug, or what? I can't imagine there is any code
I
could write that could intentionally cause this behavior without it being
some problem in the system somehow.

Any comments? Thanks in advance for responses! : )

[==P==]

Nov 27 '05 #3

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

Similar topics

5
15592
by: Wilfried Mestdagh | last post by:
Hi, I seems not to find how to change borderstyle of a panel so that it is not sunken, but raised. I only find a 3d setting in obejct inspector... Someone knows this ? -- rgds, Wilfried...
4
11663
by: Aaron Smith | last post by:
I have a panel that I have in the paint event to draw a Raised 3d border around it.. The problem is, if a msgbox is popped up or a tooltip is displayed, it leaves lines on the panel. I've tried...
6
3152
by: shumaker | last post by:
How do I make a panel control invisible, but still recieve events? I have a panel that I set visible= false, and over it I am using GDI+ to paint a grid of rectangles. It has to be invisble or...
2
2290
by: _DD | last post by:
I'm trying to gracefully intercept Control and Alt keys for mouse events within a Panel. I realize that keyboard is not normally relevant there, but in this case, I need to get...
2
9360
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
4
3546
by: =?Utf-8?B?cmF5IG4=?= | last post by:
I have a need to put an image on the background of a SplitterPanel. However, I need it to appear in the bottom right corner of the panel instead of the standard Centered/Tiled/Stretched found in...
9
4259
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...
14
2400
by: Adam Sandler | last post by:
I have a class with a method which returns a panel. The panel was not created with the visual editor, I coded it by hand -- because some of the content on the panel can be dynamic and thus I chose...
1
2142
by: desturrr | last post by:
I have been searching all over the sites, but i couldn't manage to get button or any other component on a image panel. There are some codes that says while painting the picture you can show...
0
7237
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
7137
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
7349
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
5659
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,...
1
5063
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...
0
4734
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...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.