失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > c#拼图碎片形状 用c#制作图片拼图

c#拼图碎片形状 用c#制作图片拼图

时间:2019-09-12 11:53:44

相关推荐

c#拼图碎片形状 用c#制作图片拼图

I added the 35 PictureBox to the form at the design stage and ı want to assign these picturebox to array but ı cant do this please help me about this subject!

解决方案First, you don''t need PictureBoxs to do this, at all. You just need to draw the portions of the image you need where you need them. Using picbox controls just complicates things for you.

What is an array going to do for you? Nothing...

The code below worked for me:

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace TestTabs

{

public partial class Form1 : Form

{

List pictureBoxes;

public Form1()

{

pictureBoxes = null;

InitializeComponent();

}

private List collectPictureBoxes(List collection, Control me)

{

foreach (Control ctrl in me.Controls)

{

if (ctrl.GetType() == typeof(PictureBox))

{

collection.Add((PictureBox)ctrl);

}

if (ctrl.HasChildren)

{

collectPictureBoxes(collection, ctrl);

}

}

return collection;

}

private void Form1_Load(object sender, EventArgs e)

{

pictureBoxes = collectPictureBoxes(new List(), this);

foreach (PictureBox pb in pictureBoxes)

{

MessageBox.Show(pb.Name);

}

}

}

}

Regards,

—MRB

I woudln''t assign them as design time: I would just go straight in at run time. The reason for that is that is that there is no real occasion when you want to refer to the PictureBoxes by name, just by position relative to a 6x6 array. In actual fact, I probably wouldn''t use Pictureboxes anyway, but would draw directly onto a panel instead, and have a 6x6 array of integers to tell me which section of the picture should be in which square. But, picture boxes will work too.

If you must create them at design time, then creating an array of them isn''t too difficult - it''s just messy:

private PictureBox[,] pictures;

private void SetPictures()

{

pictures = new PictureBox[6, 6] {

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox2, pictureBox3},

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox2, pictureBox3},

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox2, pictureBox3},

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox2, pictureBox3},

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox2, pictureBox3},

{pictureBox1, pictureBox2, pictureBox3, pictureBox1, pictureBox35, null},

};

}(You have to do it in a method, as the compiler won''t let you use non-static field initializers)

You will have to change the names - I cut''n''pasted to get the 35 I needed.

如果觉得《c#拼图碎片形状 用c#制作图片拼图》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。