社区
C#
帖子详情
菜鸟问题:咋控制打开窗体的位置?
lusonghe18
2003-07-25 08:12:15
我想在用一按钮打开一窗体的时候,让这窗体始终出现在
紧靠按钮的下方?
...全文
69
15
打赏
收藏
菜鸟问题:咋控制打开窗体的位置?
我想在用一按钮打开一窗体的时候,让这窗体始终出现在 紧靠按钮的下方?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
15 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
shareach
2003-07-25
打赏
举报
回复
加个循环:
System.Windows.Forms.Control parentControl=button.Parent;
System.Drawing.Point position = new System.Drawing.Point(0,0);
while (!(parentControl is System.Windows.Forms.Form))
{
position.X += parentControl.Location.X;
position.Y += parentControl.Location.Y;
parentControl = parentControl.Parent;
}
position.X += button.Location.X;
position.Y += button.Location.Y+button.Height;
openForm.Location=position;
derek
2003-07-25
打赏
举报
回复
沒問題啊
openForm.Location=new System.Drawing.Point(tn.Location.X,btn.Location.Y+20);
試試用:
openForm.Left=btn.Left;
openForm.Top=btn.Top+20;
lusonghe18
2003-07-25
打赏
举报
回复
谢谢JOELIU,但是父窗体不是最大化时,openForm的位置就不会根我的按钮位置走啊?
joeliu
2003-07-25
打赏
举报
回复
private void button1_Click(object sender, System.EventArgs e)
{
form2=new Form2 ();
form2.StartPosition=FormStartPosition.Manual ;
form2.Location =new System.Drawing.Point(0,200);
form2.Show ();
}
即可
lusonghe18
2003-07-25
打赏
举报
回复
public class MainForm
{
private OpenForm openForm;//另一窗体
public MainForm()
{
......
}
private void Buttons_Click(object sender,EvengArgs e)
{
Button btn=(Button)sender;
openForm=new OpenForm();
openForm.Location=new System.Drawing.Point(tn.Location.X,btn.Location.Y+20);
openForm.Show();
}
}
liduke
2003-07-25
打赏
举报
回复
把代码贴出来看看
lusonghe18
2003-07-25
打赏
举报
回复
按钮不是动态生成的
lusonghe18
2003-07-25
打赏
举报
回复
求助
declude
2003-07-25
打赏
举报
回复
按钮是动态生成的?
lusonghe18
2003-07-25
打赏
举报
回复
to:declude
单击第一次它出现在左上方,以后每单击打开
它会沿,他的X,Y坐标会增加即往,bottom,right方向移动
到屏幕中间后有会退至第一次的位置
declude
2003-07-25
打赏
举报
回复
什么情况?
lusonghe18
2003-07-25
打赏
举报
回复
Button btn=(Button)sender;
openForm=new OpenForm();
openForm.Location=new System.Drawing.Point(btn.Location.X,btn.Location.Y+20);
openForm.Show();
我这样做是没有达到我上述要求,
为什么?
CMIC
2003-07-25
打赏
举报
回复
设置location属性或StartPosition属性
declude
2003-07-25
打赏
举报
回复
你可以用Form的location属性设置。
joeliu
2003-07-25
打赏
举报
回复
private void button1_Click(object sender, System.EventArgs e)
{
form2=new Form1 ();
form2.StartPosition=FormStartPosition.Manual ;
//横坐标
int X=this.Location.X +this.button1 .Location .X ;
//纵坐标
int Y=this.Location .Y+this.button1 .Location .Y
+this.button1 .Size .Height+30;
form2.Location =new System.Drawing.Point(X,Y);
form2.Show ();
}
不断点按钮,效果是不错的
坐标中的数字30是form2的上面显示标题部分(蓝色条)的高度
HEX / RGB 颜色转换工具
颜色转换工具
组合式专用铣齿机床设计(论文 CAD图纸).rar
组合式专用铣齿机床设计(论文 CAD图纸).rar
AI Challenger 2018 阅读理解赛道代码分享.zip
一款 AI 辅助阅读器,三栏设计实现笔记、阅读、对话同屏交互,让深度阅读更高效
易语言源码多任务同时下载源码
易语言源码多任务同时下载源码
Artix-7-XC7A35T-DDR3开发板硬件参考设计资料
源码下载地址: https://pan.quark.cn/s/3a6709c3f9be This is a TPYboard You can get started right away by writing your Python code in 'main.py'. For a serial prompt: - Windows: you need to go to 'Device manager', right click on the unknown device, then update the driver software, using the 'tpybcdc.inf' file found on this drive. Then use a terminal program like Hyperterminal or putty. - Mac OS X: use the command: screen /dev/tty.usbmodem* - Linux: use the command: screen /dev/ttyACM0 Please visit http://www.tpyboard.com/help/ for further help. Designed by TurnipSmart in Shandong!
C#
111,131
社区成员
642,542
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章