Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 为什么按钮处于偏移位置_.net_Vb.net_Coordinates_Offset - Fatal编程技术网

.net 为什么按钮处于偏移位置

.net 为什么按钮处于偏移位置,.net,vb.net,coordinates,offset,.net,Vb.net,Coordinates,Offset,代码如下: Dim nBtn As New Button PictureBox1.Controls.Add(nBtn) nBtn.Text = "Click Me" nBtn.Location = Cursor.Position ' or mouseposition = same result 这就是它看起来的样子。。它离我最初点击的地方大约2英寸远。我的代码甚至没有偏移它的位置,那么这是怎么发生的呢? 这是位于SplitContainer右侧的图片框表示相对于控件容

代码如下:

Dim nBtn As New Button
    PictureBox1.Controls.Add(nBtn)
    nBtn.Text = "Click Me"
    nBtn.Location = Cursor.Position ' or mouseposition = same result

这就是它看起来的样子。。它离我最初点击的地方大约2英寸远。我的代码甚至没有偏移它的位置,那么这是怎么发生的呢?
这是位于SplitContainer右侧的图片框

表示相对于控件容器的位置(或者更确切地说,它的左上点)

(和)指相对于屏幕左上角的位置

因此,如果控件的容器恰好位于屏幕的左上角,则代码将正常工作。否则,它将被偏移,如您所见。你应该看看这些方法是否对你有帮助;文档对我来说并不完全清楚,但它们可能正是您所需要的。例如:

nBtn.Location = PictureBox1.PointToClient(Cursor.Position)
您能否创建一个简短但完整的程序来演示问题?