ICreate.Controls.Bars Send comments on this topic.
CommandButton Class
See Also  Members   Example 
ICreate.Controls.Bars Namespace : CommandButton Class






CommandButton is an enhanced Windows Forms Button control.

Syntax

Visual Basic (Declaration) 
Public Class CommandButton 
   Inherits CommandItem
   Implements IMouseEventProcessor 
Visual Basic (Usage)Copy Code
Dim instance As CommandButton
C# 
public class CommandButton : CommandItem, IMouseEventProcessor  
Delphi 
public class CommandButton = class(CommandItem, IMouseEventProcessor)
JScript 
public class CommandButton extends CommandItem implements IMouseEventProcessor 
Managed Extensions for C++ 
public __gc class CommandButton : public CommandItem, IMouseEventProcessor  
C++/CLI 
public ref class CommandButton : public CommandItem, IMouseEventProcessor  

Example

The example below shows how to programmatically create and add an Ok and Cancel CommandButton to a modal dialog. To run this example create a WinForm application and implement the Form constructor as shown below.
C#Copy Code
using System; 
using System.Drawing; 
using System.Windows.Forms; 
using ICreate.Controls.Bars; 
 
namespace ExamplesCommandButtonCSharp 

    public partial class CommandButtonCreate : Form 
    { 
        public CommandButtonCreate() 
        { 
            InitializeComponent(); 
 
            CommandButton okButton = new CommandButton(); 
            okButton.ButtonStyle = ButtonStyle.Vista; 
            okButton.Text = "Ok"; 
            okButton.TextImageRelation = TextImageRelation.ImageAboveText; 
            okButton.ForeColor = Color.Black; 
            okButton.BackColor = Color.Green; 
            okButton.HotTrackForeColor = Color.Gray; 
            okButton.HotTrackBackColor = Color.LightGreen; 
            okButton.PressedForeColor = Color.Gray; 
            okButton.PressedBackColor = Color.LightGreen; 
            okButton.Image = Bitmap.FromFile(@"Resources\Ok.png"); 
            okButton.AutomaticHeight = true; 
            okButton.Width = 60; 
            okButton.DialogResult = DialogResult.OK; 
            AcceptButton = okButton; 
 
            CommandButton cancelButton = new CommandButton(); 
            cancelButton.Text = "Cancel"; 
            cancelButton.ButtonStyle = ButtonStyle.Vista; 
            cancelButton.Image = Bitmap.FromFile(@"Resources\Cancel.png"); 
            cancelButton.TextImageRelation = TextImageRelation.ImageAboveText; 
            cancelButton.ForeColor = Color.Black; 
            cancelButton.BackColor = Color.Red; 
            cancelButton.HotTrackForeColor = Color.Gray; 
            cancelButton.HotTrackBackColor = Color.Pink; 
            cancelButton.PressedForeColor = Color.Gray; 
            cancelButton.PressedBackColor = Color.Pink; 
            cancelButton.AutomaticHeight = true; 
            cancelButton.Width = 60; 
            cancelButton.DialogResult = DialogResult.Cancel; 
            CancelButton = cancelButton; 
 
            okButton.Left = 10; 
            okButton.Top = ClientRectangle.Height - okButton.Height - 10; 
            this.Controls.Add(okButton); 
 
            cancelButton.Left = 10 + okButton.Width + 10; 
            cancelButton.Top = ClientRectangle.Height - okButton.Height - 10; 
            this.Controls.Add(cancelButton); 
        } 
    } 
}
Visual BasicCopy Code
Imports ICreate.Controls.Bars

Public Class CommandButtonCreate

    Public Sub New()

        InitializeComponent()

        Dim okButton As CommandButton = New CommandButton
        okButton.ButtonStyle = ButtonStyle.Vista
        okButton.Text = "Ok"
        okButton.TextImageRelation = TextImageRelation.ImageAboveText
        okButton.ForeColor = Color.Black
        okButton.BackColor = Color.Green
        okButton.HotTrackForeColor = Color.Gray
        okButton.HotTrackBackColor = Color.LightGreen
        okButton.PressedForeColor = Color.Gray
        okButton.PressedBackColor = Color.LightGreen
        okButton.Image = Bitmap.FromFile("Resources\Ok.png")
        okButton.AutomaticHeight = True
        okButton.Width = 60
        okButton.DialogResult = Windows.Forms.DialogResult.OK
        AcceptButton = okButton

        Dim cancelButton As CommandButton = New CommandButton
        cancelButton.Text = "Cancel"
        cancelButton.ButtonStyle = ButtonStyle.Vista
        cancelButton.Image = Bitmap.FromFile("Resources\Cancel.png")
        cancelButton.TextImageRelation = TextImageRelation.ImageAboveText
        cancelButton.ForeColor = Color.Black
        cancelButton.BackColor = Color.Red
        cancelButton.HotTrackForeColor = Color.Gray
        cancelButton.HotTrackBackColor = Color.Pink
        cancelButton.PressedForeColor = Color.Gray
        cancelButton.PressedBackColor = Color.Pink
        cancelButton.AutomaticHeight = True
        cancelButton.Width = 60
        cancelButton.DialogResult = Windows.Forms.DialogResult.Cancel
        cancelButton = cancelButton

        okButton.Left = 10
        okButton.Top = ClientRectangle.Height - okButton.Height - 10
        Me.Controls.Add(okButton)

        cancelButton.Left = 10 + okButton.Width + 10
        cancelButton.Top = ClientRectangle.Height - okButton.Height - 10
        Me.Controls.Add(cancelButton)

    End Sub
End Class

Remarks

CommandButton is a replacement for the standard WinForm Button control. CommandButton provides a number of additional features not found in the standard Button control. CommandButton can be drawn using different styles namely: Flat, Mac, Modern, Office2007, Outlook, Rounded, Standard and Vista. The ButtonStyle specifies which style is used to render the CommandButton. CommandButton can include Text and an image. The image is specified by setting the Image property or assigning an ImageList to the CommandButton and specifying an ImageIndex or ImageKey. If Animate is true then the image animates to an expanded state when the CommandButton is hot and animates back to its normal size when the CommandButton becomes cold.

The background and text colour of the CommandButton changes depending on its current state. The following colours can be specified for a CommandButton: ForeColor, BackColor, HotTrackForeColor, HotTrackBackColor, HotTrackActiveBackColor, PressedForeColor, PressedBackColor, CheckedForeColor and CheckedBackColor. If Animate is true then the colour transitions occur as a fade effect. If Animate is false then the colour transitions are abrupt.

The CommandButton may have a subordinate button. This sub button can be pressed independently of the main button. A ContextMenuStrip may be assigned to a CommandButton. This menu is displayed when the CommandButton, or sub button if present, is pressed.

A CommandButton can automatically toggle its Checked property if CheckOnClick is true.

A CommandButton can automatically resize or adjust its height depending on the Text and Image. Set AutomaticSize true for the CommandButton to automatically adjust its size. Set AutomaticHeight true for the CommandButton to maintain the correct Height. In this case the Width is freely adjustable. Note that the Text will wrap if required.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            ICreate.Controls.Bars.CommandItem
               ICreate.Controls.Bars.CommandButton

Requirements

Namespace: ICreate.Controls.Bars

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: ICreate.Controls.Bars (in ICreate.Controls.Bars.dll)

See Also