question about linklabel..

how to make a linklabel once the mouse point to it, a box will appear beside it that display some text...

or once the mouse point to the linklabel , the colour of the linklabel chage to other colour, and once the mouse move over, it change back to original colour

is there a way for linklabel if not, button event also can, i just want to let my page look more attractive....



Answer this question

question about linklabel..

  • Ken Robertson

    In the MouseEnter event you can set the LinkColor property to an other color and in the MouseLeave you can set it back to its original color. You can also set the Cursos property to Cursors.Hand to give the user a more link feeling.


    private void linkLabel1_MouseEnter(object sender, System.EventArgs e)
    {
    linkLabel1.LinkColor = Color.Green;
    }

    private void linkLabel1_MouseLeave(object sender, System.EventArgs e)
    {
    linkLabel1.LinkColor = Color.Red;
    }




  • Rob Plates

    Both posts are useful..thanks
  • JKohlhepp

    As for the box, it seems all you need is a tooltip. If you are not familiar with tooltips, all you need to do is drag a single tooltip control over your form. This will add a new property to your linklabels, in which you can specify the tooltip text.

    For the hovering, the simplest way to achieve this is to create your custom control, which requires only a few lines of code:

    public class HoverLink : LinkLabel {
    private Color hoverColor;
    private Color oldColor;

    public HoverLink () : base () {
    hoverColor = LinkColor;
    }

    [Browsable(true)]
    [Category (
    "Appearance")]
    public Color HoverColor {
    get { return hoverColor; }
    set { hoverColor = value; }
    }

    protected
    override void OnMouseEnter (System.EventArgs e) {
    oldColor = LinkColor;
    LinkColor = HoverColor;
    base.OnMouseEnter (e);
    }

    protected override void OnMouseLeave (System.EventArgs e) {
    LinkColor = oldColor;
    base.OnMouseLeave (e);
    }
    }

    Once you enter these lines in your project, you will find in your toolbox a new control named "HoverLink". In this you will find the HoverColor property, which will allow you to set the color to use when the mouse hovers over the control. It is otherwise a simple LinkLabel.

    HTH
    --mc


  • question about linklabel..