olive
olive

Reputation: 3143

How do you set the background image of a form to a user-selected image?

I have a Windows Forms form, and I want the user to select the background image. That is, when the application starts the file dialog appears from where the user can select the image he/she wants as the background.

How do I do this?

Upvotes: 1

Views: 593

Answers (2)

James Hulse
James Hulse

Reputation: 1581

There is a file dialog class http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.aspx which you can use to ask the user to select an image. Then you can set the forms BackgroundImage property.

Upvotes: 2

Kimberly
Kimberly

Reputation: 2712

To expand on havok's answer, if you set WindowState = WindowState.Minimized and ShowInTaskbar = false during form initialization, you can display the dialog in a Form.Load event handler ("occurs before a form is displayed for the first time"). The user will see the dialog before the main form is noticeable at all. After retrieving the image, set the BackgroundImage property as havok said, and restore the form to a normal startup state. System.Drawing.Image has a static method FromFile() that might help you, too.

Upvotes: 3

Related Questions