Showing posts with label Windows Forms. Show all posts
Showing posts with label Windows Forms. Show all posts

29 December 2009

Avoiding Flicker problem with Windows Form Controls

One of the quite common problems with the Windows Form is that it tends to flicker when many controls are placed over it. To solve this problem, just paste the code below in your form. Using this property, the painting of your controls remains invisible, and will display once it is done with drawing the controls.

protected override CreateParams CreateParams
{
   get
   {
       CreateParams objCreateParams = base.CreateParams;
       objCreateParams .ExStyle = 0x02000000;
       return objCreateParams ;
    }

}

You can also set the style for your form by using the following. But this would not significantly decrease the filckering tough.

this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.Opaque, true);

20 November 2009

How to Embed a Windows Form in Another Control

If you have to embed a windows form in another control say a tab page, panel, groupbox etc. then you have to set the TopLevel property of the form to false and define its parent control and couple of other properties also to give it desired feel.
For example:-


C#

Form1 objForm = new Form1();
Form1.TopLevel = false;
Form1.ControlBox = false;
Form1.FormBorderStyle = FormBorderStyle.None;
Form1.Dock = DockStyle.Fill;
Form1.Show();
Form1.Parent = this.pnlParent;


VB.Net

Dim objForm As New Form1()
Form1.TopLevel = False
Form1.ControlBox = False
Form1.FormBorderStyle = FormBorderStyle.None
Form1.Dock = DockStyle.Fill;
Form1.Show()
Form1.Parent = Me.pnlParent