从特定位置加载diolog框

编程入门 行业动态 更新时间:2024-10-26 08:35:09
本文介绍了从特定位置加载diolog框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好吧所以我正在开发一个工具,它可以节省游戏中的字节数,然后你可以加载它们一切正常,

但问题是它不会从特定位置加载它会很棒,如果有人可以帮我清理代码并且

打开到。\Classes \\ \\ n

感谢任何帮助的人 :D

public void SaveFile(byte [] bytes) { saveFileDialog1.ShowDialog(); File.WriteAllBytes(saveFileDialog1.FileName,bytes); } public byte [] LoadFile() { openFileDialog1.ShowDialog(); return File.ReadAllBytes(openFileDialog1.FileName); }

解决方案

嗨等待, >>好吧所以我正在开发一个工具,它可以从游戏中保存字节,然后你可以加载它们所有有用的东西, 但问题是它不会从特定位置加载它会很棒,如果有人可以帮我清理代码并 OpenFileDialog.InitialDirectory 可用于设置默认目录。它可以获取或设置文件对话框显示的初始目录。 您可以将保存上一个文件的目录保存为初始目录。以下示例供您参考。

const string directory = @" D:\ testvideo"; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = directory; if(openFileDialog1.ShowDialog()== System.Windows.Forms.DialogResult.OK) { string selectedDirectory = System.IO.Path.GetDirectoryName(openFileDialog1.FileName); if(selectedDirectory!= directory) { System.Windows.MessageBox.Show(" Wrong folder selected!"); 返回; } }

此外,如果您可以通过将有用的帖子标记为答案来关闭该帖子,将不胜感激。如果您有新问题,可以开始新的主题包含所有必要的代码段,以便其他任何人能够从头开始重现您的问题以及有关结果的详细说明,包括任何异常消息。 感谢您的理解。 最好的问候, Yong Lu

ok so im working on a tool where it can save bytes from a game and then you can load them well all that works ,

but the problem is it wont load from a specific location it would be awesome if some one could help me clean the code up and

open up to.\Classes\aw

thanks to anyone who helps :D

public void SaveFile(byte[] bytes) { saveFileDialog1.ShowDialog(); File.WriteAllBytes(saveFileDialog1.FileName, bytes); } public byte[] LoadFile() { openFileDialog1.ShowDialog(); return File.ReadAllBytes(openFileDialog1.FileName); }

解决方案

Hi waested, >>ok so im working on a tool where it can save bytes from a game and then you can load them well all that works , but the problem is it wont load from a specific location it would be awesome if some one could help me clean the code up and OpenFileDialog.InitialDirectory can be used to set a default directory . It can get or set the initial directory displayed by the file dialog box. You can save the directory where the previous file was saved as the initial directory. The following sample for your reference.

const string directory = @"D:\testvideo"; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = directory; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string selectedDirectory = System.IO.Path.GetDirectoryName(openFileDialog1.FileName); if (selectedDirectory != directory) { System.Windows.MessageBox.Show("Wrong folder selected!"); return; } }

Besides, It would be appreciated if you could close the thread by marking helpful posts as an answer. If you have a new question you can start a new thread with all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages. Thank you for your understanding. Best Regards, Yong Lu

更多推荐

从特定位置加载diolog框

本文发布于:2023-10-08 03:04:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   位置   diolog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!