Solved

Moving an empty (no menubar) form around the screen.

Posted on 1997-07-20
4
150 Views
Last Modified: 2010-04-04
I've created an empty form that I can't figure out how to move.

What I did:

1. Created a form with no components.
2. Set all the forms properties so nothing would show             around the borders.
3. Set the back color to green.
4. Double-Clicking on the form quits the application.
5. I set the client height to 2.

When I run the program it does what it's supposed to.  It puts a green line on the screen without a menu bar,  min/max buttons or boarder,  just a clean green line that stays on top of everything and goes away if you
double click on it.

Is there a way to allow the user to drag this line around without having a menu bar?  I can't find one.

I did play with setWindowPos but it only seems to work with child windows.

If it helps the purpose of this line is supposed to be to help users focus across the correct line in an Access 2.0 form.  It works but they can't move it which would be a big help.  They currently do the same thing by wrapping rubberbands around the monitors and placing the band across the
middle of the screen,  a bit inconvient at best.

Thanks.
0
Comment
Question by:wirth
  • 3
4 Comments
 

Author Comment

by:wirth
ID: 1339368
Edited text of question
0
 

Author Comment

by:wirth
ID: 1339369
Edited text of question
0
 
LVL 4

Accepted Solution

by:
erajoj earned 100 total points
ID: 1339370
This is a way I use often:

var
  X0, Y0   : Integer;
  MoveForm : Boolean = False; // Delphi 2+

procedure TGreenLine.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button = mbLeft) then begin
    MoveForm := True;
    X0 := X; Y0 := Y;
  end;
end;

procedure TGreenLine.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if MoveForm then SetBounds(Left-X0+X, Top-Y0+Y, Width, Height);
  { If you want to move vertically only: }
  // if MoveForm then SetBounds(Left, Top-Y0+Y, Width, Height);
end;

procedure TGreenLine.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    MoveForm := False;
end;

If you want to make it easier to grab then use region-functions
to create a "handle" that is wider than the line, do something
like this:

procedure TGreenLine.FormCreate(Sender: TObject);
var
  RGN, RGN1, RGN2: HRGN;
begin
  Cursor := crVSplit; // Just for appearance
  SetBounds(0, Screen.Height div 2, Screen.Width, 15);
  RGN1 := CreateRectRGN(0, 0, Screen.Width, 2);
  RGN2 := CreateEllipticRGN(Screen.Width-30, -15,
    Screen.Width+30, +15);
  CombineRGN(RGN1, RGN1, RGN2, RGN_OR);
  SetWindowRgn(Handle, RGN1, true);
end;                    

Enjoy!

/// John

0
 

Author Comment

by:wirth
ID: 1339371
Thank's earjoj.  I tried the basics you put in and it worked like a charm.  I'm going to try out the rest of your idea now.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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