Stefan
Stefan

Reputation: 1323

c# change the form title by the savefile name.extension

everytime i change a file such as a .rft or .txt i want it to display the name in the title for e.g RFT Editor:docment.rft

here the code i am using atm

this.Text = "RFT Editor:" + saveFileDialog1.FileName;

hope someone can help

Upvotes: -5

Views: 404

Answers (2)

Konrad Morawski
Konrad Morawski

Reputation: 8394

Your question is poorly worded. You don't describe how the result you are getting is different from what you'd like it to be.

I can only guess the problem is that "RFT Editor:" + saveFileDialog1.FileName gives you a file name with an entire path, and to get "RFT Editor:docment.rft" as in your example you'd need "RFT Editor:" + System.IO.Path.GetFileName(saveFileDialog1.FileName) instead.

Upvotes: 1

Rolice
Rolice

Reputation: 3103

Assuming you need this:

...
...

// Save clicked inside, not Cancel
if(saveFileDialog1.openDialog() == DialogResult.OK)
{
    // this.Text is same as only Text - in case of current class (matter of choice)
    Text = "RTF Editor: " + savefileDialog1.FileName;
    ...
    ...
}

Upvotes: 0

Related Questions