Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doublebuffering and resizing

Status
Not open for further replies.

kylua

Technical User
Sep 30, 2002
199
GB
Hi

I am trying to get a form to rearrange itself when it maximises so that the working panel is in the middle.
No big deal I thought. But it turns out I cannot stop it flickering like mad!!

I have this for the initialisation:
Code:
Public Sub New()
        MyBase.New()

        InitializeComponent()
        Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.DoubleBuffered = True
End Sub

And this is the actual code:
Code:
Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Dim x As Integer = Me.Width
        Dim y As Integer = Me.Height
        x = (x / 2) - 443
        y = (y / 2) - 315

        PanHolder.Left = x
        PanHolder.Top = y
    End Sub
Now I have used all sorts of variations on this.
I've put refresh into the code, I've tried putting the doublebuffering code into the designer.vb, I've attempted to make the panHolder, (a panel), doublebuffer = true and am told I can't access it.
There MUST be a simple solution to this but I can't find it.
Supposedly Panels don't double buffer? Will the children of the panel double buffer? These are also largely panels.
I have seen that you can create panels that can double buffer but these can't be added at design time and I dread having to rebuild the entire structure from scratch on run time. (Altho I realise that happens in the designer and I can just C&P much of that code!)

Any suggestions greatly welcomed.
 

Pretty much the only way to do this is as you said, with a user control that you call the SetStyle method in its constructor.

If you create a user control, you can add it at design time. After you create the control, open the form where it will be added. At the top of the Toolbox there should be a section that contains the user control. It is called "My User Controls" in VS 2003, and "ProjsectName Components" (where Project Name is the name of the project). I'm not sure what it is called in VS 2005. But, you can drag and drop your user control from the Toolbox onto your form at design time. Just set up the constructor like you have for the form:

Public Sub New()
MyBase.New()

InitializeComponent()
Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.DoubleBuffered = True
End Sub




I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Not knowing how bad your situation or what you might mean by "like mad", all I can say is I've used double split panels without having any major problems with flickering. I didn't use them in the same way you would, but that would get you a center panel that resized all on its own and maybe without the flickering like mad.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top