publicpartialclassadd : Form
{
String text;
staticFileStream fs1 = newFileStream(@"c:\std.txt", FileMode.Append, FileAccess.Write);
StreamWriter tw = newStreamWriter(fs1);
public add()
{
InitializeComponent();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
}
publicvoid button1_Click(object sender, EventArgs e)
{
tw.WriteLine(merge);
label1.Text = merge;
tw.Flush();
}
publicString merge
{
get
{
return
text =
"fname= " + nametxt.Text + "," + "lname= " + familytxt.Text + "," + "id= " + idtxt.Text + "," + "average= " + avgtxt.Text + "#";
}
}
protectedoverridevoid OnFormClosing(FormClosingEventArgs e)
{
MessageBox.Show("Closing", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
fs1.Close();
}
}
public
partialclassfind : Form
{
staticFileStream fs2 = newFileStream(@"c:\std.txt", FileMode.OpenOrCreate, FileAccess.Read);
StreamReader tr = newStreamReader(fs2);
String regmatch;
Boolean found;
string text;
public find()
{
InitializeComponent();
}
privatevoid find_Load(object senarrayder, EventArgs e)
{
fs2.Position = 0;
}
privatevoid findbtn_Click(object sender, EventArgs e)
{
if (findtxt.Text.Length < 6)
MessageBox.Show("ID must be at least 6 number!");
else
{
regmatch = "";
regmatch = findtxt.Text;
findtxt.Text = "";
fs2.Position = 0;
text = (tr.ReadLine());
while ((text = tr.ReadLine()) != null)
{
// findlbl.Text = "w";
text =
"";
text = (tr.ReadLine());
if (text.Contains(regmatch))
{
found = true;
listBox1.Items.Add(text);
}
}
if (found == false)
MessageBox.Show("not found");
}
}
protectedoverridevoid OnFormClosing(FormClosingEventArgs e)
{
MessageBox.Show("Closing", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
fs2.Close();
}
}
public
partialclassMain : Form
{
public Main()
{
InitializeComponent();
}
privatevoid ToolStripMenuItem_Click(object sender, EventArgs e)
{
add add;
add = newadd();
add.Show();
add.SetDesktopLocation(50, 50);
add.Activate();
//this.Close();
}
privatevoid ToolStripMenuItem1_Click(object sender, EventArgs e)
{ find fnd;
fnd= newfind();
fnd.Show();
fnd.SetDesktopLocation(50, 50);
fnd.Activate();
}
}
با تغييراتي كه دادم، وقتي فرم ها رو باز ميكنم بار اول مشكلي نداره و هر دوشو باز ميكنه. ولي اگه براي بار دوم بخوام از منو يكيشو باز كنم ارور(stream was not readable(writable رو ميده