Jones / MacDonald / Rajan | Visual C# 2010 Recipes | E-Book | sack.de
E-Book

E-Book, Englisch, 1016 Seiten, eBook

Jones / MacDonald / Rajan Visual C# 2010 Recipes

A Problem-Solution Approach
1. Auflage 2010
ISBN: 978-1-4302-2526-3
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark

A Problem-Solution Approach

E-Book, Englisch, 1016 Seiten, eBook

ISBN: 978-1-4302-2526-3
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark



Mastering the development of .NET 4.0 applications in C# is less about knowing the Visual C# 2010 language and more about knowing how to use the functionality of the .NET framework class library most effectively. Visual C# 2010 Recipes explores the breadth of the .NET Framework class library and provides specific solutions to common and interesting programming problems. Each recipe is presented in a succinct problem/solution format and is accompanied by a working code sample to help you understand the concept and quickly apply it. When you are facing a Visual C# 2010 problem, this book likely contains a recipe providing the solution—or at least points you in the right direction. Even if you are simply looking to broaden your knowledge of the .NET framework class library,  Visual C# 2010 Recipes is the perfect resource to assist you. This is an updated reference for .NET 4.0 programmers. All code samples come as stand-alone Visual Studio 2010 solutions for your convenience.
Jones / MacDonald / Rajan Visual C# 2010 Recipes jetzt bestellen!

Zielgruppe


Popular/general

Weitere Infos & Material


Application Development.- Data Manipulation.- Application Domains, Reflection, and Metadata.- Threads, Processes, and Synchronization.- Files, Directories, and I/O.- XML Processing.- Windows Forms.- Graphics, Multimedia, and Printing.- Database Access.- Networking.- Security and Cryptography.- Unmanaged Code Interoperability.- Commonly Used Interfaces and Patterns.- Windows Integration.- Parallel Programming.- Using LINQ.- Windows Presentation Foundation.


"1-2. Create a Windows-Based Application from the Command Line (p. 5-6)

Problem
You need to use the C# command-line compiler to build an application that provides a Windows Forms– based GUI.

Solution
Create a class that extends the System.Windows.Forms.Form class. (This will be your application’s main form.) In one of your classes, ensure you implement a static method named Main. In the Main method, create an instance of your main form class and pass it to the static method Run of the System.Windows. Forms.Application class. Build your application using the command-line C# compiler, and specify the /target:winexe compiler switch.

Note If you own Visual Studio, you will most often use the Windows Application project template to create new Windows Forms–based applications. Building large GUI-based applications is a time-consuming undertaking that involves the correct instantiation, configuration, and wiring up of many forms and controls. Visual Studio automates much of the work associated with building graphical applications. Trying to build a large graphical application without the aid of tools such as Visual Studio will take you much longer, be extremely tedious, and result in a greater chance of bugs in your code.

However, it is also useful to know the essentials required to create a Windows-based application using the command line in case you are ever working on a machine without Visual Studio and want to create a quick utility to automate some task or get input from a user. In order to build a WPF application from the command line, you must use the MSBuild tool—see the MSBuild reference in the .NET Framework documentation.

How It Works

Building an application that provides a simple Windows GUI is a world away from developing a fullfledged Windows-based application. However, you must perform certain tasks regardless of whether you are writing the Windows equivalent of Hello World or the next version of Microsoft Word, including the following:

• For each form you need in your application, create a class that extends the System.Windows.Forms.Form class.

• In each of your form classes, declare members that represent the controls that will be on that form, such as buttons, labels, lists, and text boxes. These members should be declared private or at least protected so that other program elements cannot access them directly. If you need to expose the methods or properties of these controls, implement the necessary members in your form class, providing indirect and controlled access to the contained controls.

• Declare methods in your form class that will handle events raised by the controls contained by the form, such as button clicks or key presses when a text box is the active control. These methods should be private or protected and follow the standard .NET event pattern (described in recipe 13-11). It’s in these methods (or methods called by these methods) where you will define the bulk of your application’s functionality.

• Declare a constructor for your form class that instantiates each of the form’s controls and configures their initial state (size, color, position, content, and so on). The constructor should also wire up the appropriate event handler methods of your class to the events of each control.
• Declare a static method named Main—usually as a member of your application’s main form class. This method is the entry point for your application, and it can have the same signatures as those mentioned in recipe 1-1.

In the Main method, call Application.EnableVisualStyles to allow Windows theme support, create an instance of your application’s main form, and pass it as an argument to the static Application.Run method. The Run method makes your main form visible and starts a standard Windows message loop on the current thread, which passes the user input (key presses, mouse clicks, and so on) to your application form as events."


Allen Jones has more than 15 years of experience covering a wide range of information technology disciplines in a variety of sectors; however, his true passion has always been software development. Allen is chief architect at SmithBayes, a U.K.-based software firm that develops high-end strategic decision support software derived from technology used in Formula 1 motor racing.



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.