使弹出窗体相对控件的位置固定的方法!
2012-01-09 11:48
337 查看
在点击Button弹出一个新窗体时,希望窗体位于Button的上面,改变Button位置点击新窗体的位置始终相对固定。
开始用这种方法,好像有些繁琐!
效果一样,如下:
BlankFrm m_listViewUI = new BlankFrm(); this.listBox1.Items.Clear(); m_listViewUI.StartPosition = FormStartPosition.Manual; m_listViewUI.Location = new Point(Control.MousePosition.X, Control.MousePosition.Y - 250 - 28); //m_listViewUI.Location = pt; m_listViewUI.Name = "listViewUI1"; m_listViewUI.Padding = new System.Windows.Forms.Padding(4); m_listViewUI.Size = new System.Drawing.Size(200, 250);
开始用这种方法,好像有些繁琐!
m_listViewUI = new BlankFrm(); int x, y; int Screen_x = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width; int Screen_y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height; this.listBox1.Items.Clear(); m_listViewUI.StartPosition = FormStartPosition.Manual; Control control = (Control)sender; //MessageBox.Show(this.PointToClient(this.btnAdd.Location).X.ToString() + " " + this.PointToClient(this.btnAdd.Location).Y.ToString()); Point pt1 = control.PointToScreen((sender as Button).Location); x = this.PointToScreen((sender as Button).Location).X; y = pt1.Y - 250 - 28; m_listViewUI.Location = new Point(x, y); m_listViewUI.Name = "listViewUI1"; m_listViewUI.Padding = new System.Windows.Forms.Padding(4); m_listViewUI.Size = new System.Drawing.Size(200, 250);
效果一样,如下:
相关文章推荐
- 窗体上的控件保持相对位置不变
- 如何获得窗体上控件相对于屏幕的位置?
- MDI窗体中打开子窗体时 子窗体的位置固定方法 十分有作用
- C# Winform 如何获得窗体上控件相对于屏幕的位置
- CSS中position属性的理解,相对位置relative,绝对位置absolute,固定fixed,页脚固定的实现2种方法
- 获取鼠标点相对于各屏幕、窗体和当前控件的位置
- JS简单实现DIV相对于浏览器固定位置不变的方法
- vc获得控件相对窗体的位置
- 调整Windows窗体程序多个子控件大小和位置的API标准方法
- WPF如何获取控件之间的相对位置
- ASP.NET 弹出窗体选择控件
- WinForm-控件、窗体的构造方法和加载方法的比较
- 使用双重缓冲,避免窗体中控件位置移动的时候闪烁
- 使用addView方法时,如何保持已有动态控件位置不被改变
- jquery设置控件位置的方法
- JavaScript中getBoundingClientRect() 方法返回元素的大小及其相对于视口的位置。
- MFC 获取picture控件的鼠标点击坐标位置的方法
- JS 获取DIV中鼠标相对位置的方法
- android 小米手机弹出框(自定义dialog)位置不居中解决方法
- JQuery 获得绝对,相对位置的坐标方法