c#如何从表单1更改字符串从按钮单击表单2
我正在创建一个僵尸生存RPG游戏,我想当我按下一个按钮(“主游戏”窗体中的“移动”按钮)时,所有“注意”窗体中的字符串都会变成我想要的任何字符串。(当点击移动按钮时,玩家可以看到与上次不同的项目。) 这是我的密码: 表格1(按钮移动点击)c#如何从表单1更改字符串从按钮单击表单2,c#,winforms,C#,Winforms,我正在创建一个僵尸生存RPG游戏,我想当我按下一个按钮(“主游戏”窗体中的“移动”按钮)时,所有“注意”窗体中的字符串都会变成我想要的任何字符串。(当点击移动按钮时,玩家可以看到与上次不同的项目。) 这是我的密码: 表格1(按钮移动点击) 请做一份财产清单,例如: public string YourString { { get; set; } }, 因此,在创建表单Look_out后传递值,您可以使用以下代码执行此操作: Form1.cs using System; using Sys
请做一份财产清单,例如:
public string YourString
{
{ get; set; }
},
因此,在创建表单Look_out后传递值,您可以使用以下代码执行此操作: Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.theVariable = textBox1.Text;
form2.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
public string theVariable //This is your method to pass the string to the new form (Form2)
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
}
}
Form2.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.theVariable = textBox1.Text;
form2.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
public string theVariable //This is your method to pass the string to the new form (Form2)
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
}
}
您需要在