views:

18

answers:

1

I would like to place one image to panel control in windows mobile application,but in properties to that control we have only backgroundcolor.what to do in this type of situation?

I am using VS 2008,windows mobile 6 professional

A: 

Create a new class that inherits from Panel and override 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);
        }
    }
}
ctacke