我希望通过点击图像将位置480,380上的另一个图片框图像设置为一个图片框图像。我不知道如何设置以及在哪里编写代码。像颈部一样会通过点击添加到客户图像颈部。紧急和我会感谢你。
答案 0 :(得分:0)
这不一定是“最佳”答案,但如果你使用的是visual express IDE,它可能是最简单的,你说你很匆忙。
1)在表单中创建一个图片框(pictureBox1或默认情况下调用的任何图片框)。
2)双击表单以创建表单加载功能。它应该看起来像:
private void Form1_Load(object sender, EventArgs e) {
}
3)添加代码以创建另一个图片框并将其添加到您的第一个图片框:
PictureBox ChildBox;
private void Form1_Load(object sender, EventArgs e) {
ChildBox = new PictureBox();
ChildBox.Visible = false;
ChildBox.Location = new Point(0, 0); // change this to your coordinates, 480 by 380
// the next 2 lines are just so that you can see the changes
ChildBox.BackColor = Color.Red;
pictureBox1.BackColor = Color.Blue;
pictureBox1.Controls.Add(ChildBox);
}
4)双击表单中的PictureBox1以创建以下存根:
private void pictureBox1_Click(object sender, EventArgs e) {
}
5)将其更改为
private void pictureBox1_Click(object sender, EventArgs e) {
ChildBox.Visible = true;
}
这将使图片框“出现”在您想要的坐标处。
答案 1 :(得分:0)
一个简单的例子
private List<Tuple<Image, int, int>> images = new List<Tuple<Image, int, int>>();
private void Form1_Load(object sender, EventArgs e)
{
//load the customer image
this.picBoxTarget.BackgroundImage = Image.FromFile(...);
//load the necklaces image
this.picBoxSource.Image = Image.FromFile(...);
}
private void picBoxSource_Click(object sender, EventArgs e)
{
if (this.picBoxSource.Image == null)
return;
//when click the picBoxSource, add the image to list
//(you may need to check whether there is another one necklace in the list, if not allowed to wear two)
this.images.Add(Tuple.Create(this.picBoxSource.Image, 480, 380));
//and make the picBoxTarget redraw
this.picBoxTarget.Invalidate();
}
private void picBoxTarget_Paint(object sender, PaintEventArgs e)
{
foreach (var img in this.images)
e.Graphics.DrawImage(img.Item1, img.Item2, img.Item3);
}