Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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 PictureBox相对于表单的图形坐标_.net_Image_Gdi+_Drawing_Picturebox - Fatal编程技术网

.net PictureBox相对于表单的图形坐标

.net PictureBox相对于表单的图形坐标,.net,image,gdi+,drawing,picturebox,.net,Image,Gdi+,Drawing,Picturebox,我在表格上有一个图片盒 在窗体的加载事件中,我按如下方式创建图形: imageGraphics = Graphics.FromImage(PictureBox1.Image) 然后,在PictureBox\u MouseMove事件中,我绘制椭圆: imageGraphics.FillEllipse(New SolidBrush(brushColor), e.X, e.Y, brushWidth, brushWidth) 不管我怎么做,它总是画不正确的坐标。我尝试了e.Location.Po

我在表格上有一个图片盒

在窗体的加载事件中,我按如下方式创建图形:

imageGraphics = Graphics.FromImage(PictureBox1.Image)
然后,在PictureBox\u MouseMove事件中,我绘制椭圆:

imageGraphics.FillEllipse(New SolidBrush(brushColor), e.X, e.Y, brushWidth, brushWidth)
不管我怎么做,它总是画不正确的坐标。我尝试了e.Location.PointToClient()、PointToScreen()和Cursor.Position。这一切与预期相差甚远(我需要准确地画光标所在的位置)

无论何时调整窗体的大小(也包括PictureBox,因为它的“定位”属性设置为“展开”),图形和光标的相对位置都会发生变化


有什么我遗漏的吗?

这听起来很可疑,好像你的图片盒上的sizeMode不正确。尝试使PictureBox图像的大小与PictureBox图像的大小相同。

虽然这是1.5年前的图像,但获取相对于PictureBox的坐标的正确调用是:

   Dim p1 as point=PictureBox1.PointToClient(Windows.Forms.Cursor.Position)
   imageGraphics.FillEllipse(New SolidBrush(brushColor), p1.X, p1.Y, brushWidth, brushWidth)

我想,这对将来的人会很有用。

如果我把PictureBox制作成与图像相同的大小,它就可以工作了。但我想在PB中保持图像的缩放,这可能吗?最终我决定使用带有自动滚动的容器,将PictureBox SizeMode设置为AutoSize。这就解决了问题。