Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Windows Development  »  Creating controls that resemble the Microsoft control suite. 2 - FlatControl.
Creating controls that resemble the Microsoft control suite. 2 - FlatControl.
by Steven Sartain | Published  10/18/2001 | Windows Development | Rating:
Steven Sartain

Steven Sartain is a consultant currently designing and leading a VB.NET project using n-tier architecture and WebServices for Accuride International Ltd.

During his 8 year career as a developer and development lead, Steve has designed and implemented a diverse number of mission critical software solutions using VB, VBA, MS Access, C/C++, ASP, Delphi, DCOM & MTS, SQL Server, Oracle, SQL Anywhere and others. See his Resume for details.

He is also a Director of Iridium Software - a UK based bespoke software development house.

Steve is always open to take over a challenging programming opportunity. If you experience a need for a professional consultant who has all the necessary skills to take a proposition from first client meeting through to profitably and elegantly completed projects; I'm sure Steve could assist. See his Resume and Professional Statement for details.

 

View all articles by Steven Sartain...
Creating controls that resemble the Microsoft control suite. 2 - FlatControl.

Control source code: FlatControl.vb

Required Files: modApi.vb

Whether you are new to VB or a VB Guru, most of us are new to .NET and are still finding our feet. I will start my development guide by introducing the development of a "base" control that all the flat style controls can and will be inherited from.

FlatControl

The FlatControl will allow us to emulate the common GUI of all the new flat style Microsoft controls. Rather that offer the controls code in its entirety at this point I will introduce sections and explain them in detail. Before that, an object of this type needs Methods, Events and Properties that are exposed to the outside world, internally and privately. These are detailed below for reference.

Properties

NameScope / descriptors
RotationPublic
EnabledPublic Shadows
LightBackColorBrushPublic Overridable ReadOnly
BackColorPublic Overridable Shadows
IsMouseInFriend
IsMouseDownFriend Overridable
TooltipPublic
ShowHighlightLineFriend ReadOnly
CanDockVerticallyPublic
ClickRegionPublic
PaintRegionPublic
MaximumSizeFriend
MinimumSizeFriend
HasKeyFocusFriend
ControlKeyPreviewPublic

Events

NameScope / descriptors
ClickPublic
OnKeyFocusPublic

Methods

NameScope / descriptors
PerformClickPublic
FlatControl_PaintPrivate
FillDisabledRectPublic
FlatControl_MouseLeavePrivate
ControlEnteredPrivate
FlatControl_MouseEnterPrivate
FlatControl_MouseDownPrivate
FlatControl_MouseUpPrivate
IsParentToolbarPrivate
WndProcProtected Overrides
DrawDropDownArrowPrivate
FlatControl_SizeChangedPrivate
IsMouseInClickRegionPrivate
IsMouseInControlPublic
ResetPaintRegionPublic
ResetClickRegionPublic
FlatControl_GotFocusPrivate
FlatControl_LostFocusPrivate
RaiseMessagesPublic
SetHandlersPrivate
FlatControl_KeyDownPrivate
FlatControl_KeyUpPrivate

Enumerations

NameScope / descriptors
RotationEnumPublic
DrawDropDownArrowPositionPublic

I will move on to explain the new .NET features used within the simple base control before offering the complete, well-commented source. I will not go into great detail about the use of the language - that is after all what the documentation is for. I will give simple explanations, my understandings of the reasons and perhaps any lessons learnt.

Imports

The imports statement basically allows us to shortcut our coding. Rather than have to enter "System.Windows.Forms.Form" every time we are required to create a form object we can enter 'Imports System.Windows.Forms' in the header of our code section and then declare a form object by simply 'Dim x as New Form'.

Attributes

The code detailed later uses attributes to define default values against properties and methods. Attributes can be used to assign descriptions, categories, and various other useful information. The documentation at the release of this article is very thin with reference to attributes, although one misleading section referring to 'DefaultValue', I feel should be clarified. Whilst you can assign a 'DefaultValue' using an attribute to a property - this does not initialise the property to this value. If you require the property initialising then the preferred approach is to initialise the value within the objects New() method. The 'DefaultValue' attribute allows the developer the ability to return a property to its 'DefaultValue' - the can be performed with right-clicking the property in the property pane at design time and selecting "Reset".

In order to use the code I had the following Imports defined within my project:

  • Microsoft.VisualBasic
  • System
  • System.Collections
  • System.Configuration
  • System.Data
  • System.Diagnostics
  • System.Drawing

Control source code: FlatControl.vb

Required Files: modApi.vb

To be continued ...

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:2.85714285714286 out of 5
 21 people have rated this page
Article Score19813
Sponsored Links