开发者

How to Save not Save As

I'm creating a richtextbox editor and need to put a save function as well as a save as. I can easily do a save as function by using the savefiledialog but im not sure how 开发者_开发百科to save without this. Can anyone help?


Create a field somewhere, say string filename. Set it to null initially.

When a document is opened, store the file name in a filename.

When a document is saved through Save As, also store this file name in filename.

When Save is invoked, check the value of filename. If it is null, invoke Save As instead. If it is not null, save to the file name specified in filename.


The way this usually works is to keep track of the file name the user either opened or saved as.

Then, when they use the Save function, simply save to the file name that was previously specified. If no file has been specified, then show the Save As.


Isn't "Save" simply the following (in pseudocode)?

Save() = 
    WriteTo(oldfilename)

SaveAs() = 
    stream = OpenDialog()
    oldfilename = stream.filename
    Save()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜