Home > C# > Custom controls design & testing…

Custom controls design & testing…


For a former Delphi-ist like me, creating custom components was almost an everyday routine, but after switching to more modern & versatile enviroments like C# (VS2010) I’ve found myself lost in the docs & lack of knowledge about such important thing.

However, things are easier than they appear to be.
There is one strange dead-end, called User Controls – well, it is nothing else but a control made of other controls – it is group of controls compiled under one typename…
To create & test your own custom control, you should extend already existing class (like System.Windows.Forms.Control or System.Windows.Forms.Button… etc.)

Suppose, you’re working on an application, and you wan’t to use a new control (e.g. slightly modified MaskedTextBox), follow this route :
1. In your app solution create another class (Add… / Class, Shift+Alt+C)
2. Name it as you want, like MyMaskEdit.cs
3. use your app namespace, or another else (remember to add appropriate usings
4. change the default declaration of your newly created class to something like :


namespace A
{
namespace B
{
[System.ComponentModel.DefaultBindingProperty("Time")]
public class DBTimeEdit : System.Windows.Forms.MaskedTextBox
{
...
}
}
}

Advertisements
Categories: C#
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: