2010-09-25 24 views
0

我正在用C#开发智能设备应用程序。我是Windows Mobile的新手。我通过使用下面的代码将背景图像添加到了我的应用程序中的窗体中。我想让这个图像透明,这样我的窗体上的其他控件就能正常显示。如何在Windows Mobile中使背景图像透明?

protected override void OnPaint(PaintEventArgs e) 
     { 
      base.OnPaint(e); 
      Bitmap CreateCustomerImage = new Bitmap(@"/Storage Card/background.png"); 
      e.Graphics.DrawImage(CreateCustomerImage, 0, 0); 
     } 

背景图像有蓝色。当应用程序运行诸如标签之类的控件时,文本框&其他控件以白色显示。如何解决这个问题呢?你能否提供我可以解决上述问题的任何代码或链接?

+0

如果你使背景透明,你会看到电池。 – 2010-09-25 09:56:30

+0

请不要只是重新提出一个问题,然后再问。 – ctacke 2010-09-25 15:10:24

+0

可能的重复[如何使标签和其他控件透明与Windows Mobile上的背景图像?](http://stackoverflow.com/questions/3793554/how-to-make-label-other-controls-transparent-with-背景图像上的窗口-M) – ctacke 2010-09-25 15:10:31

回答

2

如果你想让你的控件透明或图像,但是如果你想在绘制图像时使图像透明的话,我不能弄清楚。

您需要将特定像素设置为透明颜色,因为Windows Mobile“本机”不支持。您需要创建绘制图像时使用的ImageAttributes实例。以下示例使用左上角的像素作为“透明颜色”。

private readonly ImageAttributes imgattr; 
.ctor() { 
    imgattr = new ImageAttributes(); 
    Color trns = new Bitmap(image).GetPixel(0, 0); 
    imgattr.SetColorKey(trns, trns); 
} 

protected override void OnPaint(PaintEventArgs e) { 
    e.Graphics.DrawImage(image, 
         new Rectangle(0, 0, Width, Height), 
         0, 0, image.Width, image.Height, 
         GraphicsUnit.Pixel, 
         imgattr); 
}