473,725 Members | 2,278 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 2169
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:

[STAThreadAttrib ute]
int main(array<Syst em::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::En ableVisualStyle s();
Application::Se tCompatibleText RenderingDefaul t(false);

// Create the main window and run it
Application::Ru n(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(PaintEv entArgs 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*@discussion s.microsoft.com > wrote in message
news:CD******** *************** ***********@mic rosoft.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:

[STAThreadAttrib ute]
int main(array<Syst em::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::En ableVisualStyle s();
Application::Se tCompatibleText RenderingDefaul t(false);

// Create the main window and run it
Application::Ru n(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(PaintEv entArgs 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
15624
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 http://www.mestdagh.biz
4
11696
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 invalidate after the msgbox to no avail... Here is the event: Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,...
6
3165
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 else it covers up the GDI+. However, it is not firing the mousedown and up events while it is not visible. I am setting the visible property using VS through the properties window. I kind of anticipated that an invisble control would still...
2
2296
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 Ctrl-LeftMouseButton, etc. This could be intercepted by the form that owns the panel, but that does not seem very elegant. Are there any alternatives? I could use another type of base control if necessary. I'm mostly painting graphics.
2
9376
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
3556
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 the BackgroundImageLayout Property. Is there an example of how to do that or could someone offer a suggestion? Thanks
9
4271
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 Graphics object, which is the same as if I'd need to print it. It'd be easy using Control.DrawToBitmap, but I also need the invisible part of the panel (which is hidden because of scrolling) and DrawToBitmap just takes a screenshot.
14
2425
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 to do it that way. At any rate, I have an event handler for a button which instantiates an object of that class I mentioned and calls the method to return the panel. I put the panel on form1 like so: // it's really not called 'Class', I...
1
2152
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 components. Basically they are overriding the paint method of the panel. But i need to make my frame background image while not having the diffuculties of overriding the paint method of panel because i have many components . Netbeans offers me to change...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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
9257
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
9179
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
9116
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
6011
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();...
0
4519
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2637
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.