向各位 C++Builder 高手求教:单选按钮不见了!

rchen 2000-05-26 06:13:00
我希望在表单 Form1 上建立一个组合框,框里有两个
单选按钮,并要求组合框和单选按钮都是动态创建的。

为实现这个目的,先建立组合框对象 GroupBox1,单选
按钮 RadioButton1,RadioButton2,然后把 GroupBox1 的
Parent 属性置为 Form1,RadioButton1,RadioButton2的
Parent 属性置为 GroupBox1。代码如下:

然后编译,连接......结果发现 Form1 上只有 GroupBox1,
单选按钮不知所踪! 另外,如果 GroupBox1 不是动态创建,
而是预先拉到表单上的,结果一切正常;如果把
RadioButton2->Parent 改为 Form1, 结果也正常,但组合框
的组合目的却没有达到。

到底怎样才能让单选按钮露面呢,请各位高手救我!
兄弟在这里先作揖了。





void __fastcall TForm1::FormCreate(TObject *Sender)
{
TGroupBox *GroupBox1 = new TGroupBox(this);
TRadioButton *RadioButton1 = new TRadioButton(this);
TRadioButton *RadioButton2 = new TRadioButton(this);

GroupBox1->Parent = Form1;
GroupBox1->Left = 10;
GroupBox1->Top = 100;
GroupBox1->Width = 200;
GroupBox1->Height = 100;
GroupBox1->Caption = "";

RadioButton1->Parent = GroupBox1;
RadioButton1->Left = 11 ;
RadioButton1->Top = 120 ;
RadioButton1->Width = 100;
RadioButton1->Height = 20;
RadioButton1->Caption = "a. 衣带渐宽终不悔";

RadioButton2->Parent = GroupBox1;
RadioButton2->Left = 11 ;
RadioButton2->Top = 180 ;
RadioButton2->Width = 100;
RadioButton2->Height = 20;
RadioButton2->Caption = "b. 为伊消得人憔悴";

}






...全文
156 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
radish 2000-05-27
  • 打赏
  • 举报
回复
估计和Z-order有关,不过你完全不用这么做,可以用
TRadioGroup *GroupBox1 = new TRadioGroup(this);
// TRadioButton *RadioButton1 = new TRadioButton(this);
// TRadioButton *RadioButton2 = new TRadioButton(this);
// Add
GroupBox1->Parent = Form1;
GroupBox1->Left = 10;
GroupBox1->Top = 100;
GroupBox1->Width = 200;
GroupBox1->Height = 100;
GroupBox1->Caption = "";
GroupBox1->Items->Add("a. 衣带渐宽终不悔");
GroupBox1->Items->Add("b. 为伊消得人憔悴");
江王 2000-05-27
  • 打赏
  • 举报
回复
设置各控件的Visible属性为true,控件的visible属性缺省为false,当然会看不见了。
Wingsun 2000-05-27
  • 打赏
  • 举报
回复
我试验了你的代码,是可以的,代码没有错,也能达到效果。做了两次试验,第一次在我的现有工程里做的,不成功。可以说是不管我如何改变他的相关属性(GroupBox1)都没有变化。后来重新建立一个工程,同样的代码确成功了。所以我认为你的代码没有问题,你将你的工程完全重新编译Build一次,应该不会在有问题的。

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧