カスタム形状の Windows Form
( public class Window : Form
) を作成しており、適切な影を配置する必要があります。フォームは角が丸い長方形GraphicsPath
で、フォームの形状を取得するために適切なものを定義しています。
これを行うことになっているコードの一部を次に示します。
private const int CS_DROPSHADOW = 0x00020000;
public Window()
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
SetStyle(ControlStyles.Opaque | ControlStyles.OptimizedDoubleBuffer, true);
TransparencyKey = Color.FromArgb(0xFF, 0, 0, 0);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
Pen ps = new Pen(Color.FromArgb(0xFF, 0, 0, 0));
e.Graphics.FillRectangle(ps.Brush, this.ClientRectangle);
Pen p1 = new Pen(Color.FromArgb(0xFA, 0xFA, 0xFA));
Pen p2 = new Pen(Color.FromArgb(0xCD, 0xCD, 0xCD));
GraphicsPath border =
RoundedRectangle.Create(new Rectangle(0, 0, Width - 1, Height - 1), 7);
e.Graphics.SetClip(border); // I'd prefer if this came after the following two
// lines, but doing that results in another problem
e.Graphics.FillPath(p1.Brush, border);
e.Graphics.DrawPath(p2, border);
base.OnPaint(e);
e.Graphics.ResetClip();
}
RoundedRectangle
クラスはこちらから。
結果の影は、フォームが完全に長方形であるかのようにキャストされます。これは、右下隅で最もよく見られます。影を正しく描画するにはどうすればよいですか?
編集: 2004 年 (8 年前) から Web でこれに関する議論を見つけているとは信じられませんが、まだ解決策が見つかりません。