Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 8 comments about this article.
Article source: CoDe (2003 - Jan/Feb)


Article Pages:  1  2 3 - Next >


Working with Extender Classes

Extender classes do just that; they allow you to extend the functionality of a .NET control class. The Error Provider and Tooltip classes are two examples of extender classes in the .NET Framework. The Tooltip class represents a significant departure from how tooltips were implemented in earlier versions of Visual Studio. The Error Provider class provides a new way to inform users about invalid input. Although each class serves a different purpose, their implementation is quite similar. This article introduces these two classes and gives a brief, yet comprehensive primer on how to use them.

Tooltip Class

Implementing tooltips in Visual Basic 6 was easy. You simply set the Form's ShowTips property to True and set the ToolTipText property of each control on the form to the desired string setting. Visual Studio .NET has taken this procedure and turned it on its ear. Is it a better design? I don't know. I will reserve judgment on the issue and I will instead help you intelligently add tooltips to your .NET controls.

"
If you're like me you'll instinctively look for properties like ToolTip Text and ShowTips. However, those properties don't exist in .NET.
"

If you are like me you will instinctively look for properties like ToolTipText and ShowTips. However, these properties don't exist in .NET. Instead, there is a class devoted to this singular task called the Tooltip class. Instead of setting properties on the control you implement the Tooltip class and through various property settings, you inform the Tooltip class of the control's existence. The basic steps are:

  1. From the toolbox, select the Tooltip class.
  2. Drag the Tooltip class to the form.
  3. Drop the Tooltip class onto the form.

Figure 1 shows you how to implement the Tooltip class in an application.

Click for a larger version of this image.

Figure 1: Non visual classes like the Tooltip class, while members of the form, are not located on the form's design surface.

#1: Once you've added the Tooltip class you can put it to work. Tooltips get displayed whenever you position the mouse pointer over a control for a few moments. In Visual Basic 6 you didn't need to worry about trapping events since VB 6 handled everything automatically. In Visual Studio .NET this is not the case. The following snippet illustrates the code you might add to the Command Button's MouseHover event:

Private Sub Button1_MouseHover(_ 
 ByVal sender As Object,_
 ByVal As System.EventArgs)_
 Handles Button1.MouseHover
        Me.ToolTip1.SetToolTip(_
 Me.Button1, "This button will validate"+_
   the controls and check for errors")
  End Sub

The code is straightforward. When the user positions the mouse pointer over the control, the control sends a SetToolTip message to the ToolTip object; sending a reference to itself as well as the text that it should display. Figure 2 illustrates how the tooltip appears at runtime.

Click for a larger version of this image.

Figure 2: The Tooltip class is an extender class because it extends the functionality of another control.

While adding tooltips are simple, it does seem as through developers are taking a step backward. Setting properties in Visual Basic 6, in this author's opinion, is more straightforward and simple. .NET's way of implementing tooltips appears to add more work with little benefit in return. In preparing this article I wondered if there was a simple way to achieve the ease of the past. Then it dawned on me?what about OOP? Specifically, why not subclass the .NET textbox and outfit it with the tooltip functionality? Then, when I want tooltips I can simply add the textbox and set a property; just like in the good old days!

&

By: John V. Petersen

John Petersen has been developing software for over 20 years. It all started when, as a staff accountant, he was asked to get involved in a system upgrade to replace an old IBM Series 1 computer (about the size of a large refrigerator!). Those first programs were written in Clipper, Summer 87. Since that time, John’s tools included dBase, FoxBase, Visual FoxPro and Visual Basic. An early adopter of .NET, he then decided to go to law school. After practicing law for a few years, John realized that technology was a lot more interesting than the law. Today, John focuses on ASP.NET development and is having more fun than ever solving business problems for clients. John is a Practice Director for Custom Application Development at Neudesic, a Microsoft Gold Partner and the Trusted Technology Partner in Business Innovation. A 9-time recipient of Microsoft’s Most Valuable Professional Award, John is a current ASP.NET/IIS MVP. John is also an ASP Insider and is the INETA Mentor for PA and WV. John is the author of several books and is a frequent contributor to CODE Magazine and DevPro magazine. John holds a BS in Business Administration from Mansfield University, an MBA in Information Systems from St. Joseph’s University and a JD from the Rutgers School of Law – Camden.

email: johnvpetersen@gmail.com

blog: codebetter.com/johnvpetersen

twitter: @johnvpetersen

john.v.petersen@comcast.net

Fast Facts

In Visual Basic 6 you didn't need to worry about trapping events since VB6 handled everything automatically. In Visual Studio .NET this is not the case.



Article Pages:  1  2 3 - Next Page: '#2: Classing Things Up' >>

Page 1: Working with Extender Classes
Page 2: #2: Classing Things Up
Page 3: #3: Error Providing Class

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.5 out of 5

68 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      LearnNow

 

SSWUG