急!!记事本程序打开文件时怎样获取文件的文件名并显示在 Form1的Text上 我在做一个仿WINDOWS记事本程序,打开文件时文件的文件名自动显示在 Form1的Text上 不知道怎么弄 各位高手请帮下忙 小弟 在线等谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string strFilePaht="文件路径"; Path.GetFileNameWithoutExtension(strFilePath); private void 打开Button_Click(object sender, EventArgs e) { openFileDialog1.DefaultExt = "*.rtf"; openFileDialog1.Filter = "RTF Files|*.rtf|(*.txt)|*.txt"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0) { string filname = openFileDialog1.FileName; textBox1.Text=filname; } } 做记事本 不能用 ShowDialog()吧。获得文件名fileName之后Form1.Text=fileName; 引用#3楼做记事本 不能用 ShowDialog()吧。还是用的好,当选择打开电脑上的文件时用的上上面写是在textbox上的,要在Form1上用Form1.Text=filname; 想学习C# Response.Cookies.Add()和方法Response.AppendCookie()有什么区别? 一起来学习!一起进步!! 求救!!!关于TabControl 控件 Remove TabPage 的问题,在线等… 求助,C#如何取得Scroll Lock键的状态? 关于泛型的问题 怎样给用户控件添加像DropDownList一样的Item属性? 如何在string类型中查找分行符? 关于streamwriter的小问题请教~~ IE 的 BUG? 读txt时出现问题(不报错,文件显示不出来) C#通过SQL2005数据库连接验证登录窗口的问题??
string strFilePaht="文件路径";
Path.GetFileNameWithoutExtension(strFilePath);
{
openFileDialog1.DefaultExt = "*.rtf";
openFileDialog1.Filter = "RTF Files|*.rtf|(*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0)
{
string filname = openFileDialog1.FileName;
textBox1.Text=filname;
}
}
做记事本 不能用 ShowDialog()吧。还是用的好,当选择打开电脑上的文件时用的上
上面写是在textbox上的,要在Form1上用
Form1.Text=filname;