MWLabels and MWScrolllabels v3.0

MWLabels and MWScrollLabels are back (v3.0). This time you can choose which StringFormat you want to use: traditional GenericDefault or GenericTypographic. GenericDefault is like a normal Label and GenericTypographic is what has been used in the previous versions of MWLabel and MWScrollLabel.

More importantly you can also choose which direction you want the text to flow (TextDir property).

The TextDir property employs a graphical Design Time Editor imheriting from UITypeEditor where you can select which Text Direction you want to use in a graphical user interface. The Visual Studio Property Window also graphically displays which Text Direction has been selected by painting an 'A' in the Text Direction selected. Note that you can right-click in the TextDir UI - this allows you to change the Text Direction without the TextDir UI closing.

Note that the above mentioned changes have been made both to MWLabel and MWScrollLabel.

Important coding aspects used:

GDI+
Inheritance
Overriding EventHandlers
Custom EventArgs
Design Time enhancements
Graphical string manipulation
Timers
UI

The Visual Studio Solution contains three Projects:

MWCommon

This Project contains a class which includes a few methods for measuring strings.
Included are also two classes inheriting from EventArgs these are used to pass a bit more information than plain EventArgs when Events are raised.
There is also a class called MWEnums which contains the StringFormat enum and the TextDir enum.

MWControls

This Project contains the MWLabel and MWScrollLabel classes.
You can also find the EditorTextDir and EditorTextDirUI classes which are used by Visual Studio at Design Time to allow custom painting of the TextDir property in the Visual Studio Properties Window.

MWControlsTest

This Project contains a Windows Forms application that can be used (it's what I used) for testing the MWLabel and MWScrollLabel classes.

In order to build this Solution the MWCommon Project has to be built first, then the MWControls Project and last the MWControlsTest Project.

During the process of creating these classes I have noticed that Visual Studio doesn't like having enums employed in a UI in the Visual Studio Properties Window. There are a lot of problems where Visual Studio complains and says (when you try to change the TextDir property at Design Time) that types do not match. I tried changing the Solution into using ints (integers) instead of the TextDir enum - and voila, Visual Studio had no trouble 'converting' types. This problem is most prominent when the TextDir enum resided in the MWControls namespace. When moved into the MWCommon namespace it works ninety percent of the time.
If for some reason it does not work try this:

  • Open the Solution.
  • Build the MWCommon Project (ONLY this Project).
  • Close Visual Studio.
  • Open Visual Studio and build the MWControls Project (ONLY this Project).
  • Close Visual Studio.
  • Open Visual Studio and build the MWControlsTest Project (ONLY this Project).
  • Close Visual Studio.
  • Open Visual Studio and it should all work.

Something else that would probably also work is changing the AssemblyVersion in the AssemblyInfo.cs file of the MWCommon Project. Change it from '[assembly: AssemblyVersion("1.0.*")]' to '[assembly: AssemblyVersion("1.0.0.0")]'.

Once you get all this working and the classes are in their respective DLLs and are not built all the time for the Projects you are working on but rather just referenced (DLL referenced), there should be no hassles.

Please feel free to drop me a line if you know how to get rid of these hassles or just to confirm that the AssemblyVersion solution would work - always.

Yet again pretty simple stuff (except the hassles with Visual Studio's Property Window and enums in a Custom UI Designer). A days work or thereabouts.


Similar Articles