1. Trang chủ
  2. » Công Nghệ Thông Tin

vb.net book phần 6 pptx

79 168 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 79
Dung lượng 548,33 KB

Nội dung

Windows Forms Components and Controls• Chapter 8 363 ■ The user presses Enter when the button is the “accept” button of the form. ■ The user presses Esc when the button is the “cancel” button of the form. ■ The user presses the access key (Alt + the underlined letter) for the button. In addition, you can click the Button control programmatically in the following ways: ■ Invoke the button’s Click event. ■ Call the PerformClick method. When you designate a Button control to be the accept button on the form, the button is clicked when the user presses Enter, even if another control has the focus—except when that other control is another button or a multiline text box. This basically makes it the default button on the form.When you designate a Button control to be the cancel button on the form, the button is clicked when the user presses Esc, even if another control has the focus.A button can be both the accept button and the cancel button on the form.The following code shows you how to do this: With frmForm 'Designate btnButton as the accept button and the 'cancel button of frmForm 'Set the AcceptButton property to btnButton .AcceptButton = btnButton 'Set the CancelButton property to btnButton .CancelButton = btnButton End With NOTE If the action represented by a Button control requires additional informa- tion, such as the folder in which to save a document, include an ellipsis (…) in the button’s Caption property. www.syngress.com 153_VBnet_08 8/15/01 1:41 PM Page 363 364 Chapter 8 • Windows Forms Components and Controls CheckBox Control The Windows Forms CheckBox control indicates True/False or Yes/No options. The CheckBox control appears as a square box with an accompanying label. When a choice is set, a check mark appears in the box.When the choice is not set, the box is empty. Use the CheckBox control to present an independent or non-exclusive choice, a True/False or Yes/No selection to the user.You can group multiple check boxes using a GroupBox control to display multiple choices from which the user may select more than one. The CheckBox control has two important properties: Checked and CheckedState.The Checked property returns either True or False, and indicates whether the choice is set.The CheckedState property returns CheckState.Checked when the choice is set, and CheckState.Unchecked when the choice is not set. If the ThreeState property is set to True, the CheckedState property also returns CheckState.Indeterminate, used when the choice is set for some but not all elements of the selection. Since grouped controls can be moved around together on the form designer, group multiple boxes using the GroupBox control to enhance visual appearance and aid in GUI design Table 8.7 shows the properties of the CheckBox control. Table 8.7 CheckBox Properties Property Description AllowDrop Determines if the check box will receive drag-drop notifications Appearance Controls the appearance of the check box AutoCheck Causes the check box to automatically change state when clicked BackColor The background color used to display text and graphics in the check box BackgroundImage The background image used for the check box CheckAlign Determines the location of the check box inside the control Checked Indicates whether the check box is checked or unchecked Cursor The cursor that appears when the mouse passes over the check box FlatStyle Determines the display of the check box when users move the mouse over the check box and click www.syngress.com Continued 153_VBnet_08 8/15/01 1:41 PM Page 364 Windows Forms Components and Controls• Chapter 8 365 Property Description Font The font used to display text in the check box ForeColor The foreground color used to display text and graphics in the check box Image The image that will be displayed on the face of the check box ImageAlign The alignment of the image that will be displayed in the face of the check box ImageIndex The index of the image in the image list to display in the face of the check box ImageList The image list to get the image to display in the face of the check box RightToLeft Indicates whether the check box should draw right-to-left for RTL languages TabIndex Determines the index in the tab order that the check box will occupy TabStop Indicates whether the user can use the Tab key to give focus to the check box Text The text contained in the check box TextAlign The alignment of the text that will be displayed in the face of the check box ThreeState Controls whether or not the user can select the indeterminate state of the check box RadioButton Control The Windows Forms RadioButton control is used to give the user a single choice within a set of two or more mutually exclusive choices. Radio buttons appear as a set of small circles.When an option button choice is set, a dot appears in the middle of the circle.When the item is not the current setting, the circle next to the current setting is empty. If the user chooses any radio button in a group, that value becomes the setting for the group; the dot appears in that button and all the other buttons in the group remain empty. Group radio buttons by adding them to a form.To add separate groups, you need to add them to a Panel control or a GroupBox control. www.syngress.com Table 8.7 Continued 153_VBnet_08 8/15/01 1:41 PM Page 365 366 Chapter 8 • Windows Forms Components and Controls The radio button and the check box are used for different functions. Use a radio button when you want the user to choose only one option.When you want the user to choose all appropriate options, use a check box.Table 8.8 shows the properties of the RadioButton control. Table 8.8 RadioButton Properties Property Description AllowDrop Determines if the radio button will receive drag-drop notifications Appearance Controls whether the radio button appears as normal or as a Windows push button AutoCheck Causes the radio button to automatically change state when clicked BackColor The background color used to display text and graphics in the radio button BackgroundImage The background image used for the radio button CheckAlign Determines the location of the check box inside the radio button Checked Indicates whether the radio button is checked or not Cursor The cursor that appears when the mouse passes over the radio button FlatStyle Determines the display of the radio button when users move the mouse over the radio button and click Font The font used to display text in the radio button ForeColor The foreground color used to display text and graphics in the radio button Image The image that will be displayed on the face of the radio button ImageAlign The alignment of the image that will be displayed in the face of the radio button ImageIndex The index of the image in the image list to display in the face of the radio button ImageList The image list to get the image to display in the face of the radio button RightToLeft Indicates whether the radio button should draw right-to-left for RTL languages TabIndex Determines the index in the tab order that the radio button will occupy www.syngress.com Continued 153_VBnet_08 8/15/01 1:41 PM Page 366 Windows Forms Components and Controls• Chapter 8 367 Property Description TabStop Indicates whether the user can use the Tab key to give focus to the radio button Text The text contained in the radio button TextAlign The alignment of the text that will be displayed in the face of the radio button RichTextBox Control Much like the TextBox control, the Windows Forms RichTextBox control allows you to display text to the user and collect text from the user. In addition to the many features it shares with the TextBox control, the RichTextBox control allows you to change the font, size, and color of text.You can use a rich text box to add advanced formatting, such as indents, hanging indents, and bulleted paragraphs, to your application.You can also use a rich text box to save text to a file, or load text from a file.Table 8.9 shows the properties of the RichTextBox control. Table 8.9 RichTextBox Properties Property Description AcceptsTab Indicates if tab characters are accepted as input for the rich text box AutoSize Enables automatic resizing based on font size for a single-line rich text box AutoWordSelection Turns on/off automatic word selection BackColor The background color used to display text and graphics in the rich text box BorderStyle Indicates whether or not the rich text box should have a border BulletIndent Defines the indent for the bullets in the rich text box Cursor The cursor that appears when the mouse passes over the rich text box Delimiter Defines the delimiter characters (Asian version of OS only) DetectURLs Turns on/off automatic URL highlighting www.syngress.com Table 8.8 Continued Continued 153_VBnet_08 8/15/01 1:41 PM Page 367 368 Chapter 8 • Windows Forms Components and Controls Property Description FollowPunctuation Defines the non-leading punctuation (Asian version of OS only) Font The font used to display text in the rich text box ForeColor The foreground color used to display text and graphics in the rich text box HideSelection Indicates that the selection should be hidden when the rich text box loses focus LeadPunctuation Defines the leading punctuation (Asian version of OS only) Lines The lines of text in a multi-line rich text box, as in an array of string values MaxLength Specifies the maximum number of characters that can be entered into the rich text box. Zero implies no maximum Multiline Controls whether the text of the rich text box can span more than one line OutlineMode Turns on/off outline mode ReadOnly Controls whether the text in the rich text box can be changed or not RightMargin Defines the right margin dimensions RightToLeft Indicates whether the rich text box should draw right-to-left for RTL languages ScrollBars Defines the behavior of the scroll bars of the rich text box SelectionMargin Turns on/off the selection margin TabIndex Determines the index in the tab order that the rich text box will occupy TabStop Indicates whether the user can use the Tab key to give focus to the rich text box Text The text contained in the rich text box WordBreak Enables the word-break mode (Asian version of OS only) WordPunctuation Defines the type of punctuation table to be used for word operations (Asian version of OS only) WordWrap Indicates if lines are automatically word-wrapped for multi-line rich text boxes www.syngress.com Table 8.9 Continued 153_VBnet_08 8/15/01 1:41 PM Page 368 Windows Forms Components and Controls• Chapter 8 369 You can change the font, size, and color of text in the RichTextBox control by using the SelFont, SelFontSize, and SelColor properties.Also, you can quickly open a Rich Text Format file using a rich text box.This is handy when you want your application to display a README file that changes with every version of your application.You make changes to the file, not your code, and you can simply open the file with a rich text box. Use an OpenFileDialog control to navigate to the file you want to open, as in the following example: With OpenFileDialog1 'Show only RTF files .Filter = "Rich Text Format|*.rtf" .ShowDialog() End With richtextbox2.LoadFile(openfiledialog1.FileName) Often, when opening files, you only want to show those with a certain extension.This makes it easier for the user to locate a file.You can do this with the Filter property of the Open File dialog box: .Filter = "Rich Text Format|*.rtf" Use this line to show only RTF files in the Open File dialog box. Files with other extensions will not appear. TreeView Control The Windows Forms TreeView control is used to display hierarchical informa- tion, such as e-mail folders and messages, as well as folders and files on a computer.A tree view contains cascading branches of nodes, and each node consists of an image and a label. Node images are taken from an ImageList con- trol. At the top-most level in a tree view are root nodes that can be expanded or collapsed if the nodes have child nodes (nodes that descend from other nodes). Table 8.10 shows the properties of the TreeView control. Table 8.10 TreeView Properties Property Description AllowDrop Determines if the tree view will receive drag-drop notifications www.syngress.com Continued 153_VBnet_08 8/15/01 1:41 PM Page 369 370 Chapter 8 • Windows Forms Components and Controls Property Description BackColor The background color used to display text and graphics in the tree view BorderStyle The border style of the tree view CheckBoxes Indicates whether check boxes are displayed beside nodes Cursor The cursor that appears when the mouse passes over the tree view Font The font used to display text in the tree view ForeColor The foreground color used to display text and graphics in the tree view FullRowSelect Indicates whether the highlight spans the width of the tree view HideSelection Removes highlight from the selected node when the tree view loses focus HotTracking Indicates whether nodes give feedback when the mouse is moved over them ImageIndex The default image index for nodes ImageList The image list from which node images are taken Indent The indentation width of child nodes in pixels ItemHeight The height of every item in the tree view LabelEdit Indicates whether or not the user can edit the label text of nodes Nodes The root nodes in the tree view PathSeparator The string delimiter used for the path returned by a node’s FullPath property RightToLeft Indicates whether the control should draw right-to-left for RTL languages Scrollable Indicates whether the tree view will display scroll bars if it contains more nodes than can fit in the visible area SelectedImage The default image index for selected nodes ShowLines Indicates whether lines are displayed between sibling nodes and between parent and child nodes ShowPlusMinus Indicates if plus/minus buttons are shown next to parent nodes www.syngress.com Table 8.10 Continued Continued 153_VBnet_08 8/15/01 1:41 PM Page 370 Windows Forms Components and Controls• Chapter 8 371 Property Description ShowRootLines Indicates whether lines are displayed between root nodes Sorted Indicates whether nodes are sorted TabIndex Determines the index in the tab order that this control will occupy TabStop Indicates whether the user can use the Tab key to give focus to the tree view ListBox Control A Windows Forms ListBox control displays a list of choices which the user can select from. List boxes are best used for displaying large number of choices.There are situations in which you can display choices with either a group of check boxes or a list box. In general, use a group of check boxes when the number of choices is small. For clarity, use a list box when the number of choices is large. A vertical scroll bar accompanies a list box if the items displayed exceed the height of the box.A list box will also sport a horizontal scrollbar if the MultiColumn property is set to True. In that case, values are displayed in columns horizontally.Table 8.11 shows the properties of the ListBox control. Table 8.11 ListBox Properties Property Description AllowDrop Determines if the list box will receive drag-drop notifications BackColor The background color used to display text and graphics in the list box BorderStyle Controls what type of border is drawn around the list box ColumnWidth Indicates how wide each column should be in a multi column list box Cursor The cursor that appears when the mouse passes over the list box DataSource Indicates the list that the list box will use to get its items www.syngress.com Table 8.10 Continued Continued 153_VBnet_08 8/15/01 1:41 PM Page 371 372 Chapter 8 • Windows Forms Components and Controls Property Description DisplayMember Indicates the property to display for the items in the list box DrawMode Indicates whether the system or the user paints items in the list box Font The font used to display text in the list box ForeColor The foreground color used to display text and graphics in the list box HorizontalExtent The width, in pixels, by which a list box can be scrolled horizontally. Only valid if HorizontalScrollbar is True HorizontalScrollbar Indicates whether the list box will display a horizontal scrollbar for items beyond the right edge of the list box IntegralHeight Indicates whether the list can contain only complete items ItemHeight The height, in pixels, of items in a fixed-height owner- drawn list box Items The items in the list box MultiColumn Indicates if values should be displayed in columns horizontally RightToLeft Indicates whether the list box should draw right-to-left for RTL languages ScrollAlwaysVisible Indicates if the list box should always have a scrollbar present, regardless of how many items are in it SelectionMode Indicates if the list box is to be single-select, multi- select, or unselectable Sorted Controls whether the list is sorted TabIndex Determines the index in the tab order that the list box will occupy TabStop Indicates whether the user can use the Tab key to give focus to the list box UseTabStops Indicates if tab characters should be expanded into full spacing ValueMember Indicates the property to use as the actual value for the items in the list box www.syngress.com Table 8.11 Continued 153_VBnet_08 8/15/01 1:41 PM Page 372 [...]... System.Object 2 Set each member of the array to a string—the string becomes the text displayed in the list 3 Set the Items collection’s All property to the array www.syngress.com 375 153_VBnet_08 3 76 8/15/01 1:41 PM Page 3 76 Chapter 8 • Windows Forms Components and Controls For example, suppose you want to display the days of the week in a checked list box Follow the steps just outlined in the manner shown next:... allowable values of the up-down control In other words, the Items property is the domain of a read-only up-down control, which is where the control gets its www.syngress.com 385 153_VBnet_08 3 86 8/15/01 1:41 PM Page 3 86 Chapter 8 • Windows Forms Components and Controls name.The user cannot type a new value in a read-only up-down control Instead, a keystroke selects the item in the control that starts with... display numbers instead of text.The numeric up-down control is a great choice when collecting input such as a number of employees and a number of days from the user.Table 8. 16 shows the properties of the NumericUpDown control Table 8. 16 NumericUpDown Properties Property Description AllowDrop Determines if the up-down control will receive dragdrop notifications The background color used to display text and... pnlAttributes.BorderStyle = WinForms.BorderStyle.Fixed3D pnlAttributes.BorderStyle = WinForms.BorderStyle.FixedSingle pnlAttributes.BorderStyle = WinForms.BorderStyle.None www.syngress.com 395 153_VBnet_08 3 96 8/15/01 1:41 PM Page 3 96 Chapter 8 • Windows Forms Components and Controls You can change the background color used to display graphics and text in a panel.When you change a panel’s background color, the background... 3 In the Properties window, click the Items property, then click the ellipsis 4 In String Collection Editor, type the first item, then press Enter 5 Type the next items, pressing Enter after each item 6 Click OK There are a variety of ways to programmatically add items to a combo box You can simply add an item to the list, letting the combo box control the position of insertion based on whether or not... hexadecimal BackColor BorderStyle Cursor DecimalPlaces Font ForeColor Hexadecimal Continued www.syngress.com 153_VBnet_08 8/15/01 1:41 PM Page 387 Windows Forms Components and Controls• Chapter 8 Table 8. 16 Continued Property Description Increment Indicates the amount to increment/decrement on each button click InterceptArrowKeys Indicates whether the up-down control will increment and decrement the value... objDaysOfTheWeek(0) = "Monday" objDaysOfTheWeek(1) = "Tuesday" objDaysOfTheWeek(2) = "Wednesday" objDaysOfTheWeek(3) = "Thursday" objDaysOfTheWeek(4) = "Friday" objDaysOfTheWeek(5) = "Saturday" objDaysOfTheWeek (6) = "Sunday" 'Set the Items collection's All property to the array clbDaysOfTheWeek.Items.All = objDaysOfTheWeek ListView Control The ListView control can display text in four different views: text-only,... 3 Click the TabPages property, then click the ellipsis 4 In Tab Page Collection Editor, click Add 5 In the TabPage1 Properties box, change the Text property to an appropriate caption for the tab page 6 Click OK The tab control has other unique properties.Table 8.22 lists the properties of the TabControl control Table 8.22 TabControl Properties Property Description Alignment Determines whether the tabs . a Panel control or a GroupBox control. www.syngress.com Table 8.7 Continued 153_VBnet_08 8/15/01 1:41 PM Page 365 366 Chapter 8 • Windows Forms Components and Controls The radio button and the check. radio button will occupy www.syngress.com Continued 153_VBnet_08 8/15/01 1:41 PM Page 366 Windows Forms Components and Controls• Chapter 8 367 Property Description TabStop Indicates whether the. include an ellipsis (…) in the button’s Caption property. www.syngress.com 153_VBnet_08 8/15/01 1:41 PM Page 363 364 Chapter 8 • Windows Forms Components and Controls CheckBox Control The Windows

Ngày đăng: 14/08/2014, 04:21

TỪ KHÓA LIÊN QUAN