图片框问题
我有一个问题:
我有 3 个图片框,其中有 3 个不同的图像如图像,
我可以将什么设置为pictureBox3,以便两个图像看起来相同......
编辑: 我想将 pictureBox3 移动到 pictureBox2 上,
因此没有选项将它们合并为单个图像
I have a problem:
I have 3 picture boxes with 3 different images as in Image
what can i set to pictureBox3 so both images look same.....
EDITED:
I want to move pictureBox3 on pictureBox2,
So there is no Option to merge them to single image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
确保
pictureBox3
中的图像是透明的。将BackColor
设置为透明。在代码中,将pictureBox3
的Parent
属性设置为pictureBox2
。调整pictureBox3
的Location
坐标,因为更改Parent
后它们将相对于pictureBox2
的坐标>。在设计器中你不会看到透明度,但在运行时你会看到。
更新
图中,左侧显示设计器视图,右侧是运行时版本。
另一个更新
我真的不知道了解这怎么可能不适合你。我想我们一定在做一些不同的事情。我将描述创建工作示例所需的确切步骤。如果您遵循完全相同的步骤,我想知道我们是否会得到相同的结果。接下来的步骤描述了要做什么并使用我在网上找到的两张图像。
现在将以下代码放入表单的 OnLoad 事件处理程序中:
就是这样!如果我运行这个程序,我会在另一个图像之上得到一个透明图像。
Make sure the image in
pictureBox3
is transparent. Set theBackColor
to transparent. In code, set theParent
property of thepictureBox3
to bepictureBox2
. Adjust theLocation
coordinates ofpictureBox3
since they will be relative to the coordinates ofpictureBox2
once you've changed theParent
.In designer you will not see the transparency, but at runtime you will.
Update
In the image, the left side shows the designer view, the right side is the runtime version.
Another update
I really don't understand how it would be possible that this doesn't work for you. I suppose there must be something we are doing different. I'll describe the exact steps to take to create a working sample. If you follow the exact same steps, I wonder if we'll get the same results or not. Next steps describe what to do and use two images I found on the net.
Now place the following code in the form's OnLoad event handler:
That's it! If I run this program I get a transparent image on top of another image.
我将添加另一个示例,根据更新的要求允许移动 image3。
要使其正常工作,请将透明图像放入
Resources\transp.png
这对所有三个图像使用相同的图像,但您可以简单地将 image1 和 image2 的透明Img 替换为合适的图像。
演示启动后,可以将中间图像拖放到表单周围。
I'll add another example that according to the updated requirement allows for moving image3.
To get it working, put an image with transparency in
Resources\transp.png
This uses the same image for all three images, but you can simply replace transparentImg for image1 and image2 to suitable images.
Once the demo is started the middle image can be dragged-dropped around the form.
这段代码可以解决这个问题:
它将在 pictureBox1 的现有图像上绘制 pictureBox2 中的图像。
This code will do the trick:
It will draw the image from pictureBox2 on the existing image of pictureBox1.
首先,将 PictureBox3 的
BackColor
属性设置为透明。这应该适用于几乎所有情况。您还应该使用具有透明背景的图像而不是白色,这样紫色圆圈周围就不会出现白色边框。 (推荐图片格式:PNG)
更新
根据我收到的回复,将
BackColor
设置为透明似乎不起作用。在这种情况下,最好处理 PictureBox 的Paint
事件,并自己绘制新图像,如 阿尔宾建议。For starters, set the
BackColor
property of PictureBox3 to Transparent. This should work in almost all cases.You should also use an image with a transparent background instead of white so you do not have the white borders around your purple circle. (Recommended image format: PNG)
Update
Following the replies I got, it appears setting the
BackColor
to Transparent doesn't work. In that case, it's best you handle thePaint
event of the PictureBox and do the painting of the new image yourself as Albin suggested.您可以通过覆盖 OnPaint 等进行一些黑客攻击,例如 这里。
但我建议将 pictureBox2 和 3 中的图片合并为单个图像,然后再将它们显示在单个 pictureBox 中。
You might do some hack by overriding OnPaint and stuff, example here.
But I'd recommend to merge the pictures in pictureBox2 and 3 into a single image before displaying them in a single pictureBox.