Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

SET SIZE OF THE FORM ON MY PROGRAM BY USING TTRAYICON. HOW CAN I.

HOW CAN I SET SIZE OF ANY FORM IN MY APPLICATION USING MY COMPONENT TTRAYICON.

MAKE SET WHEN CREATE FORM.

WHEN CLOSE FORM SAVE SIZE, NAME.

QUESTIONS:

HOW IS GOING TO BE THE FUNCTION TO SAVE AND SET THIS CONFIGURATION ON INI FILE.
0
rafaelrgl
Asked:
rafaelrgl
  • 5
  • 5
1 Solution
 
TheRealLokiSenior DeveloperCommented:
uses inifiles;

To load a form's position from an ini file :-
begin
    with TINIFile.create('form positions.ini') do
    try
        Form1.SetBounds(
                                    ReadInteger('Form1', 'Top', Form1.Top),
                                    ReadInteger('Form1', 'Left', Form1.Top),
                                    ReadInteger('Form1', 'Width', Form1.Top),
                                    ReadInteger('Form1', 'Height', Form1.Top)
                                  );
    finally
        free;
    end;
end;

And when you want to save the form's position :-
begin
    with TINIFile.create('form positions.ini') do
    try
        WriteInteger('Form1', 'Top', Form1.Top);
        WriteInteger('Form1', 'Left', Form1.Top);
        WriteInteger('Form1', 'Width', Form1.Top);
        WriteInteger('Form1', 'Height', Form1.Top);
    finally
        free;
    end;
end;
0
 
TheRealLokiSenior DeveloperCommented:
oops, should be...

To load a form's position from an ini file :-
begin
    with TINIFile.create('form positions.ini') do
    try
        Form1.SetBounds(
                                    ReadInteger('Form1', 'Top', Form1.Top),
                                    ReadInteger('Form1', 'Left', Form1.Left),
                                    ReadInteger('Form1', 'Width', Form1.Width),
                                    ReadInteger('Form1', 'Height', Form1.Height)
                                  );
    finally
        free;
    end;
end;

And when you want to save the form's position :-
begin
    with TINIFile.create('form positions.ini') do
    try
        WriteInteger('Form1', 'Top', Form1.Top);
        WriteInteger('Form1', 'Left', Form1.Left);
        WriteInteger('Form1', 'Width', Form1.Width);
        WriteInteger('Form1', 'Height', Form1.Height);
    finally
        free;
    end;
end;
0
 
rafaelrglAuthor Commented:
I would like to get the name and position when the form is created using some code in my component ttrayicon, i don't want put the name of the form by myself, like that:

WriteInteger('Form1', 'Top', Form1.Top);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rafaelrglAuthor Commented:
This code is going to be inside my component ttrayicon, I think that's a big problem.
0
 
TheRealLokiSenior DeveloperCommented:
easy, all you do is have a property in your trayicon

e.g

private
    fFormToSaveSettingsFor: TForm;
published
    property FormToSaveSettingsFor: TForm read fFormToSaveSettingsFor write fFormToSaveSettingsFor;
end;

the user sets
MyTrayIcon.FormToSaveSettingsFor := Form1;

and then you just go
if assigned(fFormToSaveSettingsFor) then
  //Save Settings
// use FormToSaveSettingsFor.TOp, FormToSaveSettingsFor.Left, etc...
0
 
TheRealLokiSenior DeveloperCommented:
FormToSaveSettingsFor.Caption or FormToSaveSettingsFor.Name to get the caption or name respectively
0
 
rafaelrglAuthor Commented:
I'll give you the points, but like i sad, i don't want the user set the form, but my component ttrayicon save the position of all forms in the application whithout any code insert by user. Only thing the user is going to do is set a property on component to do that like this below:



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
THIS SET TRUE OR FALSE ON COMPONENT TO SAVE THE POSITION AND SIZE OF ANY FORM IN THE APPLICATION
BUT, HOW IS GOING TO SAVE THAT?
//////////////////////////////
private
    fActivePosition : Boolean;

protect
    procedure SetActivePosition(Value : Boolean); virtual;

published
    property ActivePosition : boolean read fActivePosition write SetActivePosition;


procedure TNucleo_TrayIcon.SetActivePosition(Value : Boolean);
begin
  //if (value <> fActivePosition) and not (csDesigning in ComponentState) then
  if value <> fActivePosition then
  Begin
      fActivePosition := Value;
  end;
end;
////////////////////////////////////////////////////////////////

///// can you help me to understand how this is going to work.
////  THANKS A LOT        
 
0
 
TheRealLokiSenior DeveloperCommented:
oh I see now. use the Screen.Forms property then

var
  i : integer;
begin
  for  i := 0 to Screen.FormCount-1 do
  begin
// Screen.Forms[] returns a "TForm", so you can do anything you like with it eg.
      memo1.lines.add(Screen.Forms[i].Name);
  end;
end;
0
 
rafaelrglAuthor Commented:
HOW CAN I KNOW WHEN THE FORM IS CREATING?
0
 
rafaelrglAuthor Commented:
OR THE FORM IS CLOSING?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now