Click here to Skip to main content
Licence CPOL
First Posted 2 Sep 2006
Views 31,546
Bookmarked 13 times

MDI Container background

By | 2 Sep 2006 | Article
Change mdi form background picture at run time

Introduction

 

Change mdi form background picture at run time

This article demonstrate how to change MDI Container background image at run time

 

Step 1: Create Windows Application Project

 

Please do the following to create a Windows Application project:

  • Select File menu -> New -> Project.
  • Choose C# from Project Types pane.
  • In the Templates pane, choose Windows Application for Visual C# projects.

Step 2:

            Add Controls

1.       Menustrip Control

2.       OpenFileDialog Control

 

Change              IsMdiContainer Property = True

 

Step 3: Coding Sections

  1. Open Image file

private void openToolStripMenuItem_Click(object sender, EventArgs e)

  {

    string Backpath = null;

  try

    {

          openFileDialog1.Filter = "Jpg|*.jpg";

          openFileDialog1.ShowDialog();

          Backpath = openFileDialog1.FileName;

          // calling Image background method

          Change_BackgroundImage(Backpath);

    }

  catch (Exception ex)

    {

           MessageBox.Show(ex.Message);

    }

  }

  1. Change_BackgroundImage(Backpath) Method

       private void Change_BackgroundImage(string _path )

        {

            string imagepath = _path;

            System.IO.FileStream fs;

            // MDI Form image background layout change here

            //(Remember control imagebakground layout take default form background layount )

            this.BackgroundImageLayout = ImageLayout.Stretch;

            // Checking File exists if yes go --->

            if (System.IO.File.Exists(imagepath))

            {

                // Read Image file

                fs = System.IO.File.OpenRead(imagepath);

                fs.Position = 0;

                // Change MDI From back ground picture

                foreach (Control ctl in this.Controls)

                {

                    if (ctl is MdiClient)

                    {

                        //ctl.BackColor = Color.AntiqueWhite;

                        ctl.BackgroundImage = System.Drawing.Image.FromStream(fs);

                        break;

                    }

                }

             }

        }

Conclusion

I am looking forward to receive any comments/suggestion you have for me.

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

 

 

 

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

anishmm

Software Developer (Senior)

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralProblem to use this for RightToLeft Layout MDI Form PinmemberFarhad Qeshlaqi19:28 3 Mar '11  
GeneralA Guide To Writing Articles For Code Project Pinmembermwdiablo15:33 3 Sep '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 2 Sep 2006
Article Copyright 2006 by anishmm
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid