extends Button : Button « GUI Windows Forms « C# / CSharp Tutorial






using System;
using System.Drawing;
using System.Windows.Forms;

class MessageButtonDemo: Form
{
    [STAThread]
    public static void Main()
    {
        Application.Run(new MessageButtonDemo());
    }
    public MessageButtonDemo()
    {

        MessageButton msgbtn = new MessageButton();
        msgbtn.Parent = this;
        msgbtn.Text = "Calculate";
        msgbtn.MessageBoxText = "This button is not yet implemented!";
        msgbtn.Location = new Point(50, 50);
        msgbtn.AutoSize = true;
    }
}

class MessageButton: Button
{
    string str;

    public MessageButton()
    {
        Enabled = false;
    }
    public string MessageBoxText
    {
        set
        {
            str = value;
            Enabled = value != null && value.Length > 3;
        }
        get
        {
            return str;
        }
    }
    protected override void OnClick(EventArgs args)
    {
        MessageBox.Show(MessageBoxText, Text);
    }
}








23.8.Button
23.8.1.Add a Button
23.8.2.Handle button messages
23.8.3.Relocate button after pressing button
23.8.4.Add Image in an ImageList to a ButtonAdd Image in an ImageList to a Button
23.8.5.Use delegate to add an event handler to a ButtonUse delegate to add an event handler to a Button
23.8.6.Button mouse eventButton mouse event
23.8.7.Set Label text in a button click eventSet Label text in a button click event
23.8.8.Add action handler to buttonAdd action handler to button
23.8.9.Button Style: image button, standard buttonButton Style: image button, standard button
23.8.10.Button PerformClick MethodButton PerformClick Method
23.8.11.Button Flat StyleButton Flat Style
23.8.12.Calculate Button size based on its TextCalculate Button size based on its Text
23.8.13.Button Background ColorButton Background Color
23.8.14.Button Text AlignmentButton Text Alignment
23.8.15.Button ImageButton Image
23.8.16.Auto Scale Button
23.8.17.extends Button
23.8.18.Device Independent Button