社区
C#
帖子详情
菜鸟问题:咋控制打开窗体的位置?
lusonghe18
2003-07-25 08:12:15
我想在用一按钮打开一窗体的时候,让这窗体始终出现在
紧靠按钮的下方?
...全文
28
15
打赏
收藏
菜鸟问题:咋控制打开窗体的位置?
我想在用一按钮打开一窗体的时候,让这窗体始终出现在 紧靠按钮的下方?
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
15 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
打赏红包
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的上面显示标题部分(蓝色条)的高度
相关推荐
c#
窗体
位置
与外观
控制
c#
窗体
位置
与外观
控制
主要是现实
窗体
的
位置
与自定义
窗体
的形状
MDI父
窗体
控制
子
窗体
MDI父子
窗体
相互传值的
问题
在网上已经能找到很多了,但是有关父
窗体
控制
子
窗体
的文章不是很多。方法其实相比较父子
窗体
的传值并不难,也许许多大虾们感觉太简单没有写出来,本人作为
菜鸟
总结出来,以便给同样是
菜鸟
的同学学习。其实父
窗体
调用子
窗体
对于Winform应用程序开发、系统开发以及CAD系统的开发的作用是比较大的。本人主要从事水工CAD系统的开发工作,在这个过程中就会遇到很多这样的
问题
。如:菜单栏
C#操作移动其他程序窗口
在做项目时候,曾经遇到一个
问题
,就是用C#的WinForm,来
打开
一个使用C++编写的软件,并
控制
打开
窗体
位置
和大小。 在这里使用了Win32 API来做的。可以使用C#根据
窗体
的路径,启动一个进程,然后使用Win32 API
控制
打开
窗口的
位置
和大小。 主要代码如下: public class A { //调用Win32 API
Linux嵌入外部程序窗口,C#操作移动其他程序窗口
在做项目时候,曾经遇到一个
问题
,就是用C#的WinForm,来
打开
一个使用C++编写的软件,并
控制
打开
窗体
位置
和大小。在这里使用了Win32 API来做的。可以使用C#根据
窗体
的路径,启动一个进程,然后使用Win32 API
控制
打开
窗口的
位置
和大小。主要代码如下:public class A{//调用Win32 API[System.Runtime.InteropServices.DllImpor...
C#实现按键
控制
窗体
移动
实现按键
控制
窗体
移动: 1
打开
窗体
接收按键事件的属性设置: mform.KeyPreview = true; 2 更改
窗体
的
位置
this.Location 的值 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threa
发帖
C#
C#
.NET技术 C#
复制链接
扫一扫
10.8w+
社区成员
64.2w+
社区内容
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
帖子事件
创建了帖子
2003-07-25 08:12
社区公告
让您成为最强悍的C#开发者