窗体停靠位置讨教

.Net技术 码拜 9年前 (2016-03-02) 697次浏览
想实现在textbox中输入字符后,弹出一个窗口,这个窗口的显示的是按照输入字符搜索出的数据(已实现),希望这个窗口
的位置应该在textbox下沿部,实现的代码:

    string var = textBox1.Text;
            var screenPoint = LocationOnClient(this.textBox1);
            screenPoint.Y += this.textBox1.Height;
            
            Form f = new Form();
            f.Width = 500;
            f.Height = 500;
            f.FormBorderStyle = FormBorderStyle.None;
            f.Location = screenPoint;
            f.Show();

LocationOnClient 是网上找到的一段获得控件位置的代码:

private Point LocationOnClient(Control c)
        {
            Point retval = new Point(0, 0);
            for (; c.Parent != null; c = c.Parent)
            {
                retval.Offset(c.Location);
            }
            return retval;
        }

运行后,窗体出来的效果是这样的:
窗体停靠位置讨教
要怎么样做才能达到窗体停靠在textbox的下部?就像百度搜索框那样的效果?谢谢

解决方案

30

有坐标 什么都好说
Rectangle rect = 控件.RectangleToScreen(控件.DisplayRectangle);

30

http://www.cnblogs.com/libaoheng/archive/2011/07/20/2112032.html

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明窗体停靠位置讨教
喜欢 (0)
[1034331897@qq.com]
分享 (0)