Click event of a Button on Click event of another button in C#

The following code example demonstrates how to call the Click event of a Button on Click event of another button. The following code assumes that two Button and one TextBox controls have been instantiated on a form. On the click of the button1, we will generate the click event of the button2 if the the value of the textbox1 is numeric. Continue reading “Click event of a Button on Click event of another button in C#”

Dock property of control in c#

 
You can set the control borders to docked to its parent control through Dock property. Dock property of any control determines how a control is resized with its parent control.means how a control automatically resized as its parent control is resized. for example if you set the dock property of a control to Left, then it automatically align with the left side of its parent and it will automatically resize as the parent control is resized.

Dock property
Dock Locations

There is one point to need consider here that Anchor and Dock properties are mutually exclusive. Only one can be set at a time and the last one set takes precedence.

Example

The following c# example creates a Panel and sets some of its common properties and then set the Dock property of this to Top.
and then set the Dock property of this to Top.

private void CreatePanelAndSetDock()
{
	Panel Pnl = new Panel();
	Pnl.BackColor = Color.Gray;
	Pnl.Height = 50;
	Pnl.BorderStyle = BorderStyle.Fixed3D;
	this.Controls.Add(Pnl);
	Pnl.Dock = DockStyle.Top;
}

Dock property of control in vb.net

 
You can set the control borders to docked to its parent control through Dock property. Dock property of any control determines how a control is resized with its parent control.means how a control automatically resized as its parent control is resized. for example if you set the dock property of a control to Left, then it automatically align with the left side of its parent and it will automatically resize as the parent control is resized

Dock property
Dock Locations

There is one point to need consider here that Anchor and Dock properties are mutually exclusive. Only one can be set at a time and the last one set takes precedence.

Example

The following example creates a Panel and sets some of its common properties and then set the Dock property of this to Top.
and then set the Dock property of this to Top.

    Private Sub CreatePanelAndSetDock()
        Dim Pnl As New Panel
        Pnl.BackColor = Color.Gray
        Pnl.Height = 50
        Pnl.BorderStyle = BorderStyle.Fixed3D
        Me.Controls.Add(Pnl)
        Pnl.Dock = DockStyle.Top
End Sub