Full Transcript

Controls controls are the building blocks of the form’s graphical user interface (GUI). When you drag a control from the Toolbox onto the design surface, it is generally represented as a visible widget (or piece) to the user. Some controls are used not for display, but...

Controls controls are the building blocks of the form’s graphical user interface (GUI). When you drag a control from the Toolbox onto the design surface, it is generally represented as a visible widget (or piece) to the user. Some controls are used not for display, but for manipulating other objects (for example, database manipulation controls and timer control), and these are displayed in a special area at the bottom of the main window. When you click on a control, its properties are shown in the Properties window. You can change any property value in the Properties window. Organizing the Properties Window Within the Properties window, you can group properties by category or alphabetically. Figure 1 shows the Accessibility, Appearance, and Behavior categories and others. You can click the appropriate buttons in the menu bar to toggle between the Categorized and Alphabetical views. (When organized alphabetically, the Name of the Control is placed at the top of the list, out of order, for convenience.) Virtually every control has events associated with it. To view a control’s events, click the lightning bolt button. To switch back to properties click the Properties button. HCI & Visual Programming………..… ( 1 )....................... Dr. OmaimaBahaidara Figure 1. The Properties window, as you would expect, shows you the properties of the control you select. You can organize the properties by category, as shown here, or alphabetically. You can also view the events associated with the control. Control Prefixes When working with web controls, it’s often useful to use a three- letter lowercase prefix to identify the type of control to make user interface code as clear as possible. Some recommended control prefixes are as follows:  Form: frm  Button: btn OR cmd  Label: lbl  TextBox: txt HCI & Visual Programming………..… ( 2 )...................... Dr. OmaimaBahaidara  CheckBox: chk  RadioButton: opt  List control: lst  Combo Box: cmb  Group Box: grp  Panel: pnl  Picture Box: pct The main common control's properties: No. Property Description 1 Name programmatic name of the control 2 Anchor Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent. 3 BackColor Gets or sets the background color for the control. 4 BackgroundImage Gets or sets the background image displayed in the control. 5 Dock Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent. 6 Enabled Gets or sets a value indicating whether the control can respond to user interaction. 7 Font Gets or sets the font of the text displayed by the control. HCI & Visual Programming………..… ( 3 )...................... Dr. OmaimaBahaidara 8 ForeColor Gets or sets the foreground color of the control. 9 Size Gets or sets the size of the control:  Height: Gets or sets the height of the control.  Width: Gets or sets the width of the control. 10 Location Gets or sets the Point ( X , Y ) that represents the upper-left corner of the control in container coordinates. 11 Text Gets or sets the text associated with this control. 12 Visible Gets or sets a value indicating whether the control is displayed or not. 1. Form It is the main container of the other controls. The application can contain more than one form. Form properties: No. Property Description 1 AutoScroll Gets or sets a value indicating whether the form enables autoscrolling. 2 ControlBox Gets or sets a value indicating whether a control box is displayed in the caption bar of the form or not. 3 MinimizeBox Gets or sets a value indicating whether the Minimize button is displayed in the caption bar of the form or not. HCI & Visual Programming………..… ( 4 )...................... Dr. OmaimaBahaidara 4 MaximizeBox Gets or sets a value indicating whether the Maximize button is displayed in the caption bar of the form or not. 5 Opacity Gets or sets the opacity level of the Form. 6 FormBorderStyle Gets or sets the border style of the Form. 7 WindowState Gets or sets a value that indicates whether form is minimized, maximized, or normal. 8 StartPosition Gets or sets the starting position of the form at run time. The default event for Form control is Load. 2. Label The Label control is used to display text in the form. This control uses the Text attribute to assign the content of the control. You can also provide content for the control through programmatic means, as illustrated in Listing 1. Listing 1: Programmatically providing text to the Label control Label1.Text = "Welcome in C# " ; No. Property Description 1 AutoSize Gets or sets a value indicating whether the control is automatically resized to display its entire contents or not. 2 TextAlign Gets or sets the alignment of text in the label. The default event for Label control is Click. 3. Button Another common control for your forms is a Button. Most of the time you are simply dealing with items contained in your form HCI & Visual Programming………..… ( 5 )...................... Dr. OmaimaBahaidara through the Button control’s Click event. HCI & Visual Programming………..… ( 6 )...................... Dr. OmaimaBahaidara No. Property Description 1 FlatStyle Gets or sets the flat style appearance of the button control. 2 FlatAppearance Gets the appearance of the border and the colors used to in flat style. 3 Image Gets or sets the image that is displayed on a button control. 4 ImageAlign Gets or sets the alignment of the image on the button control. 5 TextImageRelation Gets or sets the position of text and image relative to each other. The default event for Button control is Click. 4. Text Box The TextBox control is one of the most used controls to take information from the end user. As its name suggests, the control provides a text box on the form that enables the end user to input text. No. Property Description 1 BorderStyle Gets or sets the border type of the text box control. 2 MaxLength Gets or sets the maximum number of characters the user can type or paste into the text box control. 3 Multiline Gets or sets a value indicating whether this is a multiline TextBox control or not. HCI & Visual Programming………..… ( 7 )....................... Dr. OmaimaBahaidara 4 PasswordChar Gets or sets the character used to mask characters of a password in a TextBox control. 5 ReadOnly Gets or sets a value indicating whether text in the text box is read-only. 6 SelectedText Gets or sets a value indicating the currently selected text in the control. 7 TextAlign Gets or sets how text is aligned in a TextBox control. The default event for TextBox control is TextChanged. Using the Focus( ) Method Because the TextBox control is derived from the base class of System.Windows.Forms, one of the methods available to it is Focus( ). The Focus( ) method enables you to dynamically place the end user’s cursor in an appointed control (not just the TextBox control, but in any of the controls derived from the System.Windows.Forms class). With that said, it is probably most often used with the TextBox control, as illustrated in Listing 2. Listing 2: Using the Focus( ) method with the TextBox control private void Form1_Load(object sender, EventArgs e) { TextBox1.Focus( ); } When this Form is loaded, the cursor is already placed inside of the text box, ready for you to start typing. There is no need to move your mouse to get the cursor in place so you can start entering information in the form. HCI & Visual Programming………..… ( 8 )...................... Dr. OmaimaBahaidara MessageBox.Show Function: MessageBox.Show(String, String, MessageBoxButtons, MessageBoxIcon) Displays a message box with specified text, caption, buttons, and icon. Parameters text: Type: System.String The text to display in the message box. caption: Type: System.String The text to display in the title bar of the message box. buttons: Type: System.Windows.Forms.MessageBoxButtons One of the MessageBoxButtons values that specifies which buttons to display in the message box. icon: Type: System.Windows.Forms.MessageBoxIcon One of the MessageBoxIcon values that specifies which icon to display in the message box. Return Value: Type: System.Windows.Forms.DialogResult One of the DialogResult values. HCI & Visual Programming………..… ( 9 )...................... Dr. OmaimaBahaidara MessageBoxButtons Enumeration: N Member name Description o. 1 AbortRetryIgnore The message box contains Abort, Retry, and Ignore buttons. 2 OK The message box contains an OK button. 3 OKCancel The message box contains OK and Cancel buttons. 4 RetryCancel The message box contains Retry and Cancel buttons. 5 YesNo The message box contains Yes and No buttons. 6 YesNoCancel The message box contains Yes, No, and Cancel buttons. MessageBoxIcon Enumeration: Member Description name 1 Error The message box contains a symbol consisting of white X in a circle with a red background. 2 Information The message box contains a symbol consisting of a lowercase letter i in a circle with a blue background. 3 None The message box contain no symbols. 4 Question The message box contains a symbol consisting of a question mark in a circle with a blue background. 5 Warning The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background. HCI & Visual Programming………..… ( 10 )..................... Dr. OmaimaBahaidara DialogResult Enumeration: Member Description name 1 Abort The dialog box return value is Abort (usually sent from a button labeled Abort). 2 Cancel The dialog box return value is Cancel (usually sent from a button labeled Cancel). 3 Ignore The dialog box return value is Ignore (usually sent from a button labeled Ignore). 4 No The dialog box return value is No (usually sentfrom a button labeled No). 5 None Nothing is returned from the dialog box. This means that the modal dialog continues running. 6 OK The dialog box return value is OK (usually sent from a button labeled OK). 7 Retry The dialog box return value is Retry (usually sent from a button labeled Retry). 8 Yes The dialog box return value is Yes (usually sentfrom a button labeled Yes). HCI & Visual Programming………..… ( 11 )..................... Dr. OmaimaBahaidara

Use Quizgecko on...
Browser
Browser