Link to home
Start Free TrialLog in
Avatar of holemania
holemania

asked on

VB.NET mouseover button move

Anyone know if it's possible to create a button where if you mouseover it, the button moves away?  I know it can be done in Java and have seen the code, but is it possible to create something like this in VB.NET?  If so does anyone have sample code I can look and see how it's done?
Avatar of abel
abel
Flag of Netherlands image

Yes. Do you mean like however hard you try, the button cannot be clicked because it moves?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As abel says, of course it can be done...but is this a WinForms (Desktop) or WebForms (Browser) application?

...and do you want the button to move away as the mouse comes NEAR it?

...or make the button simply jump somewhere else when the mouse ENTERS the it?
Here's a simple example on WinForms where the cursor stays in the middle of the button and drags it around on the form. Important things to note are PostToClient/PointToScreen translations and Application.DoEvents/is_moving static boolean to give the application the time to draw the button.

static bool is_moving = false;
private void btnMovable_MouseMove(object sender, MouseEventArgs e)
{
    if (is_moving)
        return;
    else
    {
        is_moving = true;
        Point locMouse = this.PointToClient(btnMovable.PointToScreen(e.Location));
        btnMovable.Location = new Point(locMouse.X - btnStartTransform.Width / 2, locMouse.Y - btnMovable.Height / 2);
        Application.DoEvents();
        is_moving = false;
    }
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of holemania
holemania

ASKER

Yeah wanted to move as you try to click.  Thanks i'll take a look.
Thanks that's what I was looking.