1
我想在Windows Mobile应用程序中将一个图像应用于面板控件,但在该控件的属性中,我们只有背景颜色。在这种情况下应该怎么做?如何将图像作为背景应用于面板控件
我使用VS 2008,Mobile 6专业版
我想在Windows Mobile应用程序中将一个图像应用于面板控件,但在该控件的属性中,我们只有背景颜色。在这种情况下应该怎么做?如何将图像作为背景应用于面板控件
我使用VS 2008,Mobile 6专业版
窗口创建,从面板继承了一个新的类并覆盖OnPaintBackground。
class MyPanel : Panel
{
private Image m_image;
public Image BackgroundImage
{
get { return m_image; }
set
{
if (m_image != null) m_image.Dispose();
m_image = value;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (BackgroundImage == null)
{
base.OnPaintBackground(e);
}
else
{
e.Graphics.DrawImage(BackgroundImage, 0, 0);
}
}
}