禁用 SaveFileDialog 的部分内容
我正在构建一个需要使用 SaveFileDialog
的应用程序。 问题是我想限制用户使用 SaveFileDialog 的某些部分(例如我不希望他们编辑文件名)。 我听说使用 Windows 窗体 SaveAsDialog
很难做到这一点。 您知道如何在本机代码中执行此操作吗? 你有一个完整的难以理解的例子吗(我需要整个例子,因为我从未使用过Windows API)?
附言。 我确实需要使用 SaveFileDialog 来保持 UI 一致。
I'm building an application where I need to use a SaveFileDialog
. The problem is that I want to restrict the users from using some parts of the SaveFileDialog
(e.g. I don't want them to edit the name of the file). I've heard that it's very difficult to do this using Windows forms SaveAsDialog
. Do you know how to do this in native code? Do you have a full undestandable example (I need the whole example, since I've never used Windows API)?
PS. I really need to use the SaveFileDialog
to keep the UI consistent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果文件名是固定的,并且用户只能导航到备用位置,则只需使用
FolderBrowserDialog
即可。 恕我直言,这也是一致的。If the file name is fixed and the user shall only navigate to an alternate location simply use the
FolderBrowserDialog
instead. IMHO, this would be consistent, too.如果您确实想使用通用的保存文件对话框,但想让文件名只读,您可能必须调用本机代码。 您可以使用钩子提供许多自定义。 您必须研究一些 Windows API:
自定义常用对话框
打开并另存为对话框
GetSaveFileName
函数 (从托管代码中使用GetSaveFileName
)< a href="http://msdn.microsoft.com/en-us/library/ms646839(VS.85).aspx" rel="nofollow noreferrer">
OPENFILENAME
结构 ( 从托管代码中使用OPENFILENAME
)我已经很长时间没有使用旧式 Windows API 了,所以下面的想法只是:一个想法。 也许您可以创建一个挂钩,然后在
WM_INITDIALOG
中您可以找到带有文件名的编辑控件。 它似乎被命名为edt1
。 也许您可以修改该控件的窗口样式以使其只读。但也许这里提供的其他一些答案是比破解“另存为”对话框更好的选择。
If you really want to use the common save file dialog, but want to make the file name read-only you will probably have to call to native code. You can provide a lot of customizations using a hook. You will have to study some Windows API's:
Customizing Common Dialog Boxes
Open and Save As Dialog Boxes
GetSaveFileName
Function (UsingGetSaveFileName
from managed code)OPENFILENAME
Structure (UsingOPENFILENAME
from managed code)I haven't been doing old-style Windows API for a long time so the following idea is just that: an idea. Perhaps you can create a hook and in
WM_INITDIALOG
you can find the edit control with the file name. It seems to be namededt1
. Perhaps you can then modify the windows style of the control to make it read-only.But maybe some of the other answers provided here are better alternatives than hacking the save as dialog box.
从头开始创建您自己的
Savefiledialog
。只需创建一个看起来与
Savefiledialog
几乎相同的表单,但使用Label
作为名称而不是TextBox
。create your own
Savefiledialog
from scratch.Just create a form that looks almost the same as a
Savefiledialog
but with aLabel
for name instead ofTextBox
.