使用Graphics.DrawImage()在表单上绘制图像

时间:2011-06-16 13:35:03

标签: c# image graphics gdi+

我正在尝试在所有其他控件前面的表单上绘制图像。 我试图在控件前面制作一个透明面板,但它只显示背景并且没有显示控件。 我的代码是:(我用它来产生褪色效果)

Player1ColorMatrix.Matrix33 = Player1Transparency;

Player1ImageAttributes.SetColorMatrix(Player1ColorMatrix,
                    ColorMatrixFlag.Default,
                    ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(Player1ScoreImage, Player1rect, 0, 0, 200, 62, GraphicsUnit.Pixel, Player1ImageAttributes);
    Player1Transparency = 0.0f;

player1scoreimage是图像,player1rect是我要在其中绘制图像的矩形

如何让这张图片出现在其他控件的前面?

感谢, 奥菲尔

1 个答案:

答案 0 :(得分:1)

尝试使用自定义面板:

private class PanelX : Panel
{
  protected override CreateParams CreateParams
  {
    get
    {
      CreateParams cp = base.CreateParams;
      cp.ExStyle |= 0x20;
      return cp;
    }
  }

  protected override void OnPaint(PaintEventArgs e)
  {
    using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, 0, 0, 0)))
    {
      e.Graphics.FillRectangle(brush, this.ClientRectangle);
    }
  }
}
相关问题