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






Button.Image

  

using System;
using System.Drawing;
using System.Windows.Forms;
   
class BitmapButtons: Form
{
     int    cxBtn, cyBtn, dxBtn;
     Button btnLarger, btnSmaller;
   
     public static void Main()
     {
          Application.Run(new BitmapButtons());
     }
     public BitmapButtons()
     {
          ResizeRedraw = true;
   
          dxBtn = Font.Height;
          btnLarger = new Button();
          btnLarger.Parent = this;
          btnLarger.Image  = new Bitmap(GetType(), "LargerButton.bmp") ;
   
          cxBtn = btnLarger.Image.Width  + 8;
          cyBtn = btnLarger.Image.Height + 8;
   
          btnLarger.Size   = new Size(cxBtn, cyBtn);
          btnLarger.Click += new EventHandler(ButtonLargerOnClick);
   
          btnSmaller = new Button();
          btnSmaller.Parent = this;
          btnSmaller.Image  = new Bitmap(GetType(), "SmallerButton.bmp");
          btnSmaller.Size   = new Size(cxBtn, cyBtn);
          btnSmaller.Click += new EventHandler(ButtonSmallerOnClick);
   
          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 ButtonLargerOnClick(object obj, EventArgs ea)
     {
          Left   = 50;
          Top    = 50;
          Width  = 50;
          Height = 50;
     }
     void ButtonSmallerOnClick(object obj, EventArgs ea)
     {
          Left   = 200;
          Top    = 200;
          Width  = 20;
          Height = 20;
     }
}

   
    
  








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.Location
9.Button.MouseDown
10.Button.MouseEnter
11.Button.Parent
12.Button.PerformClick()
13.Button.Size
14.Button.Text
15.Button.TextAlign
16.Button.Top