Button (btn)

Button - Allows the user to run a separate subroutine.

A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.
Set the AcceptButton or CancelButton property of a Form to allow users to click a button by pressing the ENTER or ESC keys even if the button does not have focus.
When you display a form using the ShowDialog method, you can use the DialogResult property of a button to specify the return value of ShowDialog.


You can change the button's appearance. For example, to make it appear flat for a Web look, set the FlatStyle property to FlatStyle.Flat. The FlatStyle property can also be set to FlatStyle.Popup, which appears flat until the mouse pointer passes over the button; then the button takes on the standard Windows button appearance.


If the control that has focus accepts and processes the ENTER key press, the Button does not process it. For example, if a multiline TextBox or another button has focus, that control processes the ENTER key press instead of the accept button.



Examples


Button Conventions

OKmeans save and close
Savemeans save and don't close
Save & Closemeans save and close
Cancelclose without saving changes
Applymeans save and don't close
Closeclose without saving changes


Useful Code

This allows you to change the background colour of the button dynamically using a RGB value.

Me.btnOK.BackColor = System.Drawing.Color.FromArgb(giCOLOUR_RED, giCOLOUR_GREEN, giCOLOUR_BLUE) 

Escape key does not work unless the button is visible

Me.btnCancel.Top = Me.btnCancel.Top + 100 

Calling a Button_Click

btnMyButton_Click(sender, New System.EventArgs()) 

Adding a ToolTip

Drag the tooltip control to the Designer Tray underneath your form.
Once added every control will acquire a "tooltip on tooltip1' property


Properties

AutoEllipsisGets or sets a value indicating whether the ellipsis character (...) appears at the right edge of the control, denoting that the control text extends beyond the specified length of the control. (Inherited from ButtonBase.)
AutoSizeGets or sets a value that indicates whether the control resizes based on its contents. (Inherited from ButtonBase.)
AutoSizeMode Gets or sets the mode by which the Button automatically resizes itself.
BackColorGets or sets the background color of the control. (Inherited from ButtonBase.)
DefaultImeModeGets the default Input Method Editor (IME) mode supported by this control. (Inherited from ButtonBase.)
DefaultSize (Inherited from ButtonBase.)
DialogResultGets or sets a value that is returned to the parent form when the button is clicked.
FlatAppearance Gets the appearance of the border and the colors used to indicate check state and mouse state. (Inherited from ButtonBase.)
FlatStyleGets or sets the flat style appearance of the button control. (Inherited from ButtonBase.)
ImageGets or sets the image that is displayed on a button control. (Inherited from ButtonBase.)
ImageAlignGets or sets the alignment of the image on the button control. (Inherited from ButtonBase.)
ImageIndexGets or sets the image list index value of the image displayed on the button control. (Inherited from ButtonBase.)
ImageKeyGets or sets the key accessor for the image in the ImageList. (Inherited from ButtonBase.)
ImageListGets or sets the ImageList that contains the Image displayed on a button control. (Inherited from ButtonBase.)
ImeModeGets or sets the Input Method Editor (IME) mode supported by this control. This property is not relevant for this class. (Inherited from ButtonBase.)
IsDefaultGets or sets a value indicating whether the button control is the default button. (Inherited from ButtonBase.)
Text(Inherited from ButtonBase.)
TextAlignGets or sets the alignment of the text on the button control. (Inherited from ButtonBase.)
TextImageRelationGets or sets the position of text and image relative to each other. (Inherited from ButtonBase.)
UseCompatibleTextRendering Gets or sets a value that determines whether to use the compatible text rendering engine (GDI+) or not (GDI). (Inherited from ButtonBase.)

Methods

CreateAccessibilityInstance (Inherited from ButtonBase.)
DisposeOverloaded. Releases the resources used by the ButtonBase. (Inherited from ButtonBase.)
GetPreferredSize Retrieves the size of a rectangular area into which a control can be fitted. (Inherited from ButtonBase.)
NotifyDefaultNotifies the Button whether it is the default button so that it can adjust its appearance accordingly.
PerformClickGenerates a Click event for a button.
ToStringOverridden.

Events

AutoSizeChangedOccurs when the value of the AutoSize property changes. (Inherited from ButtonBase.)
DoubleClick Occurs when the user double-clicks the Button control.
MouseDoubleClickOccurs when the user double-clicks the Button control with the mouse.

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext