帮助我GetChildAtPoint [英] help me on GetChildAtPoint

查看:125
本文介绍了帮助我GetChildAtPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码。每次我运行程序它返回null.can你解决这个问题吗?

this is my code.every time i run the program it returns null.can you solve this?

Point P = new Point(64, 46);
           Control locatecontrol =this.GetChildAtPoint(P);
           Button BTN1 = new Button();
           BTN1 = (Button)locatecontrol;
           MessageBox.Show(BTN1.Text);



i有一个Button但又一次为null:|

帮助我。

i已经搜索了这个但是我无法解决我的代码。


i have a Button there but again null :|
help me.
i have searched for this but i could not solve my code.

推荐答案

如果在适当的位置有一个Button,它对我来说很好用。

我稍微改了一下,用作为代替我自己(或者你可以得到例外):

It works fine for me, if there is a Button at the appropriate point.
I'd change it slightly and use as instead myself (or you could get casting exceptions):
Point p = new Point(64, 46);
Control c = GetChildAtPoint(p);
Button btn1 = c as Button;
if (btn1 != null)
    {
    MessageBox.Show(btn1.Text);
    }





假设此时有一个按钮,它应该可以工作,但是要设置一个断点代码的第一行并逐步查看变量 - 你需要知道GetChildAtPoint返回的是有问题。



Assuming there is a button at the point, it should work, but put a breakpoint on the first line of the code and step through looking at the variables - you need to know what GetChildAtPoint is returning is there is a problem.


你使用 RightToLeft

改回 LeftToRight 或mybe可以使用





you use RightToLeft
change back to LeftToRight or mybe can use


if(this.RightToLeft==System.Windows.Forms.RightToLeft.Yes)
   pos.x=Width-pos.x;


这篇关于帮助我GetChildAtPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆