public void func() { rgb = null; gg = null; }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left)//如果按下鼠标左键 { isMove = true; x = Cursor.Position.X;//把移动之后的光标的位置赋给Point_XY便于下一个位置的计算 y = Cursor.Position.Y; } //显示像素值 if (bands == 3) { if (rgb == null) { rgb = new pixel3(); int ex = e.X / pictureBox1.Width * newBitmap.Width - pictureBox1.Location.X; int ey = e.Y / pictureBox1.Height * newBitmap.Height - pictureBox1.Location.X; if (ex >= cols || ey >= rows || ex < 0 || ey < 0) { rgb.label2.Text = "error!"; rgb.label3.Text = "error!"; rgb.label5.Text = "error!"; return; } rgb.label2.Text = newdata[0, ey, ex].ToString(); rgb.label3.Text = newdata[1, ey, ex].ToString(); rgb.label5.Text = newdata[2, ey, ex].ToString(); } else if (rgb.Visible == true) { int ex = e.X / pictureBox1.Width * newBitmap.Width - pictureBox1.Location.X; int ey = e.Y / pictureBox1.Height * newBitmap.Height - pictureBox1.Location.X; if (ex >= cols || ey >= rows || ex < 0 || ey < 0) { rgb.label2.Text = "error!"; rgb.label3.Text = "error!"; rgb.label5.Text = "error!"; return; } rgb.label2.Text = newdata[0, ey, ex].ToString(); rgb.label3.Text = newdata[1, ey, ex].ToString(); rgb.label5.Text = newdata[2, ey, ex].ToString(); } } if (bands == 1) { if (gg == null) { gg = new gray(); int ex = (int)((double)e.X / (double)pictureBox1.Width * (double)newBitmap.Width - (double)pictureBox1.Location.X); int ey = (int)((double)e.Y / (double)pictureBox1.Height * (double)newBitmap.Height - (double)pictureBox1.Location.Y); if (ex >= cols || ey >= rows || ex < 0 || ey < 0) { gg.label2.Text = "error!"; return; } gg.label2.Text = newdata[0, ey, ex].ToString(); } else if (gg.Visible == true) { int ex = (int)((double)e.X / (double)pictureBox1.Width * (double)newBitmap.Width - (double)pictureBox1.Location.X); int ey = (int)((double)e.Y / (double)pictureBox1.Height * (double)newBitmap.Height - (double)pictureBox1.Location.Y); if (ex >= cols || ey >= rows || ex < 0 || ey < 0) { gg.label2.Text = "error!"; return; } gg.label2.Text = newdata[0, ey, ex].ToString(); } } if (rgb != null) { rgb.FormClosing += (ss, ee) => { func(); }; } if (gg != null) { gg.FormClosing += (ss, ee) => { func(); }; } }