Click here to Skip to main content
Click here to Skip to main content

MDI Container background

, 2 Sep 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

anishmm
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
GeneralProblem to use this for RightToLeft Layout MDI Form PinmemberFarhad Qeshlaqi3-Mar-11 19:28 
GeneralA Guide To Writing Articles For Code Project Pinmembermwdiablo3-Sep-06 15:33 

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 2 Sep 2006
Article Copyright 2006 by anishmm
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid