我有一个CheckBox,它显示并隐藏了一个具有按钮和按钮的面板。两个TEdits(用于输入IP地址及其端口)。
问题是Button没有效果,它保持灰色,Panel也显示。我尝试了不同的方法,例如ModalResult := mrOk;
,没有任何改变。
这是我的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure CheckBox1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked = True then begin
Panel1.Visible := True;
end
else
if CheckBox1.Checked = False then begin
Panel1.Visible := False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Button1: TButton;
begin
Button1 := Sender as TButton;
ShowMessage(Button1.Caption + ' Changes');
end;
end.
答案 0 :(得分:1)
我希望我能理解你的问题。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure CheckBox1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure Showpanel(AShow: boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Showpanel(AShow: boolean);
begin
Checkbox1.checked := AShow;
Panel1.Visible := AShow;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ShowPanel(false);
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
Panel1.visible := Checkbox1.Checked;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(Button1.Caption + ' Changes');
end;
end.