How does one create a rounded window?

  • Thread starter Thread starter zorro
  • Start date Start date
Z

zorro

Hello,
I want to have a window skin with rounded corners and where the
system's usual window frame is hidden, like in Windows Media Player.
Can I do this with Windows.Forms? Is it just a matter of setting some
property, like "myframe.visibility=false"?

nu-b
 
zorro,
you can use Control.Region property to crop the control in any shape you
want.
 
Hi,
Changing the region works, the only problem with this is that if you are
using any SmoothingMode to make the edges of the window took nice, you need
to clip the region to a few pixels bigger than your actual window. If you
do not do this you will end up with a very ugly pixelized edge.
 
Do you have any code samples that demonstrate this? I created a
rounded button, but like you said, the edges are pixellated. Is it
just a matter of growing the region by one pixel?

I would like to get a nicely antialiased edge based on the background
color of the control where the button is placed.

For reference what I do with my button is create a GraphicsPath object
in the shape I want (in this case it is just rounded edges) and create
a region based on that GraphicsPath. I then use various drawing
commands to fill the interior of the button, typically with a gradient
fill. I would like to be able to anti-alias the edge of the button
against the background of the controll on which it is placed.

Thanks
 
Here is a quick control i created which illustrates how this works, you'll
notice that the control is 1 pixel smaller than the region, this allows the
small margin required by the SmoothingMode.AntiAlias, the edges are smooth
and it works for every shape that i've used it for (circles, ellipses,
rounded rectangles...)
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Data;

using System.Text;

using System.Windows.Forms;

namespace RoundRegionSmoothEdges

{

public partial class UserControl1 : UserControl

{

public UserControl1()

{

this.SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.OptimizedDoubleBuffer , true);

this.BackColor = Color.Transparent;

InitializeComponent();

}

protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

GraphicsPath backPath = new GraphicsPath();

GraphicsPath forePath = new GraphicsPath();

backPath.AddEllipse(this.ClientRectangle);

forePath.AddEllipse(new Rectangle(1, 1, this.ClientRectangle.Width - 2,
this.ClientRectangle.Height - 2));

this.Region = new Region(backPath);

e.Graphics.FillPath(Brushes.Blue, forePath);

base.OnPaint(e);

}

}

}
 
Back
Top