|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article tries to explain how to develop an MDI application. Text editors and image editors are common examples where multiple documents are useful. The attached demo application allows you to open images in child windows and then watermark them with a custom text. Using the codeCreating parent windowAdd a new form to your application. To make this form as the parent form,
set its Creating child form templateAdd a second form which will be the template for the child forms. Each time you want to create a new child window to your application, you can create a new instance of this template form and make the first form as its parent form. //Create a new instance of the MDI child template form
Form2 chForm = new Form2();
//Set parent form for the child window
chForm.MdiParent=this;
//Display the child window
chForm.Show();
Merging menus of child and parentWhen we have a The
Changing layout of child windows within the parentTo change the layout of child forms within a parent form use
//Cascade all child forms.
this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);
Minimize all and Maximize all
//Gets forms that represent the MDI child forms
//that are parented to this form in an array
Form[] charr= this.MdiChildren;
//For each child form set the window state to Maximized
foreach (Form chform in charr)
chform.WindowState=FormWindowState.Maximized;
If we loop through the child forms and call the Adding scroll for large imagesThe child form template has a Making the images resize with the formWhen a child window is resized the private void Form2_Resize(object sender, System.EventArgs e)
{
//Resize the panel to fit in the form
//when the form is maximised or minimised
panel1.Width= this.Width-20;
panel1.Height=this.Height-40;
}
Adding a simple text watermark to an imageTo add a text watermark to the image in the child window this is what we do: if (pictureBox1.Image != null)
{
//Create image.
Image tmp = pictureBox1.Image;
//Create graphics object for alteration.
Graphics g = Graphics.FromImage(tmp);
//Create string to draw.
String wmString = "Code Project";
//Create font and brush.
Font wmFont = new Font("Trebuchet MS", 10);
SolidBrush wmBrush = new SolidBrush(Color.Black);
//Create point for upper-left corner of drawing.
PointF wmPoint = new PointF(10.0F, 10.0F);
//Draw string to image.
g.DrawString(wmString, wmFont, wmBrush, wmPoint);
//Load the new image to picturebox
pictureBox1.Image= tmp;
//Release graphics object.
g.Dispose();
}
We create a Points of Interest
Acknowledgement
|
||||||||||||||||||||||||||||||||||||||||||