■■请问:如何获得窗体上控件相对于屏幕的位置?(Winform)■■

WindDirection 2004-10-15 12:00:43
可以通过int var = this.Left获得窗体相对于屏幕的位置(Left或Top)
窗体中有控件panel1,它的Left或Top属性则是相对于窗体的。
如何获得panel1相对于屏幕的位置?

难道只能用this.Top + this.panel1.Top的方法吗?
...全文
1261 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Uncommon 2004-10-22
  • 打赏
  • 举报
回复
// All methods must be contained in a class.
// This class is added to the namespace containing the Form1 class.
class MainApplication
{
public static void Main()
{
// Instantiate a new instance of Form1.
Form1 f1 = new Form1();
// Display a messagebox. This shows the application
// is running, yet there is nothing shown to the user.
// This is the point at which you customize your form.
System.Windows.Forms.MessageBox.Show("The application "
+ "is running now, but no forms have been shown.");
// Customize the form.
f1.Text = "Running Form";
// Show the instance of the form modally.
f1.ShowDialog();
}
}

http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbtsksettingformtobeinvisibleatitsinception.asp


使用twips获得屏幕信息

http://www.zdnet.com.cn/developer/code/story/0,2000081534,39191403,00.htm
WindDirection 2004-10-20
  • 打赏
  • 举报
回复
up
_jfeng 2004-10-15
  • 打赏
  • 举报
回复
楼主方法何尝不可呢,我觉得很好啊
张海霖 2004-10-15
  • 打赏
  • 举报
回复
api应该可以
CSTerry 2004-10-15
  • 打赏
  • 举报
回复
Point po=PointToScreen(new Point(button1.Left,button1.Top));
可以的啊
WindDirection 2004-10-15
  • 打赏
  • 举报
回复
还是不行啊。
5555
BearRui 2004-10-15
  • 打赏
  • 举报
回复
Point FrmP=new Point(button1.Left,button1.Top);
//ScreenP返回相对屏幕的坐标
Point ScreenP=this.PointToScreen(FrmP);
BearRui 2004-10-15
  • 打赏
  • 举报
回复
Control.PointToScreen 方法请参见
将指定工作区点的位置计算成屏幕坐标。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧