Introduction<o:p>
<o:p>
Change mdi form background picture at run time<o:p>
This article demonstrate how to change MDI Container background image at run time <o:p>
<o:p>
Step 1: Create Windows Application Project<o:p>
<o:p>
Please do the following to create a Windows Application project:<o:p>
- Select File menu -> New -> Project. <o:p>
- Choose C# from Project Types pane. <o:p>
- In the Templates pane, choose Windows Application for Visual C# projects. <o:p>
Step 2: <o:p>
Add Controls<o:p>
1. Menustrip Control<o:p>
2. OpenFileDialog Control<o:p>
<o:p>
Change IsMdiContainer Property = True<o:p>
<o:p>
Step 3: Coding Sections<o:p>
- Open Image file <o:p>
private void openToolStripMenuItem_Click(object sender, EventArgs e)<o:p>
{<o:p>
string Backpath = null;<o:p>
try<o:p>
{<o:p>
openFileDialog1.Filter = "Jpg|*.jpg";<o:p>
openFileDialog1.ShowDialog();<o:p>
Backpath = openFileDialog1.FileName;<o:p>
// calling Image background method<o:p>
Change_BackgroundImage(Backpath);<o:p>
}<o:p>
catch (Exception ex)<o:p>
{<o:p>
MessageBox.Show(ex.Message);<o:p>
}<o:p>
}<o:p>
- Change_BackgroundImage(Backpath) Method<o:p>
private void Change_BackgroundImage(string _path )<o:p>
{<o:p>
string imagepath = _path;<o:p>
System.IO.FileStream fs;<o:p>
// MDI Form image background layout change here<o:p>
//(Remember control imagebakground layout take default form background layount )<o:p>
this.BackgroundImageLayout = ImageLayout.Stretch;<o:p>
// Checking File exists if yes go ---><o:p>
if (System.IO.File.Exists(imagepath))<o:p>
{<o:p>
// Read Image file<o:p>
fs = System.IO.File.OpenRead(imagepath);<o:p>
fs.Position = 0;<o:p>
// Change MDI From back ground picture<o:p>
foreach (Control ctl in this.Controls)<o:p>
{<o:p>
if (ctl is MdiClient)<o:p>
{<o:p>
//ctl.BackColor = Color.AntiqueWhite;<o:p>
ctl.BackgroundImage = System.Drawing.Image.FromStream(fs);<o:p>
break;<o:p>
}<o:p>
}<o:p>
}<o:p>
}<o:p>
Conclusion<o:p>
I am looking forward to receive any comments/suggestion you have for me.<o:p>
Thank you for reading; I sincerely hope this article will help you a bit or two to know reporting services better through my applied approach<o:p>
<o:p>
<o:p>
<o:p>
<o:p>
<o:p>
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.