Form.AddOwnedForm : Form « System.Windows.Forms « C# / C Sharp by API






Form.AddOwnedForm

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

public class ChildForm : Form
{
  public System.Windows.Forms.Label lblState;

  public ChildForm()
  {
    InitializeComponent();
  }
  private void InitializeComponent()
  {
    this.lblState = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // lblState
    // 
    this.lblState.Location = new System.Drawing.Point(26, 24);
    this.lblState.Name = "lblState";
    this.lblState.Size = new System.Drawing.Size(184, 56);
    this.lblState.TabIndex = 2;
    // 
    // ChildForm
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(236, 104);
    this.Controls.Add(this.lblState);
    this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "ChildForm";
    this.Text = "ChildForm";
    this.ResumeLayout(false);

  }
  
}

public class ParentForm : Form{
  private System.Windows.Forms.Button cmdReleaseOwnership;
  private System.Windows.Forms.Button cmdAddOwnership;

  public ParentForm()
  {
    InitializeComponent();
    frmOwned.Show();

  }

  private ChildForm frmOwned = new ChildForm();


  private void cmdAddOwnership_Click(object sender, System.EventArgs e)
  {
    this.AddOwnedForm(frmOwned);
    frmOwned.lblState.Text = "Owned. Minimize me to see the difference.";
  }

  private void cmdReleaseOwnership_Click(object sender, System.EventArgs e)
  {
    this.RemoveOwnedForm(frmOwned);
    frmOwned.lblState.Text = "Not owned! Minimize me to see the difference.";
  }
  private void InitializeComponent()
  {
    this.cmdReleaseOwnership = new System.Windows.Forms.Button();
    this.cmdAddOwnership = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // cmdReleaseOwnership
    // 
    this.cmdReleaseOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.cmdReleaseOwnership.Location = new System.Drawing.Point(150, 197);
    this.cmdReleaseOwnership.Name = "cmdReleaseOwnership";
    this.cmdReleaseOwnership.Size = new System.Drawing.Size(128, 32);
    this.cmdReleaseOwnership.TabIndex = 6;
    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(14, 197);
    this.cmdAddOwnership.Name = "cmdAddOwnership";
    this.cmdAddOwnership.Size = new System.Drawing.Size(120, 32);
    this.cmdAddOwnership.TabIndex = 5;
    this.cmdAddOwnership.Text = "Set Ownership";
    this.cmdAddOwnership.Click += new System.EventHandler(this.cmdAddOwnership_Click);
    // 
    // ParentForm
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.cmdReleaseOwnership);
    this.Controls.Add(this.cmdAddOwnership);
    this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "ParentForm";
    this.Text = "Owner";
//    this.Load += new System.EventHandler(this.ParentForm_Load);
    this.ResumeLayout(false);

  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new ParentForm());
  }

}

   
    
    
  








Related examples in the same category

1.new Form()
2.extends Form
3.Form.AcceptButton
4.Form.ActiveForm.Location
5.Form.Activated
6.Form.AutoScaleBaseSize
7.Form.AutoScroll
8.Form.AutoScrollMinSize
9.Form.BackColor
10.Form.CancelButton
11.Form.CenterToScreen()
12.Form.ClientRectangle
13.Form.ClientSize
14.Form.Closed
15.Form.Closing
16.Form.ContextMenu
17.Form.ControlBox
18.Form.Controls
19.Form.Cursor
20.Form.DesktopBounds
21.Form.DialogResult
22.Form.DisplayRectangle
23.Form.Dispose
24.Form.FormBorderStyle
25.Form.ForeColor
26.Form.GotFocus
27.Form.Height
28.Form.Hide()
29.Form.Invalidate
30.Form.IsMdiContainer
31.Form.KeyPress
32.Form.KeyPreview
33.Form.KeyUp
34.Form.Load
35.Form.Location
36.Form.MaximizeBox
37.Form.MaximumSize
38.Form.MdiParent
39.Form.MenuComplete
40.Form.Menu
41.Form.MinimizeBox
42.Form.MinimumSize
43.Form.MouseDown
44.Form.MouseLeave(All other events)
45.Form.MouseUp
46.Form.OnDragDrop
47.Form.OnDragOver
48.Form.OnInputLanguageChanged
49.Form.OnKeyDown
50.Form.OnKeyPress
51.Form.OnMouseEnter
52.Form.OnMouseHover
53.Form.OnMouseLeave
54.Form.OnMouseMove
55.Form.OnMouseWheel
56.Form.OnPaint(PaintEventArgs e)
57.Form.OnResize
58.Form.Opacity
59.Form.Paint
60.Form.Region
61.Form.Resize
62.Form.ResizeRedraw
63.Form.SetStyle
64.Form.ShowInTaskbar
65.Form.Size
66.Form.Show
67.Form.StartPosition
68.Form.SuspendLayout
69.Form.Text
70.Form.Top
71.Form.TransparencyKey
72.Form.Visible
73.Form.Width
74.Form.WindowState