コントロールの背景として透明な境界線を持つ画像を表示しようとしています。
残念ながら、次のように、透明な領域によって親フォームに穴が作成されます。
上の画像では、フォームの背景が赤いので、透明な領域で自分のコントロールの後ろに表示されることを望んでいました。
私が使用したコードは次のとおりです。
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (this.Image != null)
{
Graphics g = Graphics.FromImage(this.Image);
ImageAttributes attr = new ImageAttributes();
//set the transparency based on the top left pixel
attr.SetColorKey((this.Image as Bitmap).GetPixel(0, 0), (this.Image as Bitmap).GetPixel(0, 0));
//draw the image using the image attributes.
Rectangle dstRect = new Rectangle(0, 0, this.Image.Width, this.Image.Height);
e.Graphics.DrawImage(this.Image, dstRect, 0, 0, this.Image.Width, this.Image.Height,
GraphicsUnit.Pixel, attr);
}
else
{
base.OnPaint(e);
}
}
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
{
//base.OnPaintBackground(e);
}
OnMouseMove および OnMouseUp イベントを実装するコントロールが必要だったため、このクラスは PictureBox から継承されます。
私は一日のほとんどを研究してきましたが、さまざまなアイデアをうまくテストできませんでしたが、残念ながら、ほとんどは完全なフレームワークでしか機能せず、.Net CF では機能しません。
どんなアイデアでも大歓迎です。