In Brief

This chapter looked at Windows programming in C#. Here's an overview of the topics we've discussed:

  • Windows are based on the System.Windows.Forms.Form class, and programming with them is straightforward. To create your own form, you just derive from this class. In Main , you pass a new object of the startup form you want the application to display to the Application.Run method.

  • Although you can write windowed applications by hand, you usually create them in the C# Integrated Development Environment (IDE). The IDE has a large set of tools available for rapid code development.

  • Forms and controls have a number of properties, such as the Text property, which displays title bar text in a form and caption text in buttons , as well as methods such as the SetBounds method to move or resize the form or control.

  • Message boxes are displayed with the MessageBox.Show method and enable you to display a message with a variety of buttons to the users. You can determine which button the user clicked with the return value from this method, which is a member of the DialogResult enumeration.

  • Basic Windows controls include text boxes, labels, buttons, check boxes, radio buttons, list boxes, scroll bars, picture boxes, combo boxes, track bars, and others.

  • Advanced Windows controls include the seven built-in dialog boxes (Open File, Save File, and so on), timers, image lists, tree views, and others.

  • You can add controls at runtime by creating a new control object using classes such as System.Windows.Forms.TextBox , configuring the control as you like, and then adding it to a form's Controls collection. You can also connect an event handler to a control's event using code like this: newButton.Click += new System.EventHandler(this.newButton_Click) .

  • Communication between windows in multi-window applications is usually via custom properties and methods. Even when a window is closed, you can still access its properties and methods until its Dispose method is called.

  • Multiple Document Interface (MDI) applications have an MDI parent and one or more MDI children that appear in the parent's client area. To make a window an MDI window, you set its IsMdiContainer property to true . To make a form an MDI child, assign the MDI parent form to its MdiParent property.

  • Dialog boxes are normal forms that you customize, giving them a fixed border, removing the control box (which contains the maximize, minimize, and close buttons), as well as setting its ShowInTaskBar property to false . You can assign the buttons in a dialog box to its AcceptButton and CancelButton properties to create OK and Cancel buttons, as well as assign values from the DialogResult enumeration to the DialogResult return value. You can display a modal dialog box with the ShowDialog method and a non-modal dialog box with the Show method.

Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: