Library sample chapters
Introduction to Windows Forms
Introduction
This is a sample chapter from C# and the .NET Framework.
In This Chapter
- The Hello Windows Forms Application
- Creating and Using an Event Handler
- Defining the Border Style of the Form
- Adding a Menu
- Adding a Menu Shortcut
- Handling Events from Menus
Windows Forms is the .NET replacement for MFC. Unlike the MFC library, which was a thin(ish) wrapper on the Win32 API, Windows Forms is a totally object-oriented, hierarchical answer to Windows development under .NET.
Despite its "Forms" epithet, the layout of components is not done with a resource file as is the case in MFC dialogs and form windows. Every component is a concrete instance of a class. Placement of the components and control of their properties are accomplished by programming them via their methods and accessors. The drag-and-drop tools used to define a Windows Form are actually maintaining the source code that initializes, places, and allows interaction with a target application.
Resource files are used by Windows Forms for tasks such as placing images on the form or storing localized text, but not in the familiar format that has been used by Windows since the 1980s. As you might expect, the new resource file format is an XML file. We'll examine resources in more detail in Chapter 3.4, "Windows Forms Example Application (Scribble .NET)."
Windows Forms layout can be done by dragging components from a tool palette onto a form. You can use VS.NET for this or alternatively, if you really want the whole hands-on experience, you can lay out your forms by coding the objects directly in C#, VB, managed C++, or any of the .NET languages. To give you the benefit of understanding what really goes on in a Windows Form, we won't be dealing with any of the design tools early in this section. Rather, we will do as much as possible by hand and then, when you understand the basics, move on to using the drag-and-drop tools.
User interaction in Windows Forms is accomplished through events. The components provide event sources, such as mouse movement, position, and button clicks, and then you wire the events to handlers. These are functions called by a standard form of delegate, which means there are no message maps of which to keep track.
Related articles
Related discussion
-
looking for help on asp
by cladironbeard (2 replies)
-
Socket Programming in C# - Part 1
by graumanoz (23 replies)
-
LINQ in Action
by naser1 (0 replies)
-
Creating a Windows Service in VB.NET
by Templario55 (107 replies)
-
simple vb to c#, help please
by lksath (1 replies)
Events coming up
-
Aug
28
St. Louis Day of .NET
St. Charles, United States
Technical conference with be 2 full days of content with over 40 sessions from local and national speakers, with topics such as:•.NET languages: C#, VB.NET•Technologies: WPF, Silverlight, WCF•Development tools: Visual Studio, TFS, Expression Blend
Actually all you have to do in place an ampersand before the letter you want underlined.
So if you want the "r" in "Print" underlined, enter in the code:
"P&rint"
That's it.
if you want to view the _ all the time for alt shortcuts you have to go to:
display properties->appearance->effects
and uncheck the "Hide underlined charactors for keyboard navigation until I press the ALT key" checkbox.
these instructions are for XP SP2 Pro build 2600
The "" on the short-cut character is visible only when "ALT" is pressed. Is it possible to display the "" programatically???
This thread is for discussions of Introduction to Windows Forms.