Introduction to C # Form controls ListBox

Source: Internet
Author: User

ListBox Control
The ListBox control is also called a list box, which displays a list of items for the user to select. In the list box, the user
You can select one item at a time, or you can select multiple items.
1. Common Properties:
(1) Items property: Used to hold list items in a list box,
is a collection. With this property, you can add list items,
Removes list items and gets the number of list items.
(2) Multicolumn property: Used to get or set a
Value that indicates whether a ListBox supports multiple columns. Value
True indicates support for multiple columns, false when not supported
multiple columns. When using multi-column mode, you can make the control display
Show more visible items.
(3) ColumnWidth property: Used to get or set multiple
The width of the column in the column ListBox control.
(4) SelectionMode property: Used to get or set the method that selects a list item in a ListBox control. When the SelectionMode property is set
When set to selectionmode.multiextended, press the SHIFT key while you click the mouse or press the SHIFT key and one of the arrow keys (top
Arrow keys, DOWN ARROW keys, LEFT ARROW keys, and RIGHT ARROW keys), the selection is expanded from the previous selection to the current item. Press the Ctrl key while
Clicking the mouse selects or revokes an item in the select list, and when the property is set to SelectionMode.MultiSimple, the mouse click or press the SPACEBAR selects or revokes an item in the select list, and the default value for this property is Selectionmode.one, and only one item is selected.
(5) SelectedIndex property: Used to get or set the zero-based index of the currently selected item in the ListBox control. If you do not select any
Entry, the return value is 1. For a ListBox control that can select only one item, use this property to determine the index of the selected item in the listbox. Such as
The SelectionMode property of the ListBox control is set to SelectionMode.MultiSimple or selectionmode.multiextended,
and select more than one item in the list, the selectedindices is applied to get the index of the selected item.
(6) SelectedIndices. This property is used to get a collection that contains the zero-based cable for all selected items in the ListBox control
Cited.
(7) SelectedItem property: Gets or sets the currently selected item in the listbox.
(8) SelectedItems property: Gets the collection of selected items in the ListBox control, typically in the SelectionMode property value of the ListBox control
Used when set to SelectionMode.MultiSimple or selectionmode.multiextended (which indicates a multiple-selection listbox).
(9) Sorted property: Gets or sets a value that indicates whether list items in a ListBox control are sorted alphabetically. If the list
Items are sorted alphabetically, the property value is true, and the property value is False if the list item is not sorted alphabetically. The default value is False. In the row
When you add items to a ListBox control, the items are moved to the appropriate location in the sorted list.
Text property: This property is used to get or search the text of the currently selected item in the ListBox control. When you set this property value to a string
Value, the ListBox control searches within the list for the item that matches the specified text and selects the item. If you select one or more items in the list, the
property returns the text of the first selected item.
(one) Itemscount property: This property is used to return the number of list items.
2. Common methods:
(1) FindString method: Used to find the first item in a list item that starts with the specified string, there are two invocation formats.
[Format 1]:
The ListBox object. FindString (s);
[function]: Finds the string s in the list box specified by the ListBox object, returns the zero-based index of the item if found;
Does not match, the listbox.nomatches is returned.
[Format 2]:
The ListBox object. FindString (S,n);
[function]: Finds the string s in the list box specified by the ListBox object, finds the starting item n+1, that is, N is the first item to start looking for.
Index. Returns the zero-based index of the item if found, or listbox.nomatches if no match is found.
Note: The FindString method is only a word part match, that is, the string to be found at the beginning of the list item is considered to be a match, if you want to
Exact match, that is, only if the list item is exactly the same as the lookup string, you can use the FindStringExact method to call the format
and the function and findstring basically consistent.
(2) SetSelected method: Used to select an item or cancel the selection of an item, call format and function as follows.
[Format]:
The ListBox object. setselected (n,l);
[function]: If the value of parameter L is true, the list item indexed as n is selected in the list box specified by the ListBox object, if the parameter L
The value is false, and the list item with index n is not selected.
(3) Items.Add method: Used to add a list item to the list box, call the format and function as follows.
[Format]:
The ListBox object. Items.Add (s);
[function]: Adds the parameter s to the list item in the list box specified by the ListBox object.
(4) Items.insert method: Use to insert a list item in the specified position in the list box, calling the format and function as follows.
[Format]:
The ListBox object. Items.insert (N,s);
[function]: parameter n represents the position index of the item to be inserted, the parameter S represents the item to be inserted, and its function is to insert S into the "ListBox object"
Specifies the position at which the index of the list box is n.

(5) Items.remove method: Used to remove a list item from the list box, the calling format and function are as follows.
[Format]:
The ListBox object. Items.remove (k);
[function]: Removes the list item s from the list box specified by the ListBox object.
(6) Items.clear method: Used to clear all items in the list box. Its invocation format is as follows:
The ListBox object. Items.clear ();
The method has no parameters.
(7) BeginUpdate method and EndUpdate method: Both methods have no parameters, and the calling format is as follows:
The ListBox object. beginupdate ();
The ListBox object. endupdate ();
The purpose of these two methods is to ensure that the list box is not redrawn when a list item is added to the list box using the Items.Add method. The list box is added to the
Add Item, call the BeginUpdate method to prevent each time the item is added to the list box
Draws a ListBox control. After you complete the task of adding items to the list box, call the EndUpdate method to redraw the ListBox control.
When you add a large number of list items to a list box, adding items using this method prevents flickering when the ListBox is drawn. One example
The subroutine is as follows:
Publicvoidaddtomylistbox ()
{listbox1.beginupdate ();
for (intx=1;x<5000;x++)
{
LISTBOX1.ITEMS.ADD ("Item" +x.tostring ());
}
Listbox1.endupdate ();
}
ListBox control Common events have the click and selectedindexchanged,selectedindexchanged events in the list box to change the selected item
Occurs.
11. ComboBox Control
ComboBox control is also called a combo box, by default, the combo box is divided into two parts: the top is a
text box that allows you to enter text, and the list box below displays the list item. You can think of a ComboBox as a combination of a text box and a list box,
The functionality of the text box and list box is basically the same. A combo box cannot be selected more than a list box, and it has no SelectionMode property. But combo box
There is a property named DropDownStyle, which is used to set or get the style of the combo box, the various styles of the combo box, the combo box on the left to enter text through the text box, the middle combo box cannot enter text,
Only list items can be selected.
12. CheckedListBox Control
The CheckedListBox control, also known as a check list box, extends the ListBox control, which is almost
Can complete all tasks that a list box can accomplish, and can also display a duplicate next to a list item
Select the tag. The other difference between the two controls is that the Check list box only supports Drawmode.normal, and the Check list box can have only one item selected or none selected. One thing to note here: The selected item refers to the
The highlighted item on the form, the selected item refers to the item that is selected by the left check box. The Check list box is shown in style 9-23.
In addition to having all the properties of a list box, it has the following properties.
(1) CheckOnClick property: Gets or sets a value that indicates when an item is selected timed
Whether the check box on the left should be toggled. True if the check mark is toggled immediately;
otherwise, false. The default value is False.
(2) CheckedItems property: This property is a collection of selected items in a check list box that represents only
In CheckState. The checked or checkstate.indeterminate state of those items. The Set
The indexes in close are sorted in ascending order.
(3) Checkedindices Property: This property represents the selected item (in the selected or intermediate
The set of indexes for those items that are in the state.
Use of the PictureBox control
13. Use of PictureBox controls
PictureBox controls, also known as Picture frames, are commonly used in graphic design and image processing applications where image file formats can be loaded in the control.
There are: Bitmap files (. BMP), Icon file (. ICO), metafile (. wmf),. JPEG and. GIF files. The control is only described under the
Common Properties and events.
1. Common Properties:
(1) Image property: Used to set the image that the control will display. There are three ways to load images in a file into a picture frame.
When you click the Image property at design time, and then the "..." button appears, clicking the button will appear with an open dialog box in the dialog box
Click the OK button when you find the appropriate drawing file in the Produces an instance of the bitmap class and assigns a value to the Image property. The form is as follows:
Bitmapp=newbitmap (image file name);
PictureBox object name. image=p;
Load directly from a file by using the Image.FromFile method. The form is as follows:
PictureBox object name. image=image.fromfile (image file name);
(2) SizeMode property: Used to determine the display mode of the image. There are four cases of value, and the value and meaning are shown in table 9-11. Various models
The image shown in style 9-24 below.

14. Timer Control
The timer control, also known as a Timer control or a timer control, is the icon in the Toolbox, and the main function of the control is to follow a certain
The interval periodically triggers an event named Tick, so that in the code of the event you can place something that needs to be repeated every few times
The execution of the program segment. When the program is running, the timer control is not visible
Of
1. Common Properties:
(1) Enabled property: Used to set whether the timer is running. When the value is true, the timer is running and the value is false when timing
The device is not running.
(2) Interval property: The time interval, in milliseconds, that is used to set the timer two tick events to occur. If its value is set to 500,
A tick event will occur every 0.5 seconds.
2. Common methods:
(1) Start method: Used to start the timer. The general format of the call is as follows:
The Timer control name. Start ();
The method has no parameters.
(2) Stop method: Used to stop the timer. The general format of the call is as follows:
The timer control name. Stop ();
The method has no parameters.
3. Common events:
The event that the definition control responds to is only tick, and is triggered once every interval time.
15. ProgressBar Controls and TrackBar controls
1. ProgressBar controls
The ProgressBar control, also known as a progress bar control, has an icon in the toolbar that displays the appropriate length in the horizontal bar
Rectangle to indicate the progress of the process. When the process is executed, the progress bar fills from left to right in the horizontal bar with the system highlight color. Into
When the process is complete, the progress bar is filled. When a process runs for a long time, if there is no visual cue, the user may think that the application does not sound
Should, by using the progress bar in your application, you can tell the user that the application is performing lengthy tasks and that the application is still responding.
The common properties of the ProgressBar control are as follows.
(1) Maximum property: used to set or return the maximum value that the progress bar can display, the default value is 100.
(2) Minimum property: Used to set or return the minimum value that the progress bar can display, the default value is 0.
(3) Value property: Used to set or return the current position of the progress bar.
(4) Step property: Used to set or return a value that determines the value increment of the Value property each time the PerformStep method is called.
Amplitude. For example, if you are copying a set of files, you can set the value of the Step property to 1 and set the value of the Maximum property to duplicate
The total number of files made. When you copy each file, you can call the PerformStep method to increase the progress bar by the value of the Step property.
The common methods for ProgressBar controls are as follows.
(1) Increment method: Used to increase the value of the progress bar by the specified number, the general format of the call is as follows:
ProgressBar object. Increment (n);
Its function is to increase the value of the progress bar object specified by the "ProgressBar object" N,n to an integer. After calling the method, if
Value property is greater than maximum property, Value property is maximum value, if the Value property is less than minimum property

Value, the Value property is the minimum value.
(2) PerformStep method: Used to increase the value of the progress bar by the value of the Step property, the general format of the call is as follows:
ProgressBar object. PerformStep ();
The method has no parameters. For example, the following program segment is a method of using a progress bar that shows the progress of copying multiple files.
Privatevoidcopywithprogress (String[]filenames)
{pbar1.visible=true;
Pbar1.minimum=1;
Pbar1.maximum=filenames. Length;
pbar1.value=1;
Pbar1.step=1;
For (Intx=1;x<=filenames. length;x++)
{if (CopyFile (filenames[x-1]) ==true)
{
Pbar1.performstep ();
}
}
}
ProgressBar controls can respond to many events, but are rarely used.
2. TrackBar controls
The TrackBar control is also known as the slider control, the track bar control, and its icon in the Toolbox is "". This control is primarily used to
Browse in a large amount of information, or use it to visually adjust the number settings. The TrackBar control has two parts: a thumbnail (also known as a slider)
and tick marks. A thumbnail is a part that can be adjusted, and its position corresponds to the Value property. Tick marks are visual points separated by regular intervals.
The display symbol. The track bar control can be moved in the specified increments and can be arranged horizontally or vertically.
The common properties of the TrackBar control are as follows.
(1) Maximum property: Used to get or set the upper limit of the range that the TrackBar control can represent, which is the maximum value.
(2) Minimum property: Used to get or set the lower limit of the range that the TrackBar control can represent, which is the minimum value.
(3) Orientation property: Used to get or set a value that indicates whether the track bar is horizontally or vertically
Straight direction.
(4) LargeChange property: Used to get or set a value that indicates whether the slider should be added to the Value property when it moves long distances or
The value to subtract.
(5) SmallChange property: Used to get or set a value that increases or decreases the Value property when the slider moves short distances.
(6) Value property: The value used to get or set the current position of the slider on the track bar control.
(7) Tickfrequency property: Used to get or set a value that specifies the increment between the ticks drawn on the control.
(8) Tickstyle property: Used to get or set a value that indicates how the tick marks on the track bar are displayed. The common event for the TrackBar control is valuechanged, which occurs when the value of the TrackBar control changes.
16. Use of HScrollBar controls and VScrollBar controls
scroll bars (ScrollBar) are controls that are in most Windows applications and are the Windows interface
A common element, usually divided into horizontal scrollbars (HscrollBar) and vertical scroll bars (vscrollbar). HScrollBar
The icon in the Toolbox is that the VScrollBar control icon in the Toolbox is. These two
Controls are primarily used to scroll horizontally or vertically in an application or control to facilitate the use of longer lists or large amounts of information
Transfer.
1. Common Properties:
(1) Minimum and maximum properties: the same Name property as the TrackBar control is basically the same.
(2) Value property: Used to set or return the position of the slider in the scroll bar, with a default value of 0. When the slider
When the position value is the minimum value, the slider moves to the leftmost position of the horizontal scroll bar, or to the top position of the vertical scroll bar.
When the position value of the slider is the maximum value, the slider moves to the far right of the horizontal scroll bar or to the bottom position of the vertical scroll bar.
(3) SmallChange and LargeChange properties: These two properties are mainly used to adjust the distance that the slider moves. Its
The SmallChange property is used to control the value that the slider scrolls when the mouse clicks the arrows on either side of the scroll bar, that is, the values property
The value to increase or decrease. The LargeChange property controls the value that the slider scrolls when you click the scroll bar directly with the mouse. When
When the user presses the PageUp key or the PageDown key or clicks the scroll bar track on either side of the slider, the Value property
Increase or decrease by the value set in the LargeChange property.
2. Common events:
(1) Scroll event: This event occurs after the user moves the slider through the mouse or keyboard.
(2) ValueChanged event: This event occurs when the value of the scroll bar control changes.
Scroll bars are used in a way that is basically consistent with trackbar controls, which are not mentioned here. dialog box class controls
17. OpenFileDialog Control
The OpenFileDialog control, also known as the Open File dialog box, is used to pop up the standard "open file" in Windows
dialog box. The icon for the control in the Toolbox is.
The common properties of the OpenFileDialog control are as follows.
(1) Title property: Used to get or set the caption of the dialog box, the default value is an empty string (""). If the caption is an empty string, the system will
Use the default title: Open.
(2) Filter property: Used to get or set the current file name filter string, which determines the "Save As File Type" dialog box
Or the selection that appears in the File type box. For each filter option, the filter string contains a filter description, a vertical line (|)
and filter mode. Strings for different filter options are separated by vertical lines, for example: "Text file (*. *.txt) |*.txt| All Files (*. *) *. *".
You can also add multiple filter patterns to a filter by separating the various file types with semicolons, for example: "Image file
(*. bmp;*. jpg;*. GIF) |*. bmp;*. JPG; *. Gif| All Files (*. *) |*.* ".
(3) FilterIndex property: Used to get or set the index of the currently selected filter in the File dialog box. The index of the first filter is 1,
The default value is 1.
(4) FileName property: Used to get a string of the file name selected in the Open File dialog box. The file name contains both the path and the package
With extension. If the file is not selected, the property returns an empty string ("").
(5) InitialDirectory property: Used to get or set the initial directory displayed by the file dialog box, the default value is an empty string ("").

(6) ShowReadOnly property: Used to get or set a value that indicates whether the dialog box contains a read-only check box. If the dialog box package
Contains a read-only check box, the property value is true, otherwise the property value is false. The default value is False.
(7) Readonlychecked property: Used to get or set a value that indicates whether the read-only check box is selected. If the read-only duplicate is selected
box, the property value is true, and conversely, the property value is false. The default value is False.
(8) MultiSelect property: Used to get or set a value that indicates whether the dialog box allows multiple files to be selected. If the dialog box allows
If multiple files are selected at the same time, the property value is true, and conversely, the property value is false. The default value is False.
(9) Filenames property: Used to get the file name of all selected files in the dialog box. Each filename contains both a file path and a text
extension. If the file is not selected, the method returns an empty array.
Restoredirectory property: Used to get or set a value that indicates whether the dialog box restores the current directory before it is closed. Assume
When a user changes a directory while searching for a file, and the property value is True, the dialog box restores the current directory to its original value, if
False if the property value is not reverted to the initial value. The default value is False. There are two common methods for OpenFileDialog controls: OpenFile
And the ShowDialog method, this section describes only the ShowDialog method, which is used to display a common dialog box whose general invocation form is
Under
The name of the common dialog box object. ShowDialog ();
When the common dialog box is run, the return value is DialogResult.OK if you click the OK button in the dialog box;
DialogResult.Cancel. Other dialog box controls have ShowDialog methods that are not repeated later.
18. SaveFileDialog Control
The SaveFileDialog control, also known as the Save File dialog box, is used to pop up the standard Save File dialog box in Windows. The control
The icon in the Toolbox is.
The SaveFileDialog control also has FileName, Filter, FilterIndex, InitialDirectory, Title, and other properties that function
is basically the same as the OpenFileDialog dialog box control, which is not mentioned here.
Note that the above two dialogs only return the name of the file to be opened or saved, and do not actually provide the ability to open or save the file.
The sequencer must write its own file to open or save the program, in order to truly implement the file opening and saving functions.
19. FontDialog Control
The FontDialog control, also known as the Font dialog box, is used primarily to pop up the standard Font dialog box in Windows. The control in the Toolbox.
Icon is. The function of the Font dialog box is to display a list of fonts currently installed in the system for the user to select. Below
Describes the main properties of the Font dialog box.
(1) Font property: This property is the most important property of the Font dialog box, which allows you to set or get font information.
(2) Color attribute: Used to set or get the colors of a character.
(3) MaxSize property: Used to get or set the maximum number of points a user can select.
(4) MinSize property: Used to get or set the minimum number of points a user can select. 192visualc#. NET Application Tutorials
(5) Showcolor property: Used to get or set a value that indicates whether the dialog box displays a color selection box. If the dialog box displays
Color selection box, the property value is true, and conversely, the property value is false. The default value is False.
(6) Showeffects property: Used to get or set a value indicating whether the dialog box contains the Allow user to specify strikethrough, underline
and the text color options for the control. If the dialog box contains controls that set strikethrough, underline, and text color options, the property value is true, the inverse
, the property value is false. The default value is true.
20. ColorDialog Control
The ColorDialog control, also known as a color dialog box, is used primarily to pop up the standard color dialog box in Windows. The control is in the Toolbox
The icon for the. The function of the Color dialog box is for the user to select a color and record the color value selected by the user using the color attribute. The main properties of the Color dialog box are described below.
(1) Allowfullopen property: Used to get or set a value that indicates whether the user can use the dialog box to define a custom color.
If the user is allowed to customize the color, the property value is true, otherwise the property value is false. The default value is true.
(2) Fullopen property: Used to get or set a value that indicates whether the control used to create a custom color when the dialog box opens
Visible. A value of true is visible, and a value of false is not visible.
(3) Anycolor property: Used to get or set a value that indicates whether the dialog box displays all the colors available in the base color set.
A value of true displays all colors, otherwise all colors are not displayed.
(4) Color property: Used to get or set the color selected by the user.
21. PrintDialog Controls and PrintDocument controls
The icon for the PrintDialog control in the Toolbox is that the icon for the PrintDocument control in the Toolbox is
。 Use the PrintDialog control to display the Windows Standard Print dialog box, where users can
To select a printer, select the page to print, and the range of pages. Note that this dialog box is not responsible for specific print tasks, and you want to
You must use the PrintDocument control to control the print content in your application. For more information about how to use these two controls, readers can refer to the
Information or visualc# Help files.
6. User Customization dialog box
In addition to using the standard dialog box that comes with Windows, users can define their own form as a dialog box. Use the custom pair
There are several key points to the dialog box.
(1) Set the FormBorderStyle property value of the form to FixedDialog.
(2) Add controls to the form as needed.
(3) Use the form's ShowDialog method to display the form, which displays the dialog box.
22. User Customize dialog box
In addition to using the standard dialog box that comes with Windows, users can define their own form as a dialog box. Use the custom pair
There are several key points to the dialog box.
(1) Set the FormBorderStyle property value of the form to FixedDialog.
(2) Add controls to the form as needed.
(3) Use the form's ShowDialog method to display the form, which displays the dialog box.
23. Menu control
The Windows menu system is one of the important components of the graphical user interface (GUI), and the use of MainMenu controls in visualc# can be
Easy to implement the Windows menu, the MainMenu control icon in the Toolbox is.
1. Structure of the Menu
Figure 10-9 and Figure 10-10 are typical menu structures. A single command that has text is called a menu item, and the top-level menu item is arranged horizontally, click
A menu item that pops up is called a menu or submenu that contains several menu items, which are actually a pair of MenuItem classes.
Like. The menu item is dimmed, indicating that the menu item is currently disabled. Some menu items have underlined text in the ToolTip
The letter, called the hotkey (or access key), if the top-level menu, you can press "ALT + Hotkey" To open the menu, if a child
menu, pressing the hotkey directly after opening the submenu executes the corresponding menu command. Some menu items have a button behind them
Or a combination of keys, called shortcut keys, press the shortcut key without opening the menu, the corresponding command will be executed. In Figure 10-9, the "Save File"
The menu item is displayed in bold, and the menu item is called the default item. There is a gray line between "Save as" and "exit" in Figure 10-9, which
A line is called a separator line or separator character. In Figure 10-10, the menu item "white Background" is preceded by a "√" number, called a checkmark, and the menu item plus a checkmark indicates that the feature represented by the MenuBar is currently working.

2. Common Properties for menu items
(1) Text property: Used to get or set a value that indicates the menu item title. When you use the Text property to specify a caption for a menu item
, you can also specify a hotkey (access key, the underlined letter) by adding a "&" to the character. For example, to add the "File"
"F" is specified as an access key, the title of the menu item should be specified as "&file".
(2) Checked property: Used to get or set a value that indicates whether a check mark appears next to the text of a menu item. If
To place a check mark next to the menu item text, the property value is true, otherwise the property value is false. The default value is False.
(3) Defaultitem property: Used to get or set a value indicating whether the menu item is the default menu item. When the value is true,
Is the default menu item, and the value is false when it is not the default menu item. The default menu items for menus are displayed in bold form. When the user double-clicks the containing default
The default entry is selected after the submenu of the entry, and then the submenu is closed.
(4) Enabled property: Used to get or set a value indicating whether the menu item is available. A value of TRUE indicates available, with a value of
False indicates that it is currently forbidden.
(5) RadioCheck property: Used to get or set a value that indicates whether the left side of the selected menu item displays a radio button or
check mark. A value of TRUE displays a radio button marker with a value of false to display a check mark.
(6) Shortcut property: Used to get or set a value that indicates the shortcut key associated with a menu item.
(7) Showshortcut property: Used to get or set a value that indicates whether the shortcut key associated with a menu item is in the header of the menu item.
Displayed next to it. True if the shortcut key combination is displayed next to the menu item title, and if no shortcut keys are displayed, the property value is
False The default value is true.
(8) MDIList property: Used to get or set a value indicating whether to use the multi-document interface (MDI) displayed in the context window
A list of child windows to populate the menu items. To display the list of MDI child windows in this menu item, set the property value to true otherwise set the
The value of the property is false. The default value is False.
3. A common event for a menu item's Common event menu item is the Click event, which occurs when the user clicks a menu item.
24. Multi-form programming Windows applications rarely consist of a single form, and in general, an application has many forms.
A C # project was just built with a form named Form1, and to build a multi-form application you should first add a form to the project, and add the form as follows.
(1) Clicking the button on the toolbar or executing the project → add Windows Form command will appear with the Add New Item dialog box shown in 10-17.
(2) In the dialog box, under Templates, in the list box, select the Windows forms icon, and in the Name text box,
Into the form name, and then click the Open button, adding a form to the application.
25. MDI Application Design
1. The concept of MDI applications
In the previous chapters, you created a single Document interface (SDI) application. Such programs (such as Notepad and paint programs) only support
Open a window or document once. If you need to edit multiple documents, you must create multiple instances of the SDI application. While using multiple documents
Interface (MDI) programs (such as Word and adobephotoshop), users can edit multiple documents at the same time. Application routines in MDI programs
The Order window is called the parent window, and the window inside the application is called a child window. Although
An MDI application can have multiple child windows, but each child window
There can be only one parent window. In addition, the maximum number of child windows in the active state
The target is 1. The child window itself can no longer be a parent window and cannot be moved to
Outside their parent window area. In addition, the child window behaves in relation to any
Other windows (such as the ability to close, minimize, resize, and so on). One
The child window may be functionally different from the other child windows of the parent window, for example,
One child window may be used to edit the image, and the other child window may be used to
The 3rd Sub-window can use a graphic to display the data, but the
Some windows belong to the same MDI parent window. Figure 10-19 is a typical
MDI Application. The outside window is the application window, inside of the two
A small window is an MDI child window.
2. Properties, methods, and events related to the design of an MDI application
The common MDI parent form properties are as follows.
(1) Activemdichild property: This property is used to represent the currently active MDI child window and returns null if no child window is currently present.
(2) IsMdiContainer property: This property is used to get or set a value indicating whether the form is a multi-document interface (MDI) child window
A container for the body, that is, the MDI parent form. When the value is true, the representation is the parent form, and the value is false when the representation is not the parent form.
(3) Mdichildren property: This property returns an MDI child form as an array of forms, with each array element corresponding to an MDI child form.
The properties of the commonly used MDI child form are:
(1) Ismdichild property: This property is used to get a value that indicates whether the form is a multiple-document interface (MDI) subform. Value
When true, the representation is a subform, and a value of false indicates that it is not a child form.
(2) MdiParent property: This property is used to specify the MDI parent form for this subform. In the methods related to MDI application design, one
Only uses the parent form's LayoutMDI method, which has the following invocation format:
The MDI parent form name. LayoutMDI (Value);
This method is used to arrange MDI child forms in the MDI parent form to navigate and manipulate MDI child forms. The parameter value determines the arrangement method,
The values are: mdilayout.arrangeicons (all MDI child forms are arranged as icons in the workspace of the MDI parent form),
Mdilayout.tilehorizontal (all MDI child windows are horizontally tiled within the workspace of the MDI parent form), mdilayout.tilevertical
(All MDI child windows are tiled vertically in the workspace of the MDI parent form) and Mdilayout.cascade (all MDI child windows are in the same layer
Stack in the workspace of the MDI parent form). The usual MDI parent form's event is mdichildactivate when activating or shutting down an MDI
The event occurs when the subform is in the child form.
3. Menu Merge
The parent form and subform can use different menus that are merged when the subform is selected. If you need to specify a merge party for the menu
, programmers can set the MergeOrder property and the MergeType property for each menu item.

(1) MergeOrder property: Used to determine the order in which menu items appear when two menus are merged, with a lower
The MergeOrder menu item will appear first.
(2) MergeType property: When the MergeOrder property value of some menu items of the combined two menus is equal,
Use this property to control how these menu items are displayed.

26. Keyboard Event Handling
Keyboard events occur when the user presses a key on the keyboard, which can be divided into two categories. The first class is the KeyPress event, when the pressed key represents a
ASCII characters, this type of event is triggered by the property KeyChar of its KeyPressEventArgs type parameter to determine the press key
ASCII code. Using the KeyPress event does not determine if the modifier keys (such as the Shift,alt and Ctrl keys) are pressed, in order to determine
Action, the KeyUp or KeyDown events are processed, and these events form the second type of keyboard event. This type of event has a KeyEventArgs
Type parameters, which can be used to test whether some modifier keys, function keys and other special key information are pressed.
1. Main properties of the KeyPressEventArgs class (one parameter type for the KeyPress event)
(1) Handled property: Used to get or set a value that indicates whether the KeyPress event has been processed.
(2) Keychar property: Used to get the character corresponding to the pressed key, usually the ASCII code of the key.
2. Main properties of the KeyEventArgs class (one parameter of the KeyUp and KeyDown events)
(1) ALT attribute: Used to get a value that indicates whether the ALT key was pressed.
(2) Control property: Used to obtain a value that indicates whether the CTRL key was pressed.
(3) Shift property: Used to get a value that indicates whether the SHIFT key has been pressed.
(4) Handled property: Used to get or set a value that indicates whether this event has been processed.
(5) KeyCode property: Returns the key code of the keyboard key with the Keys enumeration value, which does not contain modifier keys (Alt, control, and Shift keys)
Information that is used to test the specified keyboard key.
(6) KeyData property: Returns the key code of the keyboard key with the Keys enumeration type value, and contains the modifier key information for judging about pressing the keyboard
All information about the key.
(7) KeyValue property: Returns the key as an integer instead of the Keys enumeration type value. Used to obtain a numeric representation of the keyboard key being pressed.
(8) Modifiers property: Returns all pressed modifier keys (Alt, Control, and Shift keys) with the Keys enumeration type value, only used to determine
Modify key information.
27, mouse Event processing
The manipulation of the mouse is one of the important functions of the application, and there are some events related to mouse operation in visualc#, which can be used to
To facilitate mouse-related programming.
(1) MouseEnter event: Occurs when the mouse pointer enters the control.
(2) MouseMove event: Occurs when the mouse pointer moves over the control. The event handler receives a parameter of type MouseEventArgs
Number that contains the data associated with this event. The main properties of this parameter and their meanings are as follows.
Button property: Used to get which mouse button was pressed. This property is the value of the MouseButtons enumeration type.
The values and meanings are as follows: Left (press mouse button), middle (press the mouse buttons), right (mouse button), none (no mouse button pressed), XButton1 (Press the first Xbutton button, For Microsoft Smart Mouse Browser only) and XButton2 (the second Xbutton button is pressed for Microsoft Smart Mouse Browser only)
Clicks property: Used to get the number of times the mouse button was pressed and released.
Delta attribute: Used to obtain a signed count of the number of brakes that the mouse wheel has turned. The brake is a notch in the mouse wheel.
X attribute: Used to get the x-coordinate where the mouse is located.
Y property: Used to get the y-coordinate of where the mouse is located.
(3) MouseHover event: The event occurs when the mouse pointer hovers over the control.
(4) MouseDown event: The event occurs when the mouse pointer is over the control and the mouse button is pressed. The event handler also receives a
The parameters of the MouseEventArgs type.
(5) MouseWheel event: The event occurs when the mouse wheel is moved and the control has focus. The event handler for the event receives a
Parameters of the MouseEventArgs type
(6) MouseUp event: The event occurs when the mouse pointer is over the control and the mouse button is released. The event handler also receives a
The parameters of the MouseEventArgs type.
(7) MouseLeave event: The event occurs when the mouse pointer leaves the control.

Introduction to C # Form controls ListBox

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.