How to create Right Click and Middle Click event on custom hyperlink button?

I am creating my Custom hyperlink button deriving from Silverlight HyperlinkButton I want to create Right Click and Middle click event on it. Can some help me please.

Thanks, Gobind

Answers


I would add a couple of events (like MiddleClick and RightClick), then handle the MouseUp (or MouseDown, if you want to intercept on the down), then fire one of the two events depending on the details of the MouseUp event. For example:

public MyControl()
{
    InitializeComponent();
    MouseUp += OnMouseUp;
}

void OnMouseUp(object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Middle)
    {
        OnMiddleClick(e);
        e.Handled = true;
        return;
    }
    if (e.ChangedButton == MouseButton.Right)
    {
        OnRightClick(e);
        e.Handled = true;
        return;
    }
}

public event MouseButtonEventHandler RightClick;

protected virtual void OnRightClick(MouseButtonEventArgs e)
{
    var handler = RightClick;
    if (handler != null) handler(this, e);
}

public event MouseButtonEventHandler MiddleClick;

protected virtual void OnMiddleClick(MouseButtonEventArgs e)
{
    var handler = MiddleClick;
    if (handler != null) handler(this, e);
}

Need Your Help

How to run a batch script (.bat file) from eclipse

eclipse batch-file

My Java application is started by running a set of commands that are present in a batch file (.bat file). And I imported this into Eclipse workbench. How do I execute the batch file from Eclipse. S...

ffmpeg rtmp streaming issue

ffmpeg rtmp wowza

I am trying to stream my webcam video using the ffmpeg to wowza media server on linux..