ICreate.Controls.Bars Send comments on this topic.
Click Event
See Also  Example
ICreate.Controls.Bars Namespace > CommandItem Class : Click Event






Occurs when the CommandItem is clicked.

Syntax

Visual Basic (Declaration) 
Public Event Click() As EventHandler
Visual Basic (Usage)Copy Code
Dim instance As CommandItem
Dim handler As EventHandler
 
AddHandler instance.Click, handler
C# 
public event EventHandler Click()
Delphi 
public event Click: EventHandler; 
JScript 
In JScript, you can handle the events defined by another class, but you cannot define your own.
Managed Extensions for C++ 
public: __event EventHandler* Click();
C++/CLI 
public:
event EventHandler^ Click();

Example

The example below shows how to attach to the CommandButton Click and SubClick events, and the CommandLink Click event. To run this example create a WinForm application. Place two CommandButton controls and one CommandLink control onto the Form. For the second CommandButton set the SubButtonPosition property to Bottom. Implement the Form as shown below, compile and run the application.
C#Copy Code
using System; 
using System.Windows.Forms; 
 
namespace ExamplesCSharp 

    public partial class ClickEventsExample : Form 
    { 
        public ClickEventsExample() 
        { 
            InitializeComponent(); 
 
            commandButton1.Click += new EventHandler(commandButton1_Click); 
            commandButton2.Click += new EventHandler(commandButton2_Click); 
            commandButton2.SubClick += new EventHandler(commandButton2_SubClick); 
            commandLink1.Click += new EventHandler(commandLink1_Click); 
        } 
 
        private void commandButton1_Click(object sender, EventArgs e) 
        { 
            MessageBox.Show("CommandButton1 clicked"); 
        } 
 
        private void commandButton2_Click(object sender, EventArgs e) 
        { 
            MessageBox.Show("CommandButton2 main button clicked"); 
        } 
 
        private void commandButton2_SubClick(object sender, EventArgs e) 
        { 
            MessageBox.Show("CommandButton2 sub button clicked"); 
        } 
 
        private void commandLink1_Click(object sender, EventArgs e) 
        { 
            MessageBox.Show("CommandLink1 clicked"); 
        } 
    } 
}
Visual BasicCopy Code
Public Class ClickEventsExample

    Public Sub New()

        InitializeComponent()

        AddHandler CommandButton1.Click, AddressOf commandButton1_Click
        AddHandler CommandButton2.Click, AddressOf commandButton2_Click
        AddHandler CommandButton2.SubClick, AddressOf commandButton2_SubClick
        AddHandler CommandLink1.Click, AddressOf commandLink1_Click

    End Sub


    Private Sub commandButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("CommandButton1 clicked")
    End Sub


    Private Sub commandButton2_Click(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("CommandButton2 main button clicked")
    End Sub


    Private Sub commandButton2_SubClick(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("CommandButton2 sub button clicked")
    End Sub


    Private Sub commandLink1_Click(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("CommandLink1 clicked")
    End Sub

End Class

Remarks

The Click event passes an EventArgs instance to its event handler, so it only indicates that a click has occurred. If the CommandItem is a CommandButton which has a sub button, then the Click event is raised when the main button is clicked. Clicking on the sub button raises the SubClick event.

Pressing the enter key or space bar when the CommandItem has focus is the same as clicking on the CommandItem. Pressing the enter key or space bar while holding down the control key is the same as clicking on the sub button of the CommandItem.

Requirements

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

See Also