Render onto the button : Control « GUI Windows Forms « C# / CSharp Tutorial






Render onto the button
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

public class ButtonRenerer : System.Windows.Forms.Form
{
  private System.ComponentModel.Container components = null;
  private System.Windows.Forms.Button btnRenderedButton;
  private System.Windows.Forms.Button btnRenderToOtherButton;

  public ButtonRenerer()
  {
    InitializeComponent();
  }

  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
  private void InitializeComponent()
  {
    this.btnRenderedButton = new System.Windows.Forms.Button();
    this.btnRenderToOtherButton = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // btnRenderedButton
    // 
    this.btnRenderedButton.Location = new System.Drawing.Point(168, 120);
    this.btnRenderedButton.Name = "btnRenderedButton";
    this.btnRenderedButton.Size = new System.Drawing.Size(112, 136);
    this.btnRenderedButton.TabIndex = 0;
    this.btnRenderedButton.Text = "Click on other button!";
    // 
    // btnRenderToOtherButton
    // 
    this.btnRenderToOtherButton.Location = new System.Drawing.Point(168, 8);
    this.btnRenderToOtherButton.Name = "btnRenderToOtherButton";
    this.btnRenderToOtherButton.Size = new System.Drawing.Size(112, 56);
    this.btnRenderToOtherButton.TabIndex = 1;
    this.btnRenderToOtherButton.Text = "Render to button";
    // 
    // ButtonRenerer
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.btnRenderToOtherButton);
    this.Controls.Add(this.btnRenderedButton);
    this.Name = "ButtonRenerer";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "Basic Paint Form";
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.ButtonRenerer_Paint);
    this.ResumeLayout(false);

  }

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

  private void ButtonRenerer_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics buttonGraphics = Graphics.FromHwnd(btnRenderedButton.Handle);
    
    HatchBrush b = new HatchBrush(HatchStyle.Cross, Color.Purple, Color.Gold);
    
    
    buttonGraphics.FillRectangle(b,  0, 0, 50, btnRenderedButton.Height);

  }
}








23.53.Control
23.53.1.Control: TabIndex, Size and LocationControl: TabIndex, Size and Location
23.53.2.Control Tag PropertyControl Tag Property
23.53.3.Control Size and Location - DynamicControl Size and Location - Dynamic
23.53.4.Control Size and LocationControl Size and Location
23.53.5.Override the DefaultSize property to gain better performance
23.53.6.Create User Control based on Control classCreate User Control based on Control class
23.53.7.Get controls on a form and verify its typeGet controls on a form and verify its type
23.53.8.Set Caption(title) of the formSet Caption(title) of the form
23.53.9.Set form forground colorSet form forground color
23.53.10.Render onto the buttonRender onto the button