如何动态的显示Button

a1a_36 2008-10-17 08:21:19
如何动态的显示Button。
即我在窗体上点那,Button就出现在那。
...全文
177 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanreid 2008-10-18
  • 打赏
  • 举报
回复
那就只用这样就可以了:

// btn是你创建好的Button
TPoint p;
p.x = Mouse->CursorPos.x;
p.y = Mouse->CursorPos.y;
p = ScreenToClient(p);

btn->Left = p.x - btn->Width/2;
btn->Top = p.y - btn->Height/2;
a1a_36 2008-10-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yuanreid 的回复:]
这是我刚写好的,测试没有问题。鼠标点击窗口任意位置,在鼠标点击处创建一个Button


C/C++ code
void __fastcall TForm1::FormClick(TObject *Sender)
{
TButton* btn = new TButton(this);
btn->Parent = this;
TPoint p;
p.x = Mouse->CursorPos.x;
p.y = Mouse->CursorPos.y;
p = ScreenToClient(p);

btn->Left = p.x - btn->Width/2;
btn->Top = p.y - btn->Height/2;

[/Quote]
要是事先放了一个Button,我在窗体上点击那,那个Button出现在那个点上。怎么解决呢~
我来看看CB 2008-10-18
  • 打赏
  • 举报
回复
主要看做什么用
yuanreid 2008-10-17
  • 打赏
  • 举报
回复
这是我刚写好的,测试没有问题。鼠标点击窗口任意位置,在鼠标点击处创建一个Button


void __fastcall TForm1::FormClick(TObject *Sender)
{
TButton* btn = new TButton(this);
btn->Parent = this;
TPoint p;
p.x = Mouse->CursorPos.x;
p.y = Mouse->CursorPos.y;
p = ScreenToClient(p);

btn->Left = p.x - btn->Width/2;
btn->Top = p.y - btn->Height/2;
btn->Caption = "New Button";
}
xabcxyz 2008-10-17
  • 打赏
  • 举报
回复
同意楼上,或者干脆在form的onclick里面移动butoon
zhanghelpsgz 2008-10-17
  • 打赏
  • 举报
回复
不太明白你的意思
如果是让组件能移动就:
Button1MousdDown(...){
WORD SC_DragMove=0xF012;
ReleaseCapture();
((TWinControl*)Sender)->Perform(WM_SYSCOMMAND,SC_DragMove,0);
}

如果是生成几个Button就用:
TButton *tb1=new TButton(this);
tb1->Parent=this;
tb1->Caption="你要Button";
tb1->Left=5;
tb1->Top=3;

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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