Recent

Author Topic: how do I make a button that opens another form  (Read 26005 times)

sasue11

  • Newbie
  • Posts: 3
how do I make a button that opens another form
« on: June 21, 2011, 05:39:17 pm »
Hi,
My computer is windows 64 (it is 64-bits) I am very new to the forum so please tell me if I did something wrong...here is question: i would like to know how to make a button that opens another form when it is clicked...just send me the source code for it and I will use it in my program^^...
THX
[GS]HACKER

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: how do I make a button that opens another form
« Reply #1 on: June 21, 2011, 05:57:22 pm »
In Lazarus: Create New Project -> Application
Now you have the 1-st Form.
Menu: File -> New Form
Now you have the 2-nd Form
Add "Unit2" to "uses" section of Unit1.
Code: [Select]
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit2;
Add Button on Form1 from components (Standart palette)

In Object Inspector select Button1, tab Events, event OnClick (double click it)
(or double click Button1 on the Form1)

It will add
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin

end;
to your Source Editor.
Type there:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;
That's all.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

sasue11

  • Newbie
  • Posts: 3
Re: how do I make a button that opens another form
« Reply #2 on: June 21, 2011, 08:51:15 pm »
Thanks!!!

Shebuka

  • Sr. Member
  • ****
  • Posts: 429
Re: how do I make a button that opens another form
« Reply #3 on: June 22, 2011, 12:05:14 pm »
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;
That's all.
This only if you select to auto create that form in project options.

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: how do I make a button that opens another form
« Reply #4 on: June 22, 2011, 06:33:40 pm »
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;
That's all.
This only if you select to auto create that form in project options.

No, you don't have to select this option, it is the default, you only must not remove it from the auto-create list.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

vdubeau

  • New Member
  • *
  • Posts: 27
Re: how do I make a button that opens another form
« Reply #5 on: March 07, 2023, 08:12:25 pm »
i'm was also interested in doing this. I tried out your example and it worked great.

Thanks

 

TinyPortal © 2005-2018