Thursday 28 April 2011

Mdi Forms In C#


Mdi Forms In C#



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace mdi_prg1
{
    public partial class Form1 : Form
    {
        private int childFormNumber = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {          
         Form2 f2 = new Form2();
         f2.MdiParent = this;
         f2.Text = "Window Form Number:" + childFormNumber++;
         this.FormBorderStyle = FormBorderStyle.Fixed3D;
         f2.Show();
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
      
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofdlg = new OpenFileDialog();
                       
            ofdlg.Title = "Open Text Files";
            ofdlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            ofdlg.FilterIndex = 2;
           
            if (ofdlg.ShowDialog() == DialogResult.OK)
            {
                richTextBox1.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
                richTextBox1.SelectionColor = Color.Red;
                richTextBox1.LoadFile(ofdlg.FileName, RichTextBoxStreamType.PlainText);
                this.Text = ofdlg.FileName.ToString();
            }

        }

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Invalidate();
        }

        private void minimizeToolStripMenuItem_Click(object sender, EventArgs e)
        {
         
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Rectangle BaseRectangle =
                new Rectangle(0, 0, this.Width - 1, this.Height - 1);

            Brush Gradient_Brush = new LinearGradientBrush(BaseRectangle, Color.Navy, Color.LightSlateGray,
                LinearGradientMode.Vertical);

            e.Graphics.FillRectangle(Gradient_Brush, BaseRectangle);
        }
    }
}

No comments:

Post a Comment