Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 42,379 times

Contents

Downloads

Related Categories

RichTextLabel WinForms Control - Wrapping it up in a Control

palom

Wrapping it up in a Control

It's quite boring, error prone work, so I've encapsulated the technique into an easy-to-use control - the RichTextLabel control:

The RichTextLabel control at runtime

The control is intended for reuse in source form . The accompanying solution contains both, the VB.NET version as well as the C# version of the control. The RichTextLabel control exposes just one, all important RtfResourceName property. You'll need to set the property to the name of the RTF text resource you wish to display in the control. Everything else is done automatically.

In order to use the RichTextLabel control within your project, you'll have to follow these steps:

  1. Add the RichTextLabel.vb or RichTextLabel.cs source file to you project and recompile. The RichTextLabel control is derived from UserControl , so it will be added to the Visual Studio .NET toolbox automatically.
  2. Add an RTF file to your project and set its build action to 'Embedded Resource'. You can have the following substitution strings in the file:

    Substitution String Replaced by this property's value
    [Title] AssemblyTitleAttribute.Title
    [Product] AssemblyProductAttribute.Product
    [Copyright] AssemblyCopyrightAttribute.Copyright
    [Company] AssemblyCompanyAttribute.Company
  3. Place the RichTextLabel control onto a Form and set its RtfResourceName property to the name of the RTF file you've added in step 2.

In order to make things easier for you, the RtfResourceName property has an associated type editor ( RtfResourceNameEditor ), which displays a popup list of all the RTF resource files available in the current assembly:

The RichTextLabel control at design-time

In order to keep the RichTextLabel control as small as possible, I've put the type editor in a separate LaMarvin.Windows.Forms.RichTextLabel.Design.dll assembly that needn't be directly referenced by the project containing the RichTextLabel control. If you want to take advantage of the richer design-time support, just copy the LaMarvin.Windows.Forms.RichTextLabel.Design.dll assembly to your project's output directory.

If you'd like to edit the RTF files added to your project comfortably from within the Visual Studio .NET IDE, you might want to associate the .RTF file extension with WordPad. Right-click on any RTF file in the Solution Explorer and select the "Open With..." command. In the Open With dialog box, add WordPad.exe to the list of available programs and set it as the default editor for .RTF files. After that, double-clicking an RTF file in the Solution Explorer will open the file in WordPad automatically.

I live in Slovakia with my wife, two sons (fulltime), one daughter (occasionally) and a dog. I've been doing Microsoft Windows development since 1988; primarily in VB. I'm a big fan of the MS .NET framework, publisher of the www.VBInfoZine.com ezine and the author of the Dynamic AutoComplete Tool .NET component (dact.lamarvin.com).

Comments

  • Re: [4584] RichTextLabel WinForms Control

    Posted by dgauerke on 26 Jul 2006

    I moved the control into a seperate dll (along with the editor), but the editor no longer finds the embedded rtf files in the exe.  When I move the control back into the main application it wo...

  • doubt

    Posted by sherry on 22 Nov 2004

    i have a doubt...
    when we use an input box in vb.net on clicking the ok button i get the input into the text box where required but how to activate the cancel button???