We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Book Cover C# and the .NET Framework
61215 times
Rated
Read 61,215 times

Contents

Related Categories

Introduction to Windows Forms - Introduction

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.

Comments

  • short-cuts

    Posted by rholden on 15 Jul 2005

    this is not a programming issue and it is not something you can set unless you have a custom menu control.

    if you want to view the _ all the time for alt shortcuts you have to go to:

    display pro...

  • Sort-cuts

    Posted by DotDot on 15 May 2003

    The "_" on the short-cut character is visible only when "ALT" is pressed. Is it possible to display the "_" programatically???:confused: