O'Reilly Forums: Simlpe Form For Textbox Int - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Simlpe Form For Textbox Int

#1 User is offline   RK_Takashi 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 21-October 12

Posted 21 October 2012 - 06:37 PM

Dear Sir:
I am new at C# and I have a question as following. My original code is:
using System.IO;

namespace WindowsTest
{
public partial class Form1 : Form
{
public TextBox TextBoxlist(int index)
{
TextBox [] textlist={textBox1,textBox2};
return textlist[index];
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
ReadFile();
}

private void button1_Click(object sender, EventArgs e)
{
CreateFile();
}
public void CreateFile()
{
try
{
StreamWriter writer = new StreamWriter("Savefile.txt", false);
for (int i = 0; i < 2; i++)
{
writer.WriteLine(TextBoxlist(i).Text);
}

writer.Close();
MessageBox.Show("Saved Successfully");
}
catch
{
MessageBox.Show("Saved Faild");
}
}
public void ReadFile()
{
try
{
StreamReader reader = new StreamReader("Savefile.txt"); // using System.IO;
string readerStr = reader.ReadLine();
int inde = 0;
while (inde < 2)
{
TextBoxlist(inde).Text = readerStr;
readerStr = reader.ReadLine();
inde++;
}
reader.Close();
}
catch
{
}
}
}
}

But now I had many TextBox ( more then 100), could you plese teach how to write a simple code insteal
TextBox [] textlist={textBox1,textBox2,textBox3,textBox4,textBox5 ............};

Thank you.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users