Reputation: 93
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
Reputation: 1
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
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