Solved

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

Posted on 1997-07-20
4
142 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
Comment Utility
Edited text of question
0
 

Author Comment

by:wirth
Comment Utility
Edited text of question
0
 
LVL 4

Accepted Solution

by:
erajoj earned 100 total points
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now