posts from 2002

WinForms AcceptButton Extender

By Fons Sonnemans, 1-12-2002



The System.Windows.Forms.Form class has an AcceptButton property which can be used to set the button on the form that is clicked when the user presses the ENTER key. The accept (default) button should be the button that represents the action that the user is most likely to perform if that action isn't potentially dangerous. This button has a dark border to let the user know that it is the accept button.

This feature works great only when you have one accept button. Have a look at the following diaglog.

The OK button is in this dialog the accept button. This is the correct behavior when the textbox 'Name' and datepicker 'Date' have the focus. There should not be an accept button when the (multiline) textbox 'Description' has the focus. When listbox 'Avialiable' has the focus the '> Add >' button must be the accept button. And when listbox 'Assigned' has the focus the '> Add >' button must be the accept button.

This can be accomplished by implementing the following Enter and Leave event handlers.

private void textBoxDescription_Enter ( object sender , System.EventArgs e) {
    this.AcceptButton =null;

privatevoid textBoxDescription_Leave(objectsender, System.EventArgs e) {
    this.AcceptButton =buttonOK;

privatevoid listBoxAvailable_Enter(objectsender, System.EventArgs e) {
    this.AcceptButton =buttonAdd;

privatevoid listBoxAvailable_Leave(objectsender, System.EventArgs e) {
    this.AcceptButton =buttonOK;

privatevoid listBoxAssigned_Enter(objectsender, System.EventArgs e) {
    this.AcceptButton =buttonRemove;

privatevoid listBoxAssigned_Leave(objectsender, System.EventArgs e) {
    this.AcceptButton =buttonOK;

But why write code when the same can be accomplished by setting some properties in the designer. The AcceptButton extender class can be used to eliminate this code.

AcceptButton Extender Provider

An extender provider is a component that provides properties to other components. The AcceptButton class implements the IExtenderProvider interface making it an Extender Provider. When you add an AcceptButton control to a Form, all other controls (accept buttons) on the form have the UseDefaultAcceptButton and the AcceptButton property added to their list of properties.

You now only have to set the two properties for each control:

Control UseDefaultAcceptButton property AcceptButton property
textBoxName True (none)
textBoxDescription False (none)
dateTimePickerDate True (none)
listBoxAvailable False buttonAdd
listBoxAssigned False buttonRemove


The AcceptButton class is good example for which you can use Extender Providers. Extender Providers are somewhat strange to write but very powerful. I use them a lot.

Any suggestions and feedback for improving this article is most welcome. Send your suggestions and feedback to

Free 'ASP.NET Slide Menu' Control

By Fons Sonnemans, 27-11-2002

I Have found the greatest menu control for ASP.NET and it is FREE. Check it out on You can easily create very good looking menu's.

Check also their Treeview control.

Tags: Web, ASP.NET

Deck IT WAP Emulator

By Fons Sonnemans, 22-11-2002

I have found a great WAP emulator on PyWeb.

The following Article explains how you can integrate an emulator with Visual Studio.NET.

Tags: Web, ASP.NET

Janus System has released some great .NET controls

By Fons Sonnemans, 22-10-2002

I have used the Janus GridEX control in many of my VB6 projects. It worked perfectly and it is very fast.

I have tested the .NET Trial version, it is even better. This is a component that everybody who is building WinForms application should buy.

Have a look at Janus GridEX Control for .NET and try it yourself.

C# SortCode Macro for Visual Studio.NET 2003

By Fons Sonnemans, 1-10-2002



You should write your code in a consistent style. This is easier said then done. The SortCode macro helps you with this by sorting your C# code.

The SortCode macro sorts all members of a type (class or struct) on alphabetical order grouped by their type.

The default order of the types is:

  • Events
  • Fields
  • Enums
  • Constructor
  • Destructor
  • Properties and Functions
  • Properties and Functions of implemented interfaces

This order can easily be changed by modifying the private class MemberComparer. This class implements the IComparer interface.


Unzip the Zipfile and open the 'ReflectionIT.vsmacros' file. The ReflectionIT macro project will be loaded into the Macro Explorer.

Open a C# sourcefile in the VS.NET editor.

Run the SortCode macro from the CSharp module using the Macro Explorer. You will see that your code is sorted.


Only use the SortCode macro on projects which compile. It uses the Automation and Extensibility Reference (EnvDTE) of Visual Studio.NET. The EnvDTE can only work with CodeElements which are declared correctly.
You can Undo the SortCode macro using the 'Undo' menu option.

Other Macros

The ReflectionIT macro project also contains some other useful macros, for C# and VB.NET. I can imagine that more people have developed useful macros. Please mail them to me so I can extend my macro project.


The SortCode macro can help you organize your code. It demonstrates the power of Visual Studio.NET and the .NET Framework.

Any suggestions and feedback for improving this article is most welcome. Send your suggestions and feedback to

Regular Expressions

By Fons Sonnemans, 6-9-2002

I find Regular Expression powerful but difficult. Eric Gunnerson wrote the Regular Expression Workbench. This makes them easy.

It's a tool to create, test, and study regular expressions with this workbench. With the "Examine-o-matic" feature, hover over the regex to decode what it means

Free .NET tools

By Fons Sonnemans, 25-8-2002
I have found some great .NET tools on

.NET Framework Service Pack 2

By Fons Sonnemans, 9-8-2002
There is a new servicepack for the .NET Framework. Goto .NET Framework Service Pack 2

Balloon Windows for .NET

By Fons Sonnemans, 7-8-2002

I have found a class that allows for balloon shaped forms in .NET.

Have a look at CodeProject.

GotDotNet: Xml WebService Award?

By Fons Sonnemans, 1-8-2002

What happened with the XML WebServices Award on the GotDotNet website? I have submitted my Html2Xml webserivce. I don't expect to win the 25.000 dollar price, an X-box would be nice :-)

The winners would be announced at the Teched in Barcelona (1-5 July 2002). Then this was moved to July 12. It is now August. Nothing has happened. Is there no winner?


Tags: XML, CSharp

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.