将按钮与Picturebox VB/C#一起移动 [英] move button along with picturebox vb/c#
问题描述
我正在处理映射的DVR/cctv UI.
我自己制作的,所以没有使用Google的API.我只是在需要的地方剪掉了大部分地图.
I am working on a mapped DVR/cctv UI.
I made it myself, so I did not use google's API. I just cut off big part of the map where I need it.
所以,如果我确实有一个很大的地图,那么它将不适合我的PC的分辨率,我还没有找到将图片移入pictureBox内的代码,但是我要做的就是将pictureBox移入其中一个面板.然后看起来像一张带有边界的地图. :)
so, if I do have a really big map, then it won't fit in my pc's resolution, I haven't found a code to move the picture inside the pictureBox, but what I did is to move the pictureBox inside a panel. then it looked like a map, with boundaries. :)
现在,我希望能够将此按钮保存/附加到图片上.因此,无论何时何地移动pictureBox,按钮都将随它一起出现.即使超出了表单范围,但当我将其拖回时,它看起来就像是说已附加一样,只是想像googlemap的标记之类的按钮.这就是我想要发生的事情.
now, I want to be able to save/attach this button to the picture.. so whenever and wherever I move the pictureBox, button gets along with it. even if goes outside the form, but when I drag it back, it appears to where it was let's say, attached just imagine the button like googlemap's marker. that's what I wanted to happen.
就像我正在构建自己的离线Google地图..
its like I am building my own offline google map..
如有疑问,请随时提问. TIA
if you have queries, feel free to ask. TIA
推荐答案
只需将按钮添加为图片框的子项即可:
Simply add your button as a child of your picturebox:
button1.Parent = pictureBox1;
//or
pictureBox1.Controls.Add(button1);
然后,您可以使用按钮的Location
属性进行相应的设置,该位置相对于pictureBox,而不是窗体.
Then you can use the Location
property of your button to set it accordingly, that location is relative to your pictureBox, not your form.
如果要保留按钮的设计位置,可以尝试以下代码:
If you want to keep the design location of your button, you can try this code:
Point loc = pictureBox1.PointToClient(button1.PointToScreen(Point.Empty));
button1.Parent = pictureBox1;
button1.Location = loc;
这篇关于将按钮与Picturebox VB/C#一起移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!