或者有没有大神可以指点一下我,我现在在做一个拼图软件,我想创建一个公共的画布,让其他Picturebox 可以同时调用这个画布,比如2X2的拼图格式,我就把这画布平均分为四个部分,每加入一副图片,就在这公共画布的四分之一区域加入一副图片,如图所示

但是我不会知道如何定义一个公共的画布 目前只能在一个单独的事件里单独的创建一个画板,我添加第二个图片就变成这样,如图所示

这是我的代码:
private void PictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog file = new OpenFileDialog();
file.InitialDirectory = ".";
file.Filter = "图片格式(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.png)|*.png";
file.ShowDialog();
if (file.FileName != string.Empty)
{
try
{
pathname1 = file.FileName; //获得文件的绝对路径
this.PictureBox1.Load(pathname1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
SaveFileDialog save = new SaveFileDialog();
}
string str1 = pathname1;
str1.Replace(@"\","/");
Image img1 = Image.FromFile(""+str1+"");
Bitmap map1 = new Bitmap(img1);
var width = img1.Width;
var height = img1.Height; ;
// 初始化画布(最终的拼图画布)并设置宽高
Bitmap bitMap = new Bitmap(width*2, height*2);
// 初始化画板
Graphics g1 = Graphics.FromImage(bitMap);
// 将画布涂为白色(底部颜色可自行设置)
g1.FillRectangle(Brushes.White, new Rectangle(0, 0, width, height));
//在x=0,y=0处画上图一
g1.DrawImage(map1, 0, 0, img1.Width, img1.Height);
//在x=0,y在图一往下10像素处画上图二
map1.Dispose();
// map2.Dispose();
Image img = bitMap;
pictureBox3.Image = img;
textBox1.Text = pathname1;
}
private void PictureBox2_Click(object sender, EventArgs e)
{
OpenFileDialog file = new OpenFileDialog();
file.InitialDirectory = ".";
file.Filter = "图片格式(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.png)|*.png";
file.ShowDialog();
if (file.FileName != string.Empty)
{
try
{
pathname2 = file.FileName; //获得文件的绝对路径
this.pictureBox2.Load(pathname2);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
SaveFileDialog save = new SaveFileDialog();
string str2 = pathname2;
str2.Replace(@"\", "/");
Image img2 = Image.FromFile("" + str2 + "");
Bitmap map2 = new Bitmap(img2);
var width = img2.Width;
var height = img2.Height; ;
Bitmap bitMap = new Bitmap(width * 2, height * 2);
// 初始化画板
Graphics g1 = Graphics.FromImage(bitMap);
g1.DrawImage(map2, 0,height, img2.Width, img2.Height);
map2.Dispose();
Image img = bitMap;
pictureBox3.Image = img;
}
}
麻烦各位指点一下