Solved

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

Posted on 1997-07-20
4
153 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 119
Delphi selector screen 2 84
Tviruailstringtree sort multi columns on header click 1 74
Firemonkey BASS_Init into a thread 17 30
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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