65.9K
CodeProject is changing. Read more.
Home

BevelLine Control with Designer Selection Rules

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.65/5 (10 votes)

Jun 16, 2005

2 min read

viewsIcon

58503

downloadIcon

1298

A bevel line control with Visual Studio Designer SelectionRule support.

Sample Image - BevelLineScreenshot.gif

Introduction

I decided to write this bevel line control when I saw that (many moons ago) Visual Studio 2002 didn't have it in its toolbox. Coming from a Visual Basic 6 background, I was disappointed not to have a Shape control (coming in another article) to generate lines for bevels.

Using the code

Here's a sample of all the properties that make a difference:

   bevelLine1.BevelLineWidth = 1;
   bevelLine1.Blend = false;
   bevelLine1.TopLineColor = SystemColors.ControlDark;
   bevelLine1.BottomLineColor = SystemColors.ControlLightLight;
   bevelLine1.Orientation = Orientation.Horizontal;

When using the Form Designer, you can only drag the control width if it is in the horizontal position. To change the control height, set the BevelLineWidth. Using the Blend feature will do a gradient fill rather than a solid one.

Points of Interest

This control stands out from the others because I have implemented a ControlDesigner. This visually guides the developer when selecting the BeveLine control as to whether it can be sized left to right or up and down dependent on the orientation.

This does not work in Visual Studio 2005 Beta 2 as they have modified the selection drawing routine. In previous versions of Visual Studio, it would draw all selection grips around a control at design time but not allow the developer to alter the disabled option. However in Visual Studio 2005 Beta 2, it will not draw the disabled SelectionRules, and if the height of the control is less than 18 it will not be shown!

Using the Designer attribute allows us to reference the designer from the control.

 [Designer(typeof(BevelLineDesigner))]
 public class BevelLine : System.Windows.Forms.Control
 {
    // code...
 }

This is the designer code for the BevelLine. It inherits from ControlDesigner which you have to add the reference System.Design to be able to use in your project.

Overriding the SelectionRules allows you to set selection grips, whether the developer can move it at design time, and whether it's visible. You can actually reference the actual control at design time by using the base.Control property and casting it to your control.

public class BevelLineDesigner : System.Windows.Forms.Design.ControlDesigner
{
  public BevelLineDesigner()
  {
   
  }
  public override SelectionRules SelectionRules
  {
   get
   {
    SelectionRules rules; 
    rules = base.SelectionRules;
    
    // If using VS.net 2005 Beta 2 then comment this code to have
    // selective grip handles on the BevelLine control in the Designer
    if (((BevelLine)base.Control).Orientation == 
          System.Windows.Forms.Orientation.Horizontal)
    {
        rules = SelectionRules.Moveable | SelectionRules.Visible
            | SelectionRules.LeftSizeable | SelectionRules.RightSizeable;
    }
    else
    {
        rules = SelectionRules.Moveable | SelectionRules.Visible
            | SelectionRules.TopSizeable | SelectionRules.BottomSizeable;
    }
   
    return rules;
   }
  }
}

History

  • Uploaded as Visual Studio 2005 Beta 2 solution - 16 June 2005.
  • Uploaded as Visual Studio 2003 solution - 16 June 2005.