- •Table of Contents
- •C# and the .NET Platform, Second Edition
- •Introduction
- •Part One: Introducing C# and the .NET Platform
- •Part Two: The C# Programming Language
- •Part Three: Programming with .NET Assemblies
- •Part Four: Leveraging the .NET Libraries
- •Part Five: Web Applications and XML Web Services
- •Obtaining This Book's Source Code
- •The .NET Solution
- •What C# Brings to the Table
- •The Role of the Assembly Manifest
- •Summary
- •Chapter 2: Building C# Applications
- •Summary
- •Chapter 3: C# Language Fundamentals
- •Defining Program Constants
- •Defining Custom Class Methods
- •C# Enumerations
- •Summary
- •The Second Pillar: C#'s Inheritance Support
- •Summary
- •Catching Exceptions
- •Finalizing a Type
- •Garbage Collection Optimizations
- •Summary
- •Chapter 6: Interfaces and Collections
- •Building Comparable Objects (IComparable)
- •Summary
- •Summary
- •Internal Representation of Type Indexers
- •Summary
- •An Overview of .NET Assemblies
- •Understanding Delayed Signing
- •Using a Shared Assembly
- •GAC Internals
- •Summary
- •Spawning Secondary Threads
- •A More Elaborate Threading Example
- •Summary
- •Summary
- •Object Persistence in the .NET Framework
- •The .NET Remoting Namespaces
- •Understanding the .NET Remoting Framework
- •All Together Now!
- •Terms of the .NET Remoting Trade
- •Testing the Remoting Application
- •Revisiting the Activation Mode of WKO Types
- •Deploying the Server to a Remote Machine
- •Summary
- •Control Events
- •The Form Class
- •Summary
- •Regarding the Disposal of System.Drawing Types
- •Understanding the Graphics Class
- •Summary
- •The TextBox Control
- •Working with Panel Controls
- •Configuring a Control's Anchoring Behavior
- •Summary
- •Chapter 16: The System.IO Namespace
- •The Static Members of the Directory Class
- •The Abstract Stream Class
- •Summary
- •The Role of ADO.NET Data Providers
- •The Types of System.Data
- •Selecting a Data Provider
- •The Types of the System.Data.OleDb Namespace
- •Working with the OleDbDataReader
- •Summary
- •Submitting the Form Data (GET and POST)
- •Some Benefits of ASP.NET
- •Creating an ASP.NET Web Application by Hand
- •The Composition of an ASP.NET Page
- •The Derivation of an ASP.NET Page
Working with Panel Controls |
|
C# and the .NET Platf rm, Second Edition |
|
by Andrew Troelsen |
ISBN:1590590554 |
As you have seen earlier in this chapter, the GroupBox control can be used to logically bind a number of
Apress © 2003 (1200 pages)
controls (such as RadioButtons) to function as a collective. Closely related to the GroupBox is the Panel
This comprehensive text starts with a brief overview of the
control. Panels areC#alsolangusedage andto groupthen quicklyrelatedmcontrolsves to inkeya logicaltechnicalunitand. One difference is that the Panel type derives fromarchitethe ScrollableControltural issues for .class,NET developersand thus.it can support scroll bars, which is not possible with a GroupBox.
TablePanelsof Cocantentsbe used to conserve screen real estate. For example, if you have a group of controls that take C#upandthetheentire.NETbottomPlatform,halfSecondof a Form,Editionyou can contain them in a Panel that is half the size and set the IntroductiAutoScrolln property to true. In this way, the user can use the scroll bar(s) to view the hidden items. To
illustrate, let's update the previous TrackBar application. This time, each TrackBar is contained in a single
Part One - Introducing C# and the .NET Platform
Panel.Figure 15-17 shows the update.
Chapter 1 - The Philosophy of .NET
Chapter 2 - Building C# Applications
Part
Chapter |
|
Chapter |
C# |
Chapter |
|
Chapter |
|
Chapter |
Events |
Chapter |
Techniques |
Part |
|
Chapter |
|
Chapter |
and Threads |
Chapter |
Attribute-Based Programming |
Figure 15-17: Working with Panel types
Part Four - Leveraging the .NET Libraries
Chapter 12 - Object Serialization and the .NET Remoting Layer
The underlying code looks almost identical to that of manipulating a GroupBox. Begin by declaring a Panel
Chapter 13 - Building a Better Window (Introducing Windows Forms)
data member (panel1) and add each item using the Controls property, as shown here:
Chapter 14 - A Better Painting Framework (GDI+)
Chapter 15 - Programming with Windows Forms Controls
// Configure the panel.
Chapter 16 - The System.IO Namespace panel1.AutoScroll = true;
Chapter 17 - Data Access with ADO.NET panel1.Controls.Add (this.label2);
Part Five - Web Applications and XML Web Services
panel1.Controls.Add (this.blueTrackBar);
Chapter 18 - ASP.NET Web Pages and Web Controls panel1.Controls.Add (this.label3);
Chapter 19 - ASP.NET Web Applications panel1.Controls.Add (this.greenTrackBar);
Chapter 20 - XML Web Services panel1.Controls.Add (this.redTrackBar);
Index
panel1.Controls.Add (this.label1);
List of Figures
List of Tables
SOURCE The Tracker application can be found under the Chapter 15 directory.
CODE
The UpDownC# andControls:the .NET PlatforDomainUpDown, Second Edition and NumericUpDown
by Andrew Troelsen |
ISBN:1590590554 |
Windows Forms provide two widgets that function as spin controls (also known as up/down controls). Like
Apress © 2003 (1200 pages)
the ComboBox and ListBox types, these new items also allow the user to choose an item from a range of
This comprehensive text starts with a brief overview of the
possible selectionsC#. Thelanguagedifferenceand thenis thatquicklywhenmovesusingtoakeyDomainUpDowntechnical and or NumericUpDown control, the information is selectedarchitecturalusing aissmallues forpair.NETof updevelopersand down. arrows. For example, check out Figure 15-18.
Table
C# and
Part
Chapter
Chapter
Part
Chapter 3 - C# Language Fundamentals
Figure 15-18: Working with UpDown types
Chapter 4 - Object-Oriented Programming with C#
ChapterGiven your5 -workExceptionswith previousand Object(andLifetimesimilar) types, you should find working with the UpDown widgets Chpainlesspter 6. The- InterfacesDomainUpDownand Collectionswidget allows the user to select from a set of string data. NumericUpDown
allows selections from a range of numeric data points. Each widget derives from a common direct base
Chapter 7 - Callback Interfaces, Delegat s, and Events
class: UpDownBase. Table 15-10 describes some important properties of this class.
Chapter 8 - Advanced C# Type Construction Techniques
Part Three - Programming with .NET Assemblies
Table 15-10: UpDownBase Properties
Chapter 9 - Understanding .NET Assemblies
|
|
|
|
|
|
|
|
|
Chapter 10 - Processes, AppDomains, Contexts, and Threads |
|
|
||||
|
|
UpDownBase |
|
|
Meaning in Life |
|
|
|
Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming |
|
|
||||
|
|
Property |
|
|
|
|
|
Part Four - Leveraging the |
.NET Libraries |
|
|
||||
|
|||||||
ChapterInterceptArrowKeys12 - Object SerializationGetsandor thesets.NETa valueRemotingindicatingLayerwhether the user can use the Up Arrow |
|
|
|||||
|
Chapter 13 - Building a BetterandWindowDown(IntroducingArrow keysWindowsto selectForms)values |
|
|
||||
|
|
|
|
|
|||
|
|
Chapter 14 - A Better Painting |
|
|
Framework (GDI+) |
|
|
|
|
ReadOnly |
|
|
Gets or sets a value indicating whether the text can only be changed by |
|
|
|
Chapter 15 - Programming |
with Windows Forms Controls |
|
|
|||
|
|
|
|
|
the use of the up or down arrows and not by typing in the control to |
|
|
|
Chapter 16 - The System.IO |
Namespace |
|
|
|||
|
|
|
|
|
locate a given string |
|
|
|
|
|
|
|
|||
|
|
Chapter 17 - Data Access with ADO.NET |
|
|
|||
|
|
Text |
|
|
Gets or sets the current text displayed in the spin control |
|
|
Part Five - Web Applications |
|
and XML Web Services |
|
|
|||
|
|
Chapter 18 - ASP.NET Web |
|
Pag and Web Controls |
|
|
|
|
|
TextAlign |
|
|
Gets or sets the alignment of the text in the spin control |
|
|
|
|
|
|
|
|
||
|
|
Chapter 19 - ASP.NET Web |
|
|
Applications |
|
|
|
|
UpDownAlign |
|
|
Gets or sets the alignment of the up and down arrows on the spin |
|
|
|
Chapter 20 - XML Web Services |
|
|
||||
|
Index |
|
|
control, using the LeftRightAlignment enumeration |
|
|
|
|
|
|
|
|
|
List of Figures
The DomainUpDown control adds a small set of properties (Table 15-11) that allow you to configure and
List of Tables
manipulate the textual data in the widget.
Table 15-11: DomainUpDown Properties
|
|
|
|
|
|
DomainUpDown |
|
Meaning in Life |
|
|
Property |
|
|
|
|
|
|
|
|
|
Items |
|
Allows you to gain access to the set of types stored in the widget |
|
|
|
|
|
|
|
SelectedIndex |
|
Returns the zero-based index of the currently selected item |
|
|
|
|
|
|
|
SelectedItem |
|
Returns the selected item itself (not its index) |
|
|
|
|
|
|
|
Sorted |
|
Configures whether or not the strings should be alphabetized |
|
|
|
|
|
|
|
Wrap |
|
Controls if the collection of items continues to the first or last item if |
|
|
|
|
the user continues past the end of the list |
|
|
|
|
|
|
The NumericUpDown type is just as simple (Table 15-12).
C# and the .NET Platform, Second Edition
|
|
|
by Andrew Troelsen |
ISBN:1590590554 |
||||
Table 15-12: NumericUpDown Properties |
|
|
||||||
|
|
|
Apress © 2003 |
|
|
(1200 pages) |
|
|
|
NumericUpDownThis comprehensiveMeaningtext startsin Lifewith a brief overview of the |
|
||||||
|
Property |
C# language and then quickly moves to key technical and |
|
|||||
|
architectural |
|
issues for .NET developers. |
|
|
|||
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
||
|
DecimalPlaces |
|
|
|
Used to configure how the numerical data is to be displayed. |
|
||
|
ThousandsSeparator |
|
|
|
|
|
||
Table of Contents |
|
|
|
|
|
|
||
|
Hexadecimal |
|
|
|
Edition |
|
|
|
C# and the .NET Platform, Second |
|
|
||||||
|
|
|
|
|
|
|
|
|
|
Introduction |
|
|
|
Sets the numerical value to increment the value in the control when |
|
||
|
Increment |
|
|
|
|
|||
Part One - Introducing C# and |
the .NET Platform |
|
|
|||||
|
|
|
|
|
|
the up or down arrow is clicked. The default is to advance the value |
|
|
Chapter 1 |
- The Philosophy of |
.NET |
|
|
||||
|
|
|
|
|
|
by 1. |
|
|
|
|
|
|
|
|
|||
|
Chapter 2 - Building C# Applications |
|
|
|||||
|
Minimum |
|
|
|
Sets the upper and lower limits of the value in the control. |
|
||
Part Two - The C# Programming Language |
|
|
||||||
ChapterMaximum3 - C# Language Fundamentals |
|
|
||||||
|
|
|
|
|
|
|||
|
Chapter 4 - Object-Oriented |
|
|
Programming with C# |
|
|
||
|
Value |
|
|
|
|
Returns the current value in the control. |
|
|
|
Chapter 5 - Exceptions and Object Lifetime |
|
|
|||||
Chapter 6 - Interfaces and Collections |
|
|
||||||
Here is the code behind the sample application: |
|
|
||||||
Chapter 7 |
- Callback Interfaces, Delegates, and Events |
|
|
Chapter 8 - Advanced C# Type Construction Techniques
// Configure DomainUpDown widget.
Part Three - Programming with .NET Assemblies
domainUpDown.Sorted = true;
Chapter 9 - Understanding .NET Assemblies domainUpDown.Wrap = true;
Chapter 10 - Processes, AppDomains, Contexts, and Threads
domainUpDown.Items.AddRange (new object[4] { "Another Boring String named B",
Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming
"Boring String A", "BORING String C", "Final Boring string (D)"});
Part Four - Leveraging the .NET Libraries |
|
domainUpDown.SelectedIndex = 2; |
|
Chapter 12 |
- Object Serialization and the .NET Remoting Layer |
// Configure NumericUpDown widget. |
|
Chapter 13 |
- Building a Better Window (Introducing Windows Forms) |
numericUpDown.Maximum = new decimal (5000); |
|
Chapt r 14 |
- A Better Painting Fram work (GDI+) |
numericUpDown.ThousandsSeparator = true; |
|
Chapt 15 |
- Pr gramming with Windows Forms Controls |
numericUpDown.UpDownAlign = LeftRightAlignment.Left; |
|
Chapter 16 |
- The System.IO Namespace |
Chapter 17 |
- Data Access with ADO.NET |
Part Five - Web Applications and XML Web Services
The Click event handler for the Form's Button type simply asks each type for its current value and places it
Chapter 18 - ASP.NET Web Pages and Web Controls
in the appropriate Label as a formatted string, as shown here:
Chapter 19 - ASP.NET Web Applications
Chapter 20 - XML Web Services
protected void btnGetSelections_Click (object sender, System.EventArgs e)
Index
{
List of Figures
// Get info from updowns...
List of Tables lblCurrSel.Text =
string.Format("String: {0}\nNumber: {1}", domainUpDown.Text, numericUpDown.Value);
}
Of course, the DomainUpDown and NumericUpDown types support a number of events. If you ever need to capture when the selection changes, you can use SelectedItemChanged (for DomainUpDown types) or ValueChanged (for NumericUpDown types). Here is an example:
// Intercept the SelectedItemChanged event.
domainUpDown.SelectedItemChanged
+= new EventHandler (domainUpDown_SelectedItemChanged);
...
// Handle the event.
protected void domainUpDown_SelectedItemChanged (object sender,
|
C# and the .NET Platform, Second Edition |
System.EventArgs e) |
{ |
by Andrew Troelsen |
ISBN:1590590554 |
|
|
Apress © 2003 (1200 pages)
this.Text = "You changed the string value...";
}This comprehensive text starts with a brief overview of the C# language and then quickly moves to key technical and architectural issues for .NET developers.
SOURCE The UpAndDown application is included under the Chapter 15 directory.
Table of Contents
CODE
C# and the .NET Platform, Second Edition
Introduction
Part One - Introducing C# and the .NET Platform
Chapter 1 - The Philosophy of .NET
Chapter 2 - Building C# Applications
Part Two - The C# Programming Language
Chapter 3 - C# Language Fundamentals
Chapter 4 - Object-Oriented Programming with C#
Chapter 5 - Exceptions and Object Lifetime
Chapter 6 - Interfaces and Collections
Chapter 7 - Callback Interfaces, Delegates, and Events
Chapter 8 - Advanced C# Type Construction Techniques
Part Three - Programming with .NET Assemblies
Chapter 9 - Understanding .NET Assemblies
Chapter 10 - Processes, AppDomains, Contexts, and Threads
Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming
Part Four - Leveraging the .NET Libraries
Chapter 12 - Object Serialization and the .NET Remoting Layer
Chapter 13 - Building a Better Window (Introducing Windows Forms)
Chapter 14 - A Better Painting Framework (GDI+)
Chapter 15 - Programming with Windows Forms Controls
Chapter 16 - The System.IO Namespace
Chapter 17 - Data Access with ADO.NET
Part Five - Web Applications and XML Web Services
Chapter 18 - ASP.NET Web Pages and Web Controls
Chapter 19 - ASP.NET Web Applications
Chapter 20 - XML Web Services
Index
List of Figures
List of Tables
Working withC# andthetheErrorProvider.NET latform, Second Edition
by Andrew Troelsen |
ISBN:1590590554 |
Most Windows Forms applications will need to validate user input in one way or another. This is especially
Apress © 2003 (1200 pages)
true with dialog boxes, as you should inform users if they make a processing error before continuing
This comprehensive text starts with a brief overview of the forward. (I'll examineC# languagedialog boxandprogrammingthen quickly moveslater intothiskeychaptertechnical.) and
architectural issues for .NET developers.
The ErrorProvider type can be used to provide a visual cue of user input error. For example, assume you have a Form containing a TextBox and Button widget. If the user enters more than five characters in the
TableTextBox,of Contentsthe error information shown in Figure 15-19 is displayed.
C# and the .NET Platform, Second Edition
Introduction
Part
Chapter
Chapter
Part
Chapter
ChapterFigure4 - 15Object-19:-TheOri ntedErrorProviderProgrammingactionw th C#
Chapter 5 - Exceptions and Object Lifetime
Chapter 6 - Interfaces and Collections
Here, you have detected that the user entered more than five characters and responded by placing a
Chapter 7 - Callback Interfaces, Delegates, and Events
small error icon (!) next to the TextBox object. When the user places the cursor over this icon, the
Chapter 8 - Advanced C# Type Construction Techniques
descriptive error text appears as a pop-up. Also, this ErrorProvider is configured to cause the icon to blink
Part Three - Programming with .NET Assemblies
a number of times to strengthen the visual cue (which, of course, you can't see without running the
Chapter 9 - Understanding .NET Assemblies application).
Chapter 10 - Processes, AppDomains, Contexts, and Threads
ChapterIf you wish11 -toTypesupportReflection,this typeLateofBinding,input validation,and Attributethe first-BasedstepProgrammingis to understand the properties of the
PartControlFourclass- Leveraging(Table 15the-13.NET). Libraries
Chapter 12 - Object Serialization and the .NET Remoting Layer
Table 15-13: Control Properties
Ch pter 13 - Buildi g a Better Window (Introducing Windows Forms)
Chapter 14 - A Better Painting Framework (GDI+)
Control Meaning in Life
Chapter 15 - Programming with Windows Forms Controls
Property
Chapter 16 - The System.IO Namespace
ChapterCausesValidation17 - Data Access withIndicatesADO.NETwhether selecting this control causes validation on the controls |
|||||
Part Five - Web Applicationsrequiringand XML WebvalidationServices |
|||||
|
|
|
|
|
|
|
Chapter 18 |
- ASP.NET Web |
|
Pages and Web Controls |
|
|
Validated |
|
Occurs when the control is finished performing its validation logic |
|
|
|
Chapter 19 |
- ASP.NET Web |
|
Applications |
|
|
|
|
|||
|
ChapterValidating20 - XML Web ServicesOccurs when the control is validating user input (e.g., when the control |
|
|||
Index |
|
|
loses focus) |
|
|
|
|
|
|
|
|
List of Figures
Every GUI widget can set the CausesValidation property to true or false. (The default is false.) If you set
List of Tables
this bit of state data to true, the control forces the other controls on the Form to validate themselves when it receives focus (provided the CausesValidation property is also set to true).
Once a validating control has received focus, the Validating and Validated events are fired for each control. It is in the scope of the Validating event handler in which you configure a corresponding ErrorProvider. Optionally, the Validated event can be handled to determine when the control has finished its validation cycle.
To begin, assume you have set the CausesValidation property to true for the Button and TextBox and have added a member variable of type ErrorProvider. Here is the configuration code:
// Configure the error provider.
errorProvider1.DataMember = "";
errorProvider1.DataSource = null;
errorProvider1.ContainerControl = null;
errorProvider1.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.AlwaysBlink;
errorProvider1.BlinkRate = 500;
C# and the .NET Platform, Second Edition
by Andrew Troelsen |
ISBN:1590590554 |
The ErrorProviderApresstype has© 2003a small(1200 pages)set of members. The most important item for your purposes is the BlinkStyle property,Thiswhichcomprehensivecan be settextto anystartsof thewithvaluesbriefofoverviewthe ErrorBlinkStyleof the enumeration described in Table 15-14. C# language and then quickly moves to key technical and
architectural issues for .NET developers.
Table 15-14: ErrorBlinkStyle Properties
|
|
|
|
|
|
Table of Contents |
|
|
Meaning in Life |
|
|
|
ErrorBlinkStyle |
|
|
|
|
C#Propertyand the .NET Platform, Second |
Edition |
|
|||
|
|
|
|
|
|
|
Introduction |
|
|
Causes the error icon to blink when the error is first displayed or |
|
|
AlwaysBlink |
|
|
|
|
Part One - Introducing C# and |
|
the .NET Platform |
|
||
Chapter 1 - The Philosophy of |
|
|
when a new error description string is set for the control and the |
|
|
|
.NET |
|
|||
|
|
|
|
error icon is already displayed |
|
|
Chapter 2 - Building C# Applications |
|
|||
|
|
||||
Part Two - The C# Pr gramming Language |
|
||||
|
BlinkIfDifferentError |
|
|
Causes the error icon to blink only if the error icon is already |
|
Chapter 3 - C# Language Fundamentdisplayed,ls but a new error string is set for the control |
|
||||
|
|
|
|
|
|
|
Chapter 4 - Object-Oriented |
|
Programming with C# |
|
|
|
NeverBlink |
|
|
Indicates the error icon never blinks |
|
Chapter 5 - Exceptions and Object Lifetime
Chapter 6 - Interfaces and Collections
The ErrorProvider also has additional members beyond BlinkStyle and BlinkRate. For example, if you wish
Chapter 7 - Callback Interfaces, Delegates, and Events
to associate a custom icon to the error, you can do so using the Icon property. Nevertheless, once you
Chapter 8 - Advanced C# Type Construction Techniques
have configured how the ErrorProvider looks and feels, you bind the error to the TextBox within the scope
Part Three - Programming with .NET Assemblies
of its Validating event handler, as shown here:
Chapter 9 - Understanding .NET Assemblies
Chapter 10 - Processes, AppDomains, Contexts, and Threads
protected void txtInput_Validating (object sender, CancelEventArgs e)
Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming
{
Part Four - Leveraging the .NET Libraries
// Check if the text length is greater than 5.
Chapter 12 - Object Serialization and the .NET Remoting Layer if(txtInput.Text.Length > 5)
Chapter 13 - Building a Better Window (Introducing Windows Forms)
{
Chapter 14 - A Better Painting Framework (GDI+)
errorProvider1.SetError(txtInput, "Can't be greater than 5!");
Chapter 15 - Programming with Windows Forms Controls
}
Chapter else16 - The//SystemThings.IO NaremespaceOK, don't show anything.
Chapter 17 - DataerrorProvider1Access w th ADO..SetError(txtInput,NET "");
Part} Five - Web Applications and XML Web Services
Chapter 18 - ASP.NET Web Pages and Web Controls
Chapter 19 - ASP.NET Web Applications
Chapter 20 - XML Web Services
SOURCE The ErrorProvider application is included under the Chapter 15 directory.
Index
CODE
List of Figures
List of Tables