我有 2 个 winform,我想在它们之间传递数据。
表格 1 只不过是一个大图片框。
Form2 在表单 1 之上始终保持打开状态。它充当带有退出按钮的半透明控件,我添加了一个轨迹栏。退出按钮工作得很好,但是如果值发生变化,我将无法读取轨迹栏的值。
我想要发生的是,如果跟踪栏的值发生变化,它将值发送到第一个表单并触发一个事件。
我哪里错了?
表格 1 是
public sbyte value
{
get { return Exitform.myValue; }
}
public Fullscreenpreview(string filename)
{
InitializeComponent();
this.pictureBox1.MouseMove += this.pictureBox_MouseMove;
pictureBox1.Image = new Bitmap(filename);
pictureBox1.Refresh();
//to show exit button which is a seperate form
var frm3 = new Exitform();
frm3.FormClosed += (o, e) => this.Close();
frm3.Show();
frm3.TopMost = true;
//to show exit button which is a seperate form
if (myValue != 0)
{
MessageBox.Show("zoinks the value is = " + value);
}
}
表格 2 是
public partial class Exitform : Form
{
private const int CpNocloseButton = 0x200;
private bool mouseIsDown = false;
private Point firstPoint;
public static sbyte myValue = 0;
public Exitform()
{
InitializeComponent();
this.TopMost = false;
}
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CpNocloseButton;
return myCp;
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
firstPoint = e.Location;
mouseIsDown = true;
//http://stackoverflow.com/questions/3441762/how-can-i-move-windows-when-mouse-down
}
private void label1_MouseUp(object sender, MouseEventArgs e)
{
mouseIsDown = false;
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseIsDown)
{
// Get the difference between the two points
int xDiff = firstPoint.X - e.Location.X;
int yDiff = firstPoint.Y - e.Location.Y;
// Set the new point
int x = this.Location.X - xDiff;
int y = this.Location.Y - yDiff;
this.Location = new Point(x, y);
}
}
private void contrast_trackbar_Scroll(object sender, EventArgs e)
{
myValue = 1;
}
}
谢谢安迪