表格C#之间的链接信息 [英] linking information between forms C#

查看:47
本文介绍了表格C#之间的链接信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个小问题,这是完成项目之前我要做的最后一件事.

I have a little problem, this is the last thing I have to do before I can finish my project.

我有一个来自女巫的随机密钥生成器,运行正常, 现在我添加了一个保存按钮来保存已生成的密钥,当您单击保存"时,它会打开通过右键单击项目中的我添加的新表格 解决方案资源管理器,然后单击添加新项.

I have a from witch is a random key generator, works perfectly,  now what I did is added a save button to save the key that has been generated, when you click save it opens a new form which I added by right clicking on my project in the solution explorer and clicking add new item.

现在我有2种形式,我添加的第二种形式是我添加的自定义消息框,您可以在其中选择保存在名称下生成的密钥,您所要做的就是键入您想要的名称保存为您,然后应该将其保存在记事本中 像这样的文档

Now I have 2 forms, the second for I added is a custom message box I added, where you can choose to save the key you generated under a name, all you have to do is type in the name you want it to save as for you and then it is supposed to save it in the notepad doc like this

彼得2bc4t

不只是数字,而且您不知道它的用途或用途

Instead of just numbers and you don’t know what or who it has been used for

所以我的问题是它没有做到这一点

So the problem I have is that it doesn’t do that

这是我在第一种形式中保存的代码(我刚刚保存了代码,而没有第二种形式将其保存为名称)

Here is the code I had in the 1st form (where I just saved the code and didn’t have a second form to save it under a name)

字符串tempFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+" \\ Password. txt";

;   如果(!File.Exists(tempFile))

            if (!File.Exists(tempFile))

;       System.IO.File.WriteAllText(tempFile,textBox1.Text);

                System.IO.File.WriteAllText(tempFile, textBox1.Text);

;   else

            else

;       System.IO.File.AppendAllText(tempFile,``\ r \ n''+ textBox1.Text);

                System.IO.File.AppendAllText(tempFile, "\r\n" + textBox1.Text);

添加第二个表单时,我将表单1上的保存按钮更改为此代码以打开form2 CustomMsgBox formcustommsgbox = CustomMsgBox ();

When I added the second form, I changed the save button on form 1 to this code to open form2 CustomMsgBox formcustommsgbox = new CustomMsgBox();

;      formcustommsgbox.Show();

                formcustommsgbox.Show();

然后在form2的保存"按钮中有这个按钮(这是行不通的,因为我无法链接这两个表单,或者无法获得第二个表单来使用来自form1文本框中的文本)

Then in form2’s save button I have this (Which doesn’t work because I can’t link the 2 forms or I can’t get the second form to use the text from form1’s textbox)

我尝试了{get,set}并将其设置为公开字符串<-嗯,没有命令:-/

I tried {get, set} and making it a public sting <-- ummm, no commen :-/

注意:问题尚未说明

private 无效 savebtn_Click(对象发​​件人, EventArgs e)

private void savebtn_Click(object sender, EventArgs e)

   {

        {

      如果(saveastextBox.Text.Length> = 1)

            if (saveastextBox.Text.Length >= 1)

      {

            {

      字符串 tempFile = 环境 .GetFolderPath(环境. SpecialFolder .Desktop)+ &; \\ Password.txt"";

            string tempFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Password.txt";

      如果(!文件 .Exists(tempFile))

            if (!File.Exists(tempFile))

          System.IO.文件 .WriteAllText(tempFile,saveastextBox.Text);

                System.IO.File.WriteAllText(tempFile, saveastextBox.Text);

      其他

            else

          System.IO.文件 .AppendAllText(tempFile, " \ r \ n" + saveastextBox.Text +

                System.IO.File.AppendAllText(tempFile, "\r\n" + saveastextBox.Text + the text form textbox1 in my first form :-/);

      }

            }

      其他 MessageBox .显示(" ;请使用名称");

            else MessageBox.Show("Please save the generated key under a name");

   }

        }

推荐答案

您可以更改CustomMsgBox,使其具有Form1类型的私有成员,并传递"this".到其构造函数,以便您可以使用_form1.textbox1.Text
You can change CustomMsgBox so that it has a private member of type Form1 and pass "this" to its constructor so that you can use _form1.textbox1.Text


这篇关于表格C#之间的链接信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆