?
Solved

The old moving button joke?

Posted on 2003-02-20
2
Medium Priority
?
1,525 Views
Last Modified: 2007-12-19
I've no doubt that you've all seen what I'm about to describe...

I'm trying to find the code involved with the old moving button in window joke - you know the one where as you attempt the click the 'click me to win a prize' as soon as the cursor position approaches the button the button moves off and is therfore impossible to press.

I'm interested in seeing how this is built (I've a rough idea) - can anyone point me in the direction of some code please?

Thanks
0
Comment
Question by:wacjac
2 Comments
 
LVL 1

Accepted Solution

by:
FrankTheRat earned 90 total points
ID: 7986211
I wrote this a while back, it only moves the button around some predefined locations, but you'll get the idea.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TMainForm = class(TForm)
    MyButton: TButton;
    procedure MyButtonClick(Sender: TObject);
    procedure MyButtonMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

var
  Lft : integer;
  Tp  : integer;

procedure TMainForm.MyButtonClick(Sender: TObject);
begin
  {Just put this in case the user hits enter....}
  MessageDlg('Ha ha ha...!', mtWarning, [mbOK], 0);
end;

procedure TMainForm.MyButtonMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  Lft := MyButton.Left;
  Tp  := MyButton.Top;

  case Lft of
    176 : Lft := 4;
      4 : Lft := 256;
    256 : Lft := 176;
  end;
  case Tp of
    88 : Tp := 72;
    72 : Tp := 88;
  end;

  MyButton.Top  := Tp;
  MyButton.Left := Lft;

end;

end.
0
 

Expert Comment

by:MethinX
ID: 7986223
Click on the MouseMove event of the Button and you 'll get this procedure header, and i added a code to move if from left 200 to left 50 and back.

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if
    button1.Left <> 200 then
    button1.Left := 200
  else
    button1.Left := 50;
end;
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question