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 (“ “);