Recent

Author Topic: [solved] Form stick in top right corner  (Read 2391 times)

zoimutante

  • New Member
  • *
  • Posts: 34
[solved] Form stick in top right corner
« on: December 20, 2016, 12:08:56 am »
Fellows, I need to stick my form in top right corner, I search in google, and found some codes, but I'm really newbie in computer programming, and don't know how to use it or even  if it will work.

Here is the code

Quote
procedure MoveFormToTopOfRightmostMonitor(Form: TForm);
var
  i: Integer;
  Monitor, RightMostMonitor: TMonitor;
begin
  RightMostMonitor := Screen.Monitors[0];
  for i := 1 to Screen.MonitorCount-1 do
  begin
    Monitor := Screen.Monitors;
    if Monitor.Left+Monitor.Width > RightMostMonitor.Left+RightMostMonitor.Width then
      Monitor := RightMostMonitor;
  end;
  Form.Left := Monitor.Left+Monitor.Width-Form.Left;
  Form.Top := Monitor.Top;
end;

If it works, can some one explain where did I use it, and if I'm not asking too much, comment line per line ?
It works in the on create event of the form ?
Thanks to advice.
« Last Edit: December 20, 2016, 08:43:07 pm by zoimutante »

zoimutante

  • New Member
  • *
  • Posts: 34
Re: Form stick in top right corner
« Reply #1 on: December 20, 2016, 01:02:29 am »
to anyone facing the same problem, i fix it. Don't know if it is the right  solution,  but works
On form create
Code: Pascal  [Select][+][-]
  1.   var altura,largura:Integer; //declarations of variables,  altura means height and largura means width, use it in portugues to void conflicts with reservad words
  2.   begin //The program starts here
  3.    largura:=screen.Width; //defines the value of variable "largura" with the screen width using withd.Screen.Width function/
  4.    altura:=screen.Height; //Same as above
  5.    Form1.Top:=altura-altura; //Pixel count I belive start up corner to down right corner, so, top of screen is at 0 pixel, so i need to do the substration. Form1 is the name of form
  6.    Form1.Left:=largura; Same as above.
  7.   end;
  8.  

Hope it will be help some one in the future.

PS: Maybe the variables is not necessary, don't test.

Nice Christmas to all :)
« Last Edit: December 20, 2016, 08:47:12 pm by zoimutante »

Graeme

  • Hero Member
  • *****
  • Posts: 1440
    • Graeme on the web
Re: Form stick in top right corner
« Reply #2 on: December 20, 2016, 12:18:54 pm »
The following line:

Code: Pascal  [Select][+][-]
  1. Monitor := Screen.Monitors;
  2.  

should probably read....

Code: Pascal  [Select][+][-]
  1. Monitor := Screen.Monitors[i];
  2.  

...because you are looping through the monitor list and retrieving each instance.

This ....
Code: Pascal  [Select][+][-]
  1. if Monitor.Left+Monitor.Width > RightMostMonitor.Left+RightMostMonitor.Width then
  2.   Monitor := RightMostMonitor;
  3.  

... could possible become...

Code: Pascal  [Select][+][-]
  1. if Monitor.Left+Monitor.Width > RightMostMonitor.Left then
  2.   RightMostMonitor := Monitor;
  3.  

And this...
Code: Pascal  [Select][+][-]
  1.   Form.Left := Monitor.Left+Monitor.Width-Form.Left;
  2.   Form.Top := Monitor.Top;
  3.  

... should probably become....
Code: Pascal  [Select][+][-]
  1.   Form.Left := RightMostMonitor.Left+RightMostMonitor.Width-Form.Width;
  2.   Form.Top := RightMostMonitor.Top;
  3.  

Hope that helps.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

zoimutante

  • New Member
  • *
  • Posts: 34
Re: Form stick in top right corner
« Reply #3 on: December 20, 2016, 05:24:56 pm »
thanks:D

 

TinyPortal © 2005-2018