Problem with Paint Degaget on a form based control

  • Thread starter Thread starter Roy Chastain
  • Start date Start date
R

Roy Chastain

I have created a control that is based on Form. The Paint delegate code never gets called. Forms are new to me, so I probably
missed some important basic concept.

public class SplashForm: System.Windows.Forms.Form
{
protected override void OnLoad (EventArgs e)
{
this.Size = bitmap_to_be_clipped.Size;
this.Region = clipping_region;
this.BackgroundImage = bitmap_to_be_clipped;
} /* OnLoad */

private void PaintIt (object sender, PaintEventArgs e)
{
e.Graphics.DrawString("ProductName",font_product,
brush_product,pointf_product);
} /* PaintIt */

public SplashForm (Image the_image, Color transparent_color)
{
InitializeComponent();
this.Paint += newSystem.Windows.Forms.PaintEventHandler(this.PaintIt);
this.ResumeLayout(false);
.....
}
} /* end of class */

Then code that uses this does a
SplashForm splash = new SplashForm(image,color);
splash.Show();

I have tried invalidates on both sides of spash.Show to no avail.

Thanks for the advice
 
Hi Roy,
The reason is maybe in the way you use that form. I see it is a SplashForm.
Maybe you have code that looks like this

SplashForm splash = new SplashForm(image,color);
splash.Show();

MainForm mf = new MainForm();

//Load main form

splash.Close();
Application.Run(mf);

In this case your splash want be painted because Applicaion.Run(...) is the
methods that starts the windows message loop. Before that no messages are
send to the controls. Thus no WM_PAINT messages are send to your splash
form.
To have it work you should create the spalsh form in separate UI thread.
This way it would be alive while you load the main form.

One hint. Instead a handling forms' own events you can override the
corresponding OnXXX method. For each event WindowsForms controls have
virtual OnXXX method. So, for Paint event you can overload OnPaint method.

--
HTH
B\rgds
100 [C# MVP]

Roy Chastain said:
I have created a control that is based on Form. The Paint delegate code
never gets called. Forms are new to me, so I probably
 
Back
Top