Delphi case语句问题
抱头啊。——————是单选改变字体颜色的问题。选第一个的时候字体颜色改变了,选第二个确没有改变。——————procedureTForm1.radiobuttonClic...
抱头啊。
——————
是单选改变字体颜色的问题。
选第一个的时候字体颜色改变了,选第二个确没有改变。
——————
procedure TForm1.radiobuttonClick(Sender: TObject);
begin
case (sender as tradiobutton).tag of
0:edit1.Font.color:=clred;
1:edit1.Font.color:=clgreen;
2:edit1.Font.color:=clblue;
end;
end;
————————
莫名其妙的运行不了了…… 展开
——————
是单选改变字体颜色的问题。
选第一个的时候字体颜色改变了,选第二个确没有改变。
——————
procedure TForm1.radiobuttonClick(Sender: TObject);
begin
case (sender as tradiobutton).tag of
0:edit1.Font.color:=clred;
1:edit1.Font.color:=clgreen;
2:edit1.Font.color:=clblue;
end;
end;
————————
莫名其妙的运行不了了…… 展开
4个回答
展开全部
首先你要设置radiobutton的tag,
我用delphi试了下,可以用,把源代码贴上:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure radiobuttonclick(sender:Tobject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.radiobuttonclick(sender:Tobject);
begin
case (sender as tradiobutton).tag of
0:edit1.Font.color:=clred;
1:edit1.Font.color:=clgreen;
2:edit1.Font.color:=clblue;
end;
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
radiobuttonclick(radiobutton1)
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
radiobuttonclick(radiobutton2);
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
begin
radiobuttonclick(radiobutton3);
end;
end.
我用delphi试了下,可以用,把源代码贴上:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure radiobuttonclick(sender:Tobject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.radiobuttonclick(sender:Tobject);
begin
case (sender as tradiobutton).tag of
0:edit1.Font.color:=clred;
1:edit1.Font.color:=clgreen;
2:edit1.Font.color:=clblue;
end;
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
radiobuttonclick(radiobutton1)
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
radiobuttonclick(radiobutton2);
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
begin
radiobuttonclick(radiobutton3);
end;
end.
展开全部
加这个: 刚才复制成一个了!嘿嘿
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioButton1.Tag := 0;
RadioButton2.Tag := 1;
RadioButton3.Tag := 2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioButton1.Tag := 0;
RadioButton2.Tag := 1;
RadioButton3.Tag := 2;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是:
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioButton1.Tag := 0;
RadioButton2.Tag := 1;
RadioButton3.Tag := 2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RadioButton1.Tag := 0;
RadioButton2.Tag := 1;
RadioButton3.Tag := 2;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在 Radiobutton2,Radiobutton3 的OnClick 事件中都加上这个事件radiobuttonClick
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询