: Allen Jones, Matthew MacDonald, Rakesh Rajan, Adam Freeman
: Visual C# 2010 Recipes A Problem-Solution Approach
: Apress
: 9781430225263
: 1
: CHF 60.60
:
: Allgemeines, Lexika
: English
: 1016
: Wasserzeichen/DRM
: PC/MAC/eReader/Tablet
: PDF

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.



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.
"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."
Index 333
796333
Problem796
Solution796
How It Works796
The Code796
CHAPTER 17 Windows Presentation Foundation801
17-1. Create and Use a Dependency Property802
Problem802
Solution802
How It Works803
The Code805
17-2. Create and Use an Attached Property807
Problem807
Solution808
How It Works808
The Code808
17-3. Define Application-Wide Resources811
Problem811
Solution811
How It Works811
The Code812
17-4. Debug Data Bindings Using an IValueConverter813
Problem813
Solution813
How It Works813
The Code813
17-5. Debug Bindings Using Attached Properties815
Problem815
Solution815
How It Works816
The Code817
17-6. Arrange UI Elements in a Horizontal or Vertical Stack817
Problem817
Solution817
How It Works817
The Code818
17-7. Dock UI Elements to the Edges of a Form819
Problem819
Solution819
How It Works820
The Code820
17-8. Arrange UI Elements in a Grid821
Problem821
Solution821
How It Works822
The Code822
17-9. Position UI Elements Using Exact Coordinates823
Problem823
Solution824
How It Works824
The Code824
17-10. Get Rich Text Input from a User825
Problem825
Solution825
How It Works825
The Code827
17-11. Display a Control Rotated830
Problem830
Solution830
How It Works830
The Code830
17-12. Create a User Control832
Problem832
Solution832
How It Works833
The Code833
17-13. Support Application Commands in a User Control834
Problem834
Solution835
How It Works835
The Code835
17-14. Create a Lookless Custom Control838
Problem838
Solution839
How It Works839
The Code841
17-15. Create a Two-Way Binding845
Problem845
Solution845
How It Works845
The Code847
17-16. Bind to a Command848
Problem848
Solution848
How It Works848
The Code849
17-17. Use Data Templates to Display Bound Data856
Problem856
Solution856
How It Works856
The Code857
17-18. Bind to a Collection with the Master-Detail Pattern860
Problem860
Solution860
How It Works860
The Code861
17-19. Change a Control’s Appearance on Mouseover866
Problem866
Solution866
How It Works867