Friday, February 18, 2005

Non-Rectangular Windows Forms

Yo, now a problem from me. I tried to search for it, without any success.

http://www.thecodeproject.com/csharp/nonRectangularForm.asp

I'm trying to create a non-rectangular windows form. Currently it's quite easy if the person uses 24bit and below resolution, you just assign your background image and set your transparencykey. But who uses 24bit and below nowadays? We all use 32bit.

That article above explains to you how to get it done. The modification I made was to make it happen in OnPaintBackground event instead of OnPaint event, because if it was OnPaint event, the controls will flicker and you can see what's behind the form.

So now, the problem is, it still flickers and is very slow. To solve this flickering, you must implement double buffering. But when I set the styles to do double buffering, the transparency of the background is ignored.

Question. How can I achieve double buffering which the background transparency still intact?

Here's the code for reference

protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
this.SuspendLayout();

// First we create a graphics object using the PiantEventArgs e that will use the
// form
Graphics grfx = e.Graphics;
// Make Antialiasing which avoid stepped look for circular path and curves you
// may use the SmoothingMode.AntiAlias
grfx.SmoothingMode = SmoothingMode.None;
grfx.DrawImage(this.background, this.frmRectangle);

this.ResumeLayout();
}

Setting the styles I'm sure you guys should know. How to I apply transparency over here?

No comments: