?
Solved

The old moving button joke?

Posted on 2003-02-20
2
Medium Priority
?
1,447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 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