以前学Java 现在实习用的是c#,遇到问题了,求大家帮忙啊````如果是控制台程序,感觉自己很容易上手
但是图形化界面一直是瓶颈啊,没有突破口````请看以下程序```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;namespace Demo_082001
{
class Program
{
static void Main(string[] args)
{
string s_FileName1 = @"c:\1.txt";
string s_FileName2 = @"c:\2.txt";
string s_FileName3 = @"c:\3.txt"; using (StreamReader sr1 = new StreamReader(s_FileName1))
{
using (StreamReader sr2 = new StreamReader(s_FileName2))
{
using (StreamWriter sw3 = new StreamWriter(s_FileName3))
{
while (sr1.Peek() >= 0 && sr2.Peek() >= 0)
{
string str1 = sr1.ReadLine(); //读取数据
string str2 = sr2.ReadLine(); string[] a = str1.Split(','); //拆分数据
string[] b = str2.Split('/'); int temp = a.Length ;
string f = "";
for (int i = 0; i < temp-1; i++)
{
if (a[i].Equals(b[i]))
{
f = f + a[i];
} else
{
int q;
Console.WriteLine("********************************");
//Console.WriteLine("These" + "[" + (i+1) + "]" + "rows are wrong...");
//Console.WriteLine(a[i]+" "+b[i]);
Console.WriteLine(str1);
Console.WriteLine(str2);
Console.WriteLine(f);
Console.WriteLine("PLEASE ENTER YOUR CHOOSE,1,化为一 ,2,化为二");
q = int.Parse(Console.ReadLine()); if (q ==1)
{
f = f + a[i];
Console.WriteLine(f);
continue;
} else if(q ==2)
{
f=f+b[i];
Console.WriteLine(f);
continue;
}
}
}
Console.WriteLine(f);
}
}
}
}
}
}
}
我想换成图形化界面``` 如下:
string s_FileName1 = "";
string s_FileName2 = "";
string s_FileName3 = "";
int changer_no = 0; private void OpenFile1_Click(object sender, EventArgs e)//选择文件一并打开
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName1 = openFileDialog1.FileName;
pathtextBox1.Text = openFileDialog1.FileName;
}
} private void OpenFile2_Click(object sender, EventArgs e)//选择文件二并打开
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName2 = openFileDialog1.FileName;
pathtextBox2.Text = openFileDialog1.FileName;
}
} private void SaveFile3_Click(object sender, EventArgs e)//选择保存位置
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName3 = saveFileDialog1.FileName;
pathtextBox3.Text = saveFileDialog1.FileName;
}
} public string Change(int c,string f,string e1,string e2)
{
if (c == 1)
{
f = f + e1;
} if (c == 2)
{
f = f + e2;
}
return f;
} private void Search_Click(object sender, EventArgs e)//检查过程
{
using (StreamReader sr1 = new StreamReader(s_FileName1))
{
using (StreamReader sr2 = new StreamReader(s_FileName2))
{
using (StreamWriter sw3 = new StreamWriter(s_FileName3))
{
while (sr1.Peek() >= 0 && sr2.Peek() >= 0)
{
string str1 = sr1.ReadLine();//从文件一中读取一行数据...
string str2 = sr2.ReadLine();//从文件二中读取一行数据... string[] a = str1.Split(','); //拆分数据
string[] b = str2.Split('/'); int temp = a.Length;
string f = ""; //建立新字符串
for (int i = 0; i < temp - 1; i++)
{
if (a[i].Equals(b[i]))
{
f = f + a[i];
} else
{
textBox1.Text = str1 ;
textBox2.Text = str2 ;
textBox3.Text = f ; Change(changer_no, f, a[i], b[i]);
continue;
}
}
sw3.WriteLine(f);
}
}
}
}
} private void Changebutton1_Click(object sender, EventArgs e)//进行改变处理,同而为一
{
changer_no = 1;
} private void Changebutton2_Click(object sender, EventArgs e)//进行改变处理,同而为二
{
changer_no = 2;
}可是 我不会在 Search_click事件中 触发下面的时间啊````
怎么才能改变现在状态啊````
但是图形化界面一直是瓶颈啊,没有突破口````请看以下程序```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;namespace Demo_082001
{
class Program
{
static void Main(string[] args)
{
string s_FileName1 = @"c:\1.txt";
string s_FileName2 = @"c:\2.txt";
string s_FileName3 = @"c:\3.txt"; using (StreamReader sr1 = new StreamReader(s_FileName1))
{
using (StreamReader sr2 = new StreamReader(s_FileName2))
{
using (StreamWriter sw3 = new StreamWriter(s_FileName3))
{
while (sr1.Peek() >= 0 && sr2.Peek() >= 0)
{
string str1 = sr1.ReadLine(); //读取数据
string str2 = sr2.ReadLine(); string[] a = str1.Split(','); //拆分数据
string[] b = str2.Split('/'); int temp = a.Length ;
string f = "";
for (int i = 0; i < temp-1; i++)
{
if (a[i].Equals(b[i]))
{
f = f + a[i];
} else
{
int q;
Console.WriteLine("********************************");
//Console.WriteLine("These" + "[" + (i+1) + "]" + "rows are wrong...");
//Console.WriteLine(a[i]+" "+b[i]);
Console.WriteLine(str1);
Console.WriteLine(str2);
Console.WriteLine(f);
Console.WriteLine("PLEASE ENTER YOUR CHOOSE,1,化为一 ,2,化为二");
q = int.Parse(Console.ReadLine()); if (q ==1)
{
f = f + a[i];
Console.WriteLine(f);
continue;
} else if(q ==2)
{
f=f+b[i];
Console.WriteLine(f);
continue;
}
}
}
Console.WriteLine(f);
}
}
}
}
}
}
}
我想换成图形化界面``` 如下:
string s_FileName1 = "";
string s_FileName2 = "";
string s_FileName3 = "";
int changer_no = 0; private void OpenFile1_Click(object sender, EventArgs e)//选择文件一并打开
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName1 = openFileDialog1.FileName;
pathtextBox1.Text = openFileDialog1.FileName;
}
} private void OpenFile2_Click(object sender, EventArgs e)//选择文件二并打开
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName2 = openFileDialog1.FileName;
pathtextBox2.Text = openFileDialog1.FileName;
}
} private void SaveFile3_Click(object sender, EventArgs e)//选择保存位置
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
s_FileName3 = saveFileDialog1.FileName;
pathtextBox3.Text = saveFileDialog1.FileName;
}
} public string Change(int c,string f,string e1,string e2)
{
if (c == 1)
{
f = f + e1;
} if (c == 2)
{
f = f + e2;
}
return f;
} private void Search_Click(object sender, EventArgs e)//检查过程
{
using (StreamReader sr1 = new StreamReader(s_FileName1))
{
using (StreamReader sr2 = new StreamReader(s_FileName2))
{
using (StreamWriter sw3 = new StreamWriter(s_FileName3))
{
while (sr1.Peek() >= 0 && sr2.Peek() >= 0)
{
string str1 = sr1.ReadLine();//从文件一中读取一行数据...
string str2 = sr2.ReadLine();//从文件二中读取一行数据... string[] a = str1.Split(','); //拆分数据
string[] b = str2.Split('/'); int temp = a.Length;
string f = ""; //建立新字符串
for (int i = 0; i < temp - 1; i++)
{
if (a[i].Equals(b[i]))
{
f = f + a[i];
} else
{
textBox1.Text = str1 ;
textBox2.Text = str2 ;
textBox3.Text = f ; Change(changer_no, f, a[i], b[i]);
continue;
}
}
sw3.WriteLine(f);
}
}
}
}
} private void Changebutton1_Click(object sender, EventArgs e)//进行改变处理,同而为一
{
changer_no = 1;
} private void Changebutton2_Click(object sender, EventArgs e)//进行改变处理,同而为二
{
changer_no = 2;
}可是 我不会在 Search_click事件中 触发下面的时间啊````
怎么才能改变现在状态啊````
事件你也只管当成类成员理解就可以了
只要c#语法上可以的,直接用就行了,不要考虑什么java,c#的那么多