カスタムウィンドウで、角丸ウィンドウ
カスタムウィンドウで、角丸にしてみた。前回のカスタムウィンドウを使用。右下は角丸にしていないです。ギザギザが気になるので、角丸の半径は小さくしてます。
protected override void OnResize ( EventArgs e )
{
base.OnResize( e );
int radius = 5;
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
// 左上
path.AddPie( 0, 0, radius * 2, radius * 2, 180, 90 );
// 右上
path.AddPie( this.Width - radius * 2, 0, radius * 2, radius * 2, 270, 90 );
// 左下
path.AddPie( 0, this.Height - radius * 2, radius * 2, radius * 2, 90, 90 );
// 中央
path.AddRectangle( new Rectangle( radius, 0,
this.Width - radius * 2, this.Height) );
// 左
path.AddRectangle( new Rectangle( 0, radius,
radius, this.Height - radius * 2 ) );
// 右
path.AddRectangle( new Rectangle( this.Width - radius, radius,
radius, this.Height - radius ) );
this.Region = new Region( path );
}
リサイズのときに角丸になるようにしてます。なので、初期状態で角丸にならないです。そのため、ロードイベントに次のコードを入れる。
OnResize( null );
これで、初期状態でも、リサイズしたときでも、角丸になるはず。
フルスクリーンのときも角丸になるので、気になるようだったら、つぎのように変更してみたり。
if ( this.WindowState == FormWindowState.Normal )
{
// 省略
}
else if ( this.WindowState == FormWindowState.Maximized )
{
path.AddRectangle( new Rectangle( 0, 0, this.Width, this.Height ) );
}
this.Region = new Region( path );
参考サイト
