MDI (Multiple Document Interface) Set Background Image
To change the background color of a parent MDI form is to set the background color property. However, it seems to ignore it. Also some of us hate the dark gray background.
In this tutorial I will help you to programmatically set the Background Image of the MDI parent. This includes vs2003 & vs2005 c# source file.
VS2003 C#
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private string filepath = System.Environment.CurrentDirectory;
private void Form1_Load(object sender, System.EventArgs e)
{
filepath = System.IO.Path.Combine (filepath, "Desert.jpg");
foreach(Control cntrl in this.Controls)
{
if ((cntrl.GetType() == typeof(System.Windows.Forms.MdiClient ))){
cntrl.BackgroundImage = Image.FromFile(filepath);
}
}
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Form frmChild = new Form();
frmChild.MdiParent = this;
frmChild.Text = "Hello, im a child form";
frmChild.Show ();}VS2005 C# - applicable to VS2008
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MdiApplicationCS2005
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control cntrl in this.Controls)
{
if (cntrl is MdiClient)
{
cntrl.BackgroundImage = Properties.Resources.Jellyfish;
}
}
}
private void childToolStripMenuItem_Click(object sender, EventArgs e)
{
Form frmChild = new Form();
frmChild.MdiParent = this;
frmChild.Text = "Hello i'm a child form";
frmChild.Show();
}
}
} 





5 comments:
Hi sir can u make a database buck up tutorial using vb.net 2008 and sql server 2005
Thanks in advance
buck up! hehehehehehe
sure no problem. paki antay lang cguro sir
Thank you for being Nice to the newbie programmers
^_^
Thanks for your so useful code. Just to give a little heads up:
Make sure your FORM's LAYOUT property IS NOT RIGHT-to-LEFT or it doesn't work.
Ridiculous/Irrelevant isn't it?
Thanks again anyway.
Good article
We can submit .net related article links on http://www.dotnettechy.com to increase the traffic
Post a Comment