【发布时间】:2011-12-05 01:39:38
【问题描述】:
我想知道,您如何获得表格的坐标?
我有一个当前有一个按钮的应用程序。此按钮随机每 1 秒重新定位一次。但是,我希望此按钮始终在表单内重新定位 - 而不是超出表单的范围。所以,我在想我应该找到表单的边界并使用它来确保按钮始终在表单的边界内。我如何获得表格的高度和宽度?
我有以下代码工作(但用户的屏幕尺寸不是我想要的):
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
这段代码不应该工作吗?
int xPosition = position.X;
int yPosition = position.Y;
int num = random.Next(screenHeight);
int num1 = random.Next(screenWidth);
Point templocation;
templocation = new Point(num1, num);
ClickMe.Location = templocation;
templocation.X = num1;
templocation.Y = num;
任何帮助将不胜感激。
PS。我已经查看了这个网站http://msdn.microsoft.com/en-us/library/system.windows.forms.control.resize(v=vs.71).aspx,但是“Control control = (Control)sender;”这一行产生错误...
【问题讨论】:
标签: c# forms resize height width