locked
Background Image for the dialog RRS feed

  • Question

  • Hi,

    I want to set a background image for my dialogs, in a windows mobile application, but there's no property for that in windows forms, then I need to paint it using the paint event, but how can I change the size of the image, or if there's any other way to assign image to the dialog just let me know..


    Regards
    Thursday, May 28, 2009 8:09 AM

Answers

  • Override the OnPaintBackground and draw image to specific size, in this case the ClientRectangle.

            // Load your background image into _backgroundImage object
            private Bitmap _backgroundImage = new Bitmap(320, 240);
    
            protected override void OnPaintBackground(PaintEventArgs e)
            {
                e.Graphics.DrawImage(this._backgroundImage, 
                                        this.ClientRectangle, 
                                        0, 
                                        0,
                                        this._backgroundImage.Width,
                                        this._backgroundImage.Height,
                                        GraphicsUnit.Pixel,
                                        new ImageAttributes());
            }
    

    why do you robot?
    • Proposed as answer by therobotgeek Friday, May 29, 2009 6:05 PM
    • Marked as answer by warrentang Monday, June 1, 2009 9:51 AM
    Friday, May 29, 2009 6:05 PM

All replies

  • Hi Mankeer,

    Yes you need to paint the background as there is no property available directly.

    I think its best example for your requirement:

    http://expression.microsoft.com/en-us/dd279543.aspx


    Regards,
    Malleswar
    Thursday, May 28, 2009 8:21 AM
  • You also may want to check out the "UI Framework" for Windows Mobile on the Codeplex. It will simplify the painting of the background in some cases.

    Joel Ivory Johnson
    Thursday, May 28, 2009 12:05 PM
  • Override the OnPaintBackground and draw image to specific size, in this case the ClientRectangle.

            // Load your background image into _backgroundImage object
            private Bitmap _backgroundImage = new Bitmap(320, 240);
    
            protected override void OnPaintBackground(PaintEventArgs e)
            {
                e.Graphics.DrawImage(this._backgroundImage, 
                                        this.ClientRectangle, 
                                        0, 
                                        0,
                                        this._backgroundImage.Width,
                                        this._backgroundImage.Height,
                                        GraphicsUnit.Pixel,
                                        new ImageAttributes());
            }
    

    why do you robot?
    • Proposed as answer by therobotgeek Friday, May 29, 2009 6:05 PM
    • Marked as answer by warrentang Monday, June 1, 2009 9:51 AM
    Friday, May 29, 2009 6:05 PM
  • Excellent answers,

    Thank you very much.


    Regards
    Saturday, May 30, 2009 5:31 AM