1) 将 form1 引用传递给 form2 的构造函数:
Form2 dataWindow = new Form2(this);
dataWindow.Show();
...
private form1 as Form1;
public Form2(Form1 frm1)
{
form1 = frm1;
}
然后在 Form2s TrackBar_Scroll 事件中通过私有成员变量 form1 引用 PictureBox:form1.PictureBox1.Property
2)使用 PictureBox 放大您的图片,以便您可以使用鼠标滚轮进行缩放
更好的方法是事件:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var form2 = new Form2();
form2.TrackBarMoved += new Action<int>(ZoomPictureBox);
form2.ShowDialog();
form2.TrackBarMoved -= new Action<int>(ZoomPictureBox);
}
private void ZoomPictureBox(int zoomFactor)
{
pictureBox1.Width = 100 * zoomFactor;
pictureBox1.Height = 100 * zoomFactor;
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public event Action<int> TrackBarMoved;
private void trackBar1_Scroll(object sender, EventArgs e)
{
TrackBarMoved(trackBar1.Value);
}
}