I need to get the width and height of the taskbar. Also I need the position of the taskbar. How can I get this?
Delphi – Taskbar width, height and position
delphi
Related Solutions
Like so:
MainForm.Width := 127;
MainForm.Height := 263;
Or perhaps you want to set the client area to those dimensions:
MainForm.ClientWidth := 127;
MainForm.ClientHeight := 263;
Of course, you most commonly set these properties in the Object Inspector at design time and then they are written to your form's .dfm file.
If you want such a change to occur on a button click add a handler for the button click that looks like this:
procedure TMainForm.Button1Click(Sender: TObject);
begin
Width := 127;
Height := 263;
end;
In this last excerpt you don't need to specify the MainForm
object instance because the event handler is a member of the TMainForm
class and so the Self
is implicit.
If you wish to follow Ulrich Gerhardt's advice (see comment) and use SetBounds
then you would write:
SetBounds(Left, Top, 127, 263);
Finally, if your form has Scaled = True
then you need to deal with font scaling. Hard coded pixel dimensions like this will not be appropriate for machines with font scaling set to a different value from your machine.
Ok, now that it is clear what you want, first a couple of things:
- The first Form created is automatically the MainForm,
- An application cannot without a MainForm; when the MainForm closes, the application closes, whatever other forms are shown,
- You can hide the MainForm,
- By default (in older Delphi versions anyway) the application's window is shown on the taskbar (
Application.MainFormOnTaskbar = False
). As long as the application is active, and as long as there is at least one form showing, this icon/window is shown in the taskbar. - When
Application.MainFormOnTaskbar = True
, then the icon/window of the MainForm is shown in the taskbar. When the MainForm is hiden, the icon dissapears. Showing another form does not result in another taskbar icon/window, so there is no icon at all then.
So, it is clear you need to set Application.MainFormOnTaskbar := False
in the project file.
Furthermore, the following combination of methods seems to work as you want:
Unit1/Form1/MainForm:
procedure TForm1.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.OpenForm2ButtonClick(Sender: TObject);
begin
TForm2.Create(Self).Show;
Hide;
end;
Unit2/Form2:
procedure TForm2.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TForm(Owner).Show;
Action := caFree;
end;
procedure TForm2.OpenForm3ButtonClick(Sender: TObject);
begin
TForm3.Create(Self).Show;
Hide;
end;
Unit3/Form3:
procedure TForm3.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TForm(Owner).Show;
Action := caFree;
end;
Note that the caption of the taskbar button remains the same during these changes. If you want to synchronize that with the caption of the form being shown, set Application.Title
.
Best Answer
Depending on what you need that information for, you might want to look into Forms.TScreen.WorkAreaRect, because the work-area identified that way subtracts not only the TaskBar, but also any other "bar" that might limit available Desktop space.
You can simply use
Screen.WorkAreaRect
from your code, because aScreen: TScreen
variable is declared in theForms
unit and initialized by the VCL.