Form Ownership : MDI « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » MDIScreenshots 
Form Ownership
Form Ownership

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace FormOwnership
{
    /// <summary>
    /// Summary description for Owner.
    /// </summary>
    public class Owner : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Button cmdReleaseOwnership;
        internal System.Windows.Forms.Button cmdAddOwnership;
        private System.Windows.Forms.Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Owner()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cmdReleaseOwnership = new System.Windows.Forms.Button();
            this.cmdAddOwnership = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // cmdReleaseOwnership
            // 
            this.cmdReleaseOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.cmdReleaseOwnership.Location = new System.Drawing.Point(152196);
            this.cmdReleaseOwnership.Name = "cmdReleaseOwnership";
            this.cmdReleaseOwnership.Size = new System.Drawing.Size(12832);
            this.cmdReleaseOwnership.TabIndex = 3;
            this.cmdReleaseOwnership.Text = "Remove Ownership";
            this.cmdReleaseOwnership.Click += new System.EventHandler(this.cmdReleaseOwnership_Click);
            // 
            // cmdAddOwnership
            // 
            this.cmdAddOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.cmdAddOwnership.Location = new System.Drawing.Point(16196);
            this.cmdAddOwnership.Name = "cmdAddOwnership";
            this.cmdAddOwnership.Size = new System.Drawing.Size(12032);
            this.cmdAddOwnership.TabIndex = 2;
            this.cmdAddOwnership.Text = "Set Ownership";
            this.cmdAddOwnership.Click += new System.EventHandler(this.cmdAddOwnership_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(4036);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(21680);
            this.label1.TabIndex = 4;
            this.label1.Text = "To test form ownership, try minimizing this form when the second form is owned. T" +
                "hen try, minimizing it when the second form is not owned.";
            // 
            // Owner
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(292242);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1,
                                                                          this.cmdReleaseOwnership,
                                                                          this.cmdAddOwnership});
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "Owner";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Owner";
            this.Load += new System.EventHandler(this.Owner_Load);
            this.ResumeLayout(false);

        }
        #endregion

        private OwnedForm frmOwned = new OwnedForm();

        private void Owner_Load(object sender, System.EventArgs e)
        {
            this.Show();
            frmOwned.Show();
        }

        private void cmdAddOwnership_Click(object sender, System.EventArgs e)
        {
            this.AddOwnedForm(frmOwned);
            frmOwned.lblState.Text = "I'm Owned";
        }

        private void cmdReleaseOwnership_Click(object sender, System.EventArgs e)
        {
            this.RemoveOwnedForm(frmOwned);
            frmOwned.lblState.Text = "I'm Free!";
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new Owner());
        }
    }
    /// <summary>
    /// Summary description for OwnedForm.
    /// </summary>
    public class OwnedForm : System.Windows.Forms.Form
    {
        public System.Windows.Forms.Label lblState;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public OwnedForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lblState = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblState
            // 
            this.lblState.Location = new System.Drawing.Point(88);
            this.lblState.Name = "lblState";
            this.lblState.Size = new System.Drawing.Size(18456);
            this.lblState.TabIndex = 1;
            // 
            // OwnedForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(514);
            this.ClientSize = new System.Drawing.Size(20878);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblState});
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "OwnedForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Text = "OwnedForm";
            this.ResumeLayout(false);

        }
        #endregion
    }


}


           
       
Related examples in the same category
1.Set MDI parent windowSet MDI parent window
2.Maximized MDI window at startupMaximized MDI window at startup
3.MDI formMDI form
4.MDI RelativesMDI Relatives
5.MDI BasicsMDI Basics
6.MDI and DockMDI and Dock
7.MdiLayout.Cascade MdiLayout.Cascade
8.MdiLayout.TileHorizontal MdiLayout.TileHorizontal
9.MdiLayout.TileVerticalMdiLayout.TileVertical
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.