如题,form用来显示图片,在program.cs文件中,已经做了唯一实例的处理,但不知道如何传参然后让form重新显示新的图片:
static class Program
{
public static System.Threading.Mutex MutexRun;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] cmd)
{
bool noRun = false;
MutexRun = new Mutex(true, "HumControl", out noRun); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 frm1 = new Form1();
if (noRun)
{
if (cmd.Length > 0)
{
frm1.strFile = cmd[0];
}
MutexRun.ReleaseMutex();
Application.Run(frm1);
}
else
{
if (cmd.Length > 0)
{
frm1.strFile = cmd[0];
}
//todo 如何写,改变正在运行的frm1的picbox图片变成给定的路径的图片
MessageBox.Show("已有实例正在运行!");
}
}
}
以下是form1.cs文件: public string strFile = @"F:\g.jpg";
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(0, 0);
//this.Size = new System.Drawing.Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
mvPicBox.BackColor = Color.Black;
this.mvPicBox.Image = Image.FromFile(strFile);
}
求高手指点,谢谢
static class Program
{
public static System.Threading.Mutex MutexRun;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] cmd)
{
bool noRun = false;
MutexRun = new Mutex(true, "HumControl", out noRun); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 frm1 = new Form1();
if (noRun)
{
if (cmd.Length > 0)
{
frm1.strFile = cmd[0];
}
MutexRun.ReleaseMutex();
Application.Run(frm1);
}
else
{
if (cmd.Length > 0)
{
frm1.strFile = cmd[0];
}
//todo 如何写,改变正在运行的frm1的picbox图片变成给定的路径的图片
MessageBox.Show("已有实例正在运行!");
}
}
}
以下是form1.cs文件: public string strFile = @"F:\g.jpg";
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(0, 0);
//this.Size = new System.Drawing.Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
mvPicBox.BackColor = Color.Black;
this.mvPicBox.Image = Image.FromFile(strFile);
}
求高手指点,谢谢
frm1.OnLoad();//引发FormLoad事件。
如果不清楚可以新建一个VB的WinForm项目参考
在Form1中定义一个方法:
public void PerformOnLoad()
{
this.OnLoad();
}
设置好frm1.strFile = cmd[0];后
frm1.PerformOnLoad();//引发Form1 OnLoad事件。