我有一个 10 行 4 列的 GUI。它的目的是让我在每个框中输入输入,然后在底部单击提交按钮,它会给我一个包含所有输入的文件。我遇到的问题是如何编码我的“按钮”来做到这一点?帮助?
我的菜单条也有问题。似乎一切都是正确的,但我的视觉不会接受。我的代码有问题吗?
-- 这是我第一次使用 C# 和视觉,所以任何帮助将不胜感激!
Public partial class Form 1 : Form
{
int count;
Form mdiChild;
TextBox editTextBox;
public Form1()
{
InitializeComponent();
count = 1;
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
mdiChild = new Form();
mdiChild.Text = “Document” + count.ToString();
mdiChild.MdiParent = this;
editTextBox = new TextBox();
editTextBox.Multiline = true;
editTextBox.Dock = Dockstyle.Fill;
mdiChild.Controls.Add(editTextBox);
mdiChild.Show();
count++;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = “Open a Text File”;
ofd.Filter = “Text File (*.txt)|*.txt|All Files (*.*)|*.*”;
DialogResult dr = ofd.ShowDialog();
If (dr == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamREader(ofd.FileName);
Form activeChildForm = this.ActiveMdiChild;
If (activeChildForm != null)
activeTextBox.Text = sr.ReadToEnd();
{
System.IO.StreamReader sr = new System.IO.StreamREader(ofd.FileName);
Form activeChildForm = this.ActiveMdiChild;
If (activeChildForm != null)
activeTextBox.Text = sr.ReadToEnd();
sr.Close();
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = “Save a Text File”;
sfd.Filter = “Text File (*.txt)|*.txt|All Files (*.*)|*.*”;
DialogResult dr = sfd.ShowDialog();
If (dr == DialogResult.OK)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName);
Form activeChildForm = this.ActiveMdiChild;
If (activeChildForm != null)
{
TextBox activeTextBox = (TextBox)activeChildForm.ActiveControl;
If (activeTextBox != null)
sw.Write(activeTextBox.Text);
sw.Close();
}
}
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form activeChildForm = this.ActiveMdiChild;
if (activeChildForm != null)
{
TextBox activeTextBox = (TextBox)activeChildForm.ActiveControl;
if (activeTextBox != null)
activeTextBox.Cut();
}
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Form activeChildForm = this.ActiveMdiChild;
if (activeChildForm != null)
{
TextBox activeTextBox = (TextBox)activeChildForm.ActiveControl;
if (activeTextBox != null)
activeTextBox.Copy();
}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
Form activeChildForm = this.ActiveMdiChild;
if (activeChildForm != null)
{
TextBox activeTextBox = (TextBox)activeChildForm.ActiveControl;
if (activeTextBox != null)
activeTextBox.Paste();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
String file_name = “C:\\test1.txt”;
System.IO.StreamReader objReader;
objReader = new System.IO.StreamReader(file_name)l
textBox1.Text = objReader.ReadToEnd();
objReader.Close();
}
Private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start (“ “);