user3004295
user3004295

Reputation: 93

how to change background image of a form in c#?

Can I use Menu strip or context menu to allow the user so that he can change the background image of the window instead of background colour in c# ?

Upvotes: 10

Views: 101141

Answers (2)

davi
davi

Reputation: 1

  1. every image you want use to background image form select in properties window again several once
  2. Go into soluitionExproler to child Form1 open Form1.Designer.cs
  3. copy this part of form Designer Form1.ActiveForm.BackgroundImage = global::TtimerComputer.Properties.Resources.ImageName;
  4. paste into your wanted change ImageName

Example:

private void btnBackSilver_Click(object sender, EventArgs e)
{
  Form1.ActiveForm.BackgroundImage = global::YourProjectName.Properties.Resources.ImageName1;
}

private void btnBackGreen_Click(object sender, EventArgs e)
{
  Form1.ActiveForm.BackgroundImage = global::YourProjectName.Properties.Resources.ImageName2;
}

Upvotes: 0

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

You can use MenuStrip Control to change the BackgroundImage of the Form.

Note: Here i'm giving you the steps/idea so that you can change as per your requirements.but you need to Explore more.

Steps:

1.You add the MenuStrip control from Menus & Toolbars Category in ToolBox and then Add the MenuStrip To the Form.

2.You can add Menu Items as you want .ex: change Image1,change Image2 etc.,

3.You can handle the MenuItemClick Event to Change the BackgroundImage of the Form

Sample Code:

private void changeBGImageToolStripMenuItem_Click(object sender, System.EventArgs e)
{
    Image myimage = new Bitmap(@"D:\Images\myImage1.jpg");
    this.BackgroundImage = myimage;
}

Sample code2: accessing Images from Resources file.
Note: first you need to add the Images into Resources.
Here i have added myImage1.jpg file to Resources.

See here for how to add images to Resources

this.BackgroundImage = Properties.Resources.myImage1;

Please let me know if you need anything more.

Upvotes: 18

Related Questions