ButtonEditEvents in Windows Forms ButtonEdit

The ButtonEdit events are discussed in the below sections.

ButtonClicked Event

ButtonClicked event is raised whenever ButtonEditChildButton control is clicked. It allows you to get the child button that is clicked.

buttonEdit.ButtonClicked += ButtonEdit_ButtonClicked;
private void ButtonEdit_ButtonClicked(object sender, ButtonClickedEventArgs args)
{
    args.ClickedButton.ButtonAlign = ButtonAlignment.Left;
}
buttonEdit.ButtonClicked += ButtonEdit_ButtonClicked
Private Sub ButtonEdit_ButtonClicked(ByVal sender As Object, ByVal args As ButtonClickedEventArgs)
    args.ClickedButton.ButtonAlign = ButtonAlignment.Left
End Sub

Border Events

The Border3DStyleChanged and BorderSidesChanged events are raised whenever Border3DStyle and BorderSides properties values are changed in ButtonEdit control.

ButtonEdit Properties Description
Border3DStyleChanged Raised when Border3DStyle property of ButtonEdit control is changed.
BorderSidesChanged Raised when BorderSides property of ButtonEdit control is changed.
private void buttonEdit1_Border3DStyleChanged(object sender, EventArgs e)
{
    Console.WriteLine("3D border styles is changed");            
}
private void buttonEdit1_BorderSidesChanged(object sender, EventArgs e)
{
    Console.WriteLine(" Border sides is changed");           
}
Private Sub buttonEdit1_Border3DStyleChanged(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("3D border styles is changed")
End Sub
Private Sub buttonEdit1_BorderSidesChanged(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine(" Border sides is changed")
End Sub

ButtonEditChildButton Events

The below table list the events that are available for the ButtonEditChildButton control.

ButtonEditChildButton Events Description
Click Occurs when the control is clicked. This event calls the ButtonEdit.HandleChildButtonClicked method. Using this method, we can access the corresponding control and customize it.
TextChanged Raised when Text property value is changed. This event calls HandleChildButtonTextChanged method. Using this method, we can access the corresponding control and customize it.
MouseDown Handled when the mouse is over the control and when mouse button is pressed. This event calls HandleChildButtonMouseDown. Using this method, we can access the corresponding control and customize it.
MouseUp Handled when the mouse is over the control and mouse button is released. This event calls HandleChildButtonMouseUp. Using this method, we can access the corresponding control and customize it.
MouseEnter Raised when the mouse pointer enters the control. This event calls HandleChildButtonMouseEnter method. Using this method, we can access the corresponding control and customize it.
MouseLeave Raised when the mouse pointer leaves the control. This event calls HandleChildButtonMouseLeave method. Using this method, we can access the corresponding control and customize it.
MouseHover Raised when the mouse pointer rests the control. This event calls HandleChildButtonMouseHover method. Using this method, we can access the corresponding control and customize it.
BackColorChanged Raised when BackColor property of the ButtonEdit control is changed. This event calls HandleChildButtonBackColorChanged method. Using this method, we can access the corresponding control and customize it.

Click Event

You can display CalendarPopup on ButtonEdit Child button click event. It can be done using the below steps.

  1. Drag and drop TableLayoutPanel and add ButtonEdit control on first row and resize to its fit.
  2. Remove unwanted columns in TableLayoutPanel.
  3. Create an instance of CalendarPopup and MonthCalendarAdv control and add MonthCalendarAdv in CalendarPopup.
  4. Add the CalendarPopup control in second row.
public partial class Form1 : Form
{
    ButtonEditChildButton childButton = new ButtonEditChildButton()
    {
         Size = new Size(22, 22),
         Image = Image.FromFile(@"..\..\Images\Dot.png"),
    };

    CalendarPopup calendarPopup = new CalendarPopup()
    {
        AutoSize = false,
        Visible = false,
        Dock = DockStyle.Fill
    };

    MonthCalendarAdv monthCalendarAdv = new MonthCalendarAdv();
    public Form1()
    {
        InitializeComponent();
           
        childButton.Click += ChildButton_Click;

        calendarPopup.Controls.Add(monthCalendarAdv);
        buttonEdit1.Buttons.Add(childButton);
        tableLayoutPanel1.Controls.Add(calendarPopup, 0, 1);
        monthCalendarAdv.DateSelected += MonthCalendarAdv_DateSelected;
    }
}
Public Partial Class Form1
    Inherits Form

    Private childButton As ButtonEditChildButton = New ButtonEditChildButton() With {
        .Size = New Size(22, 22),
        .Image = Image.FromFile("..\..\Images\Dot.png")
    }
    Private calendarPopup As CalendarPopup = New CalendarPopup() With {
        .AutoSize = False,
        .Visible = False,
        .Dock = DockStyle.Fill
    }
    Private monthCalendarAdv As MonthCalendarAdv = New MonthCalendarAdv()

    Public Sub New()
        InitializeComponent()
        childButton.Click += ChildButton_Click
        calendarPopup.Controls.Add(monthCalendarAdv)
        buttonEdit1.Buttons.Add(childButton)
        tableLayoutPanel1.Controls.Add(calendarPopup, 0, 1)
        monthCalendarAdv.DateSelected += MonthCalendarAdv_DateSelected
    End Sub
End Class
  1. Handle the Click event of buttonEditChildButton1 to display the Calendar as follows.
private void ChildButton_Click(object sender, EventArgs e)
{
    calendarPopup.Visible = true;
}
Private Sub ChildButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    calendarPopup.Visible = True
End Sub
  1. The event DateSelected can also be handled to display the selected date in the textbox of ButtonEdit control.
private void MonthCalendarAdv_DateSelected(object sender, EventArgs e)
{
    buttonEdit1.TextBox.Text = monthCalendarAdv.Value.ToString();
    calendarPopup.Visible = false;
}
Private Sub MonthCalendarAdv_DateSelected(ByVal sender As Object, ByVal e As EventArgs)
    buttonEdit1.TextBox.Text = monthCalendarAdv.Value.ToString()
    calendarPopup.Visible = False
End Sub

MonthCalendar in ButtonEdit

NOTE

Download Demo sample fromGitHub