我有问题:
我有3个带有3个不同图像的图片框 as in Image
我可以设置为 pictureBox3 所以两个图像看起来都一样.....
EDITED: 我想在pictureBox2上移动pictureBox3,
因此没有选择将它们合并到单个图像中
- 2021-1-111 #
- 2021-1-112 #
确保在
pictureBox3
中显示图像 是透明的.设置BackColor
透明.在代码中,设置Parent
pictureBox3
的属性 成为pictureBox2
.调整Location
pictureBox3
的坐标 因为它们将相对于pictureBox2
的坐标 一旦您更改了Parent
private void Form1_Load(object sender, EventArgs e) { pictureBox3.Parent = pictureBox2; pictureBox3.Location = new Point( pictureBox3.Location.X - pictureBox2.Location.X, pictureBox3.Location.Y - pictureBox2.Location.Y); }
在设计器中您不会看到透明性,但是在运行时您将看到透明性。
Update
在图像中,左侧显示设计器视图,右侧是运行时版本。
Another update
我真的不明白这怎么可能对您不起作用.我想我们必须做些不同的事情.我将描述创建工作样本所要采取的确切步骤.如果您遵循完全相同的步骤,我想知道我们是否会获得相同的结果.后续步骤描述了如何使用并使用我在网上发现的两张图片。
Using Visual Studio 2008, create a New Project using template Windows Forms Application. Make sure the project is targeted at the .NET Framework 3.5.
Set the Size of the Form to 457;483.
Drag a PictureBox control onto the form. Set its Location to 0;0 and its Size to 449;449.
Click the ellipsis besides its Image property, click the Import... button and import the image at http://a.dryicons.com/files/graphics_previews/retro_blue_background.jpg (just type the URL in the File name text box and click Open). Then click OK to use the image.
Drag another PictureBox onto the form, set its Location to 0;0 and its Size to 256;256. Also set its BackColor property to Transparent.
Using the same method as described above, import image http://www.axdn.com/redist/axiw_i.png which is a transparent image.
Now place the following code in the form's OnLoad event handler:
private void Form1_Load(object sender, EventArgs e) { pictureBox2.Parent = pictureBox1; }
就是这样! 如果我运行此程序,则会在另一个图像的顶部获得透明图像。
- 2021-1-113 #
对于初学者,请设置
BackColor
PictureBox3的"透明"属性.几乎在所有情况下都可以使用。您还应该使用背景透明而不是白色的图像,这样紫色圆圈周围就不会出现白色边框. (推荐图片格式:PNG)
Update
在收到我的回复后,似乎设置了BackColor
透明不起作用.在这种情况下,最好您处理Paint
PictureBox事件,并按照Albin的建议自己绘制新图像。 - 2021-1-114 #
此代码可以解决问题:
using (Graphics g = Graphics.FromImage(pictureBox1.Image)) { g.DrawImage(pictureBox2.Image, (int)((pictureBox1.Image.Width - pictureBox2.Image.Width) / 2), (int)((pictureBox1.Image.Height - pictureBox2.Image.Height) / 2)); g.Save(); pictureBox1.Refresh(); }
它将在pictureBox1的现有图像上绘制来自pictureBox2的图像。
- 2021-1-115 #
您可能会通过覆盖OnPaint和其他内容(例如此处的示例)来进行一些破解。
但是我建议将pictureBox2和3中的图片合并为一个图像,然后再将其显示在单个pictureBox中。
相关问题
- c#:获取windows 8自动颜色主题的活动颜色c#netwpfwinapiwindows82021-01-12 01:28
- c#:如果路径受保护,请求windows Vista UAC提升吗?c#netwindowsvistauacelevatedprivileges2021-01-11 20:27
- c#:设置TabPage标头颜色c#winformscolorsheadertabcontrol2021-01-11 04:59
- c#:静态和实例方法同名?c#netoop2021-01-11 05:55
- c#:RequestUrlReferrer为空?c#netvisualstudiovisualstudio20082021-01-11 07:24
- c#:NET 40和可怕的OnUserPreferenceChanged挂起c#netmultithreadingclrdeadlock2021-01-11 12:56
我将添加另一个示例,根据更新的要求,该示例允许移动图像3。
为了使其正常工作,请将透明图像放入
Resources\transp.png
这对所有三个图像都使用相同的图像,但是您只需将image1和image2的transparentImg替换为合适的图像即可。
演示开始后,可以将中间图像拖放到表单周围。