1 / 24

Graphical User Interface Components Version 1.1

Graphical User Interface Components Version 1.1. Obectives. Students should understand how to use these basic Form components to create a Graphical User Interface (GUI) application. Form TextBox Label Button ListBox MessageBox RichTextBox MenuStrip.

Download Presentation

Graphical User Interface Components Version 1.1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphical User InterfaceComponentsVersion 1.1

  2. Obectives Students should understand how to use these basicForm components to create a Graphical User Interface (GUI) application Form TextBox Label Button ListBox MessageBox RichTextBox MenuStrip

  3. These windows controls are discussed in great detail at http://msdn.microsoft.com/en-us/library/k50ex0x9.aspx

  4. Form Control A Form control is created when your GUI application is created by Visual Studio. A form encapsulates your main program and provides a frame, title bar with: icon, text, minimize, maximize/restore and close buttons and a client area containing your GUI controls.

  5. TextBox Control A TextBox control is typically used to get/set a single line of text from/to the user. The most important member of a TextBox is its Text property. The Text property of a TextBox control is a getter/setter string object. You can operate (via get/set) on this string just like any other string object.

  6. TextBox Control Example Given that the user has typed an integer value into a TextBox control named “Txtjoe” , you could get the integer by writing int value = int.Parse(Txtjoe.Text); Note that we use three or four charaters to indicate the type of control “Txt” in this case.

  7. TextBox Control Example Given that you want to output a double value, “money” formatted as currency in a TextBox named “Txtjoe”, you could write Txtjoe.Text = string.Format(“{0:C}”, money);

  8. Label Control Label controls are typically used to provide descriptive text for a control. For example, you can use a Label to add descriptive text for a TextBox control to inform the user about the type of data expected. Label controls can also be used to add descriptive text to a Form to provide the user with helpful information. For example, you can add a Label to the top of a Form that provides instructions to the user on how to input data in the controls on the form. Label controls can be also used to output data to your Form.

  9. Label Control Example Given that you want to output a double value, “money” formatted as currency in a Label named “Lbljoe”, you could write Lbljoe.Text = string.Format(“{0:C}”, money); Note that the Text property is a getter/setter property of the Label control.

  10. Button Control Button controls are typically used to let the user initiate some action. When you click on a Button with the mouse, it generates a Click event.

  11. Button Example When the Button is clicked, this event handler reads data from TxtBox1, parses it to an integer, and then writes it out to TxtBox2. private void BtnTest1_Click(object sender, EventArgs e) { string x = TxtBox1.Text; int num = int.Parse(x); TxtBox2.Text = string.Format("Answer = {0}", num); }

  12. ListBox Control A ListBox control provides the user with a list of items. An event is generated when one of these items is selected. You can provide the list if items to be shown at design time, or they can be added at run time using the Add method.

  13. ListBox Example private void LstBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex != -1) switch (LstBox1.SelectedIndex) { case 0: TxtBox2.Text = "Pizza"; break; case 1: TxtBox2.Text = "Hamburger"; break; case 2: TxtBox2.Text = "Salad"; break; case 3: TxtBox2.Text = "Drink"; break; case 4: TxtBox2.Text = "Hot Dog"; break; case 5: TxtBox2.Text = "Apple Pie"; break; }// end switch }

  14. MessageBox Control A MessageBox control displays a Modal Dialog Box some text and optionally a Button and an icon. Message boxes are used to provide feedback information to the user. You cannot add a MessageBoxat design time. Message boxes are created by using the method MessageBox.Show( ). There are several forms of this method, for example // message box with text MessageBox.show(string); // message box with text and caption MessageBox.Show(string, string); // message box with text, caption, and buttons MessageBox.Show(string, string, MessageBoxButtons);

  15. MessageBoxButtons * OK The message box contains an OK button. * OKCancel The message box contains OK and Cancel buttons. * AbortRetryIgnore The message box contains Abort, Retry, and Ignore buttons. * YesNoCancel The message box contains Yes, No, and Cancel buttons. * YesNo The message box contains Yes and No buttons. * RetryCancel The message box contains Retry and Cancel buttons.

  16. The response to a MessageBoxButton click comes back as a DialogResult.

  17. MessageBox Example private void BtnQuit_Click(object sender, EventArgs e) { DialogResult response = MessageBox.Show("Do you really want to quit?",Quit", MessageBoxButtons.YesNo); if (response == DialogResult.Yes) this.Close(); }

  18. RichTextBox Control A RichTextBox control displays one or more lines of text are used to give output or receive input from the user. // Adding text to a RichTextBox Control RTxt.Append(string); // Clearing a RichTextBox Control RTxt.Clear();

  19. Menu Controls To add a menu bar to your form follow these steps

  20. Drag a MenuStrip from the tool box onto your form.

  21. (2) Type then text that you want for the first item on the menu here.

  22. You can continue to add 1st level menu items

  23. Or add sub-menu items here.

  24. Create an event handler by double clicking on one of the items in your menu private void exitToolStripMenuItem1_Click(object sender, EventArgs e) { this.Close(); }

More Related