C# control programming detailed form (Form)

Abstract: Based on my own development experience, explain the usage of the form in detail from the properties and events of the form.

Programming language: C#

Programming environment: Visual Studio 2019

Table of contents

Detailed Form Properties

layout

window style

design

Exterior

Behavior

miscellaneous

 Detailed Form Events

summary

each message


Detailed Form Properties

layout

  • AutoScroll: bool type, indicating whether to display scroll bars when the content of the control is larger than its visible area, initially false. (Note: The scroll bar is only displayed when the content exceeds the visible area, instead of showing the scroll bar all the time)
  • AutoSize: bool type, indicating whether the size of the control is adaptive to its content, initially false.
  • Location: Point type, which defines the coordinates of the upper left corner of the control relative to the upper left corner of its container, initially (0, 0). (If created by toolbox dragging, the initial coordinates are the upper left corner of the placed control)
  • MaximumSize: Size type, which defines the maximum size that the form can be adjusted to, and is initially (0, 0). (Note: At the beginning, it is equivalent to not working, and can be enlarged at will)
  • MinimumSize: Size type, which defines the minimum size that the form can be adjusted to, and is initially (0, 0).
  • Size: Size type, which defines the size (width, height) of the control.
  • StartPosition: FormStartPosition enumeration type, which defines the starting position of the form. The enumeration values ​​include Manual (manual), CenterSreen (center of the screen), WindowsDefaultLocation (default position, upper left), WindowsDefaultBounds (default position and boundary), CenterParent (parent window body center), initially WindowsDefaultLocation. (Note: If you want to write code to modify the start position of the form, you need to set this property to Manual; if this property is set to WindowsDefaultBounds, the form size remains the given value and cannot be modified)
  • WindowState: FormWindowState enumeration type, which defines the initial state of the form display. The enumeration values ​​are Normal (normal display), Minimizied (minimized display), Maximized (maximized display), and the initial is Normal.

window style

  • ControlBox: bool type, indicating whether there are system menu buttons (minimize, maximize, fork) and icons in the title bar of the form, initially true.
  • HelpButton: bool type, indicating whether there is a help button in the title bar of the form, initially false. (Note: Only when there is no minimize button and maximize button, this property is set to true is valid, and the help button is displayed next to the cross)
  • Icon: Icon type, which defines the icons of the form title bar and taskbar, initially the system icon, which can be modified by importing the .ico icon file.
  • MaximizeBox: bool type, indicating whether there is a maximize button in the title bar of the form.
  • MinimizeBox: bool type, indicating whether there is a minimize button in the title bar of the form.
  • Opacity: double type, defines the opacity percentage of the form, the initial value is 100%, that is, it is completely opaque.
  • ShowIcon: bool type, indicating whether the window icon is displayed on the title bar, initially ture.
  • ShowInTaskbar: bool type, indicating whether the form appears in the taskbar, initially ture.
  • SizeGripSize: SizeGripSize enumeration type, which defines the mode of displaying the resizing handle in the lower right corner of the form. The enumeration values ​​are Auto (automatic), Hide (hidden), Show (display), and the initial value is Auto.

  • TopMost: bool type, indicating whether the form is always displayed on top of all forms, initially false.
  • TransparencyKey: Color type, which defines the transparent color drawn on the form and is initially empty.

design

  • Name: string type, defines the member variable name of the form, initially "Form1".
  • Locked: bool type, indicating whether to lock the size of the form at design time, initially false. (Note: Setting this to true will make it impossible to drag to set the size of the form, but you can still modify the size of the form by writing code)

Exterior

  • BackColor: Color type, defines the background color of the form, initially the system color Control.
  • BackgroundImage: Image type, defines the background image of the form, initially empty.
  • BackgroundImageLayout: ImageLayout enumeration type, which defines the background image layout of the form. The enumeration values ​​include None (left display), Tile (repeated display), Center (centered display), Stretch (stretched to fill the display), Zoom ( Scaled to display), the initial is Tile. (Note: If the RightToLeft property is Yes, then None means display on the right)
  • Cursor: Cursor type, define the cursor displayed when the mouse moves to the form, the initial is Default.
  • Font: Font type, define the font and font size of the form title, the initial is Arial, 9pt.
  • ForeColor: Color type, defines the color of the form title, initially the system color ControlText.
  • FormBorderStyle: FormBorderStyle enumeration type, defines the appearance of the border and title bar of the form, initially Sizable. (Note: If this property is adjusted to the property starting with Fixed, then the form size will not be modified by dragging the mouse after running)
  • RightToLeft: RightToLeft enumeration type, which defines whether the form is drawn from right to left. The enumeration values ​​include Yes (draw from right to left), No (draw from left to right), Inherit (inherit the current, usually from left to right) drawing), the initial value is No.
  • RightToLeftLayout: bool type, indicating whether the window layout is from right to left, initially false. (Note: This property only works when the RightToLeft property is set to Yes)
  • Text: string type, defines the title text of the form, initially "Form1".

Behavior

  • ContextMenuStrip: Define the shortcut menu displayed when the user right-clicks the form, initially empty. (Note: To create this menu, you need to write code to create or drag to create a ContextMenuStrip and then select here, you cannot create it directly in the property box, see my other article for details) ContextMenuStrip of C#Windows Form Design (right click Menu) usage_C# is actually not difficult blog - CSDN blog
  • Enabled: bool type, indicating whether to enable the form, initially true. (Note: If this property is set to false, all controls in the form will be grayed out and unavailable)

miscellaneous

  • KeyPreview: bool type, indicating whether the window receives keyboard events, initially false. (Note: If this property is true, the form will receive keyboard events (including KeyPress, KeyDown, KeyUp events), if it is false, the selected controls in the form will receive keyboard events)

 Detailed Form Events

  • Load: Load the form event, which occurs when the form is loaded, and is the default double-click event of the form. (Note: This event is called after it is created and before it is displayed. Double-click the form to directly register the event and automatically go to the method body of the event)
  • Shown: Form display event, which occurs when the form is displayed for the first time. (Note: This event is called after display, that is, occurs after Show() or ShowDialog())
  • FormClosed: Form has been closed event, the form has been closed to occur.
  • FormClosing: The form is closing (before closing) event, the form is closing (before closing) occurs. (Note: The FormClosing event can prevent the form from closing, but FormClosed cannot)

summary

        Form is a widely used control that must be used in C# control programming. First of all, you should learn and master its use, and then you can use the control in the form to be handy. The editor lists the usage of some attributes and events that I have used, and there are many other attributes and events that need to be further studied and shared with you.

each message

        Sharpening a knife does not cut firewood by mistake.

Guess you like

Origin blog.csdn.net/lucgh/article/details/130093820