Button.Parent : Button « System.Windows.Forms « C# / C Sharp by API






Button.Parent

  
using System;
using System.Drawing;
using System.Windows.Forms;
   
class TwoButtons: Form
{
     readonly Button btnLarger, btnSmaller;
     readonly int    cxBtn, cyBtn, dxBtn;
   
     public static void Main()
     {
          Application.Run(new TwoButtons());
     }
     public TwoButtons()
     {
          ResizeRedraw = true;
   
          cxBtn = 200;
          cyBtn = 100;
          dxBtn = 12;
   
          btnLarger = new Button();
          btnLarger.Parent = this;
          btnLarger.Text   = "&Larger";
          btnLarger.Size   = new Size(cxBtn, cyBtn);
          btnLarger.Click += new EventHandler(ButtonOnClick);
   
          btnSmaller = new Button();
          btnSmaller.Parent = this;
          btnSmaller.Text   = "&Smaller";
          btnSmaller.Size   = new Size(cxBtn, cyBtn);
          btnSmaller.Click += new EventHandler(ButtonOnClick);
   
          OnResize(EventArgs.Empty);
     }
     protected override void OnResize(EventArgs ea)
     {
          base.OnResize(ea);
   
          btnLarger.Location =
                         new Point(ClientSize.Width / 2 - cxBtn - dxBtn / 2,
                                  (ClientSize.Height - cyBtn) / 2);
          btnSmaller.Location =
                         new Point(ClientSize.Width / 2 + dxBtn / 2,
                                  (ClientSize.Height - cyBtn) / 2);
     }
     void ButtonOnClick(object obj, EventArgs ea)
     {
          Button btn = (Button) obj;
   
          if (btn == btnLarger)
          {
               Left   -= (int)(0.1 * Width);
               Top    -= (int)(0.1 * Height);
               Width  += (int)(0.1 * Width);
               Height += (int)(0.1 * Height);
          }
          else
          {
               Left   += (int)(Width  / 22f);
               Top    += (int)(Height / 22f);
               Width  -= (int)(Width  / 11f);
               Height -= (int)(Height / 11f);
          }
     }
}

   
    
  








Related examples in the same category

1.new Button()
2.Button.Anchor
3.Button.Click
4.Button.DialogResult
5.Button.Dock
6.Button.FlatStyle
7.Button.Font
8.Button.Image
9.Button.Location
10.Button.MouseDown
11.Button.MouseEnter
12.Button.PerformClick()
13.Button.Size
14.Button.Text
15.Button.TextAlign
16.Button.Top