[英]Getting file name and changing a button to that name
我只是进入C#表单,我想知道如何将按钮文本更改为您要打开的文件的名称,我对此有些工作,但是当我打开文件时,按钮文本更改为该文件的路径,我只想要文件名称
OpenFileDialog op = new OpenFileDialog();
op.Title = "open";
op.Filter = "Text Document(*.txt)|*.txt|All Files(*.*)|*.*";
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(op.FileName, RichTextBoxStreamType.PlainText);
button1.Text = op.FileName;
this.Text = op.FileName;
}
Path.GetFileName(op.FileName);
您将需要检出Path类。 记住要引用System.IO
OpenFileDialog op = new OpenFileDialog();
op.Title = "open";
op.Filter = "Text Document(*.txt)|*.txt|All Files(*.*)|*.*";
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(op.FileName, RichTextBoxStreamType.PlainText);
button1.Text = Path.GetFileNameWithoutExtension(op.FileName);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.