自定义 OpenFileDialog
我正在用 C# 开发 winforms 应用程序。我想要实现的是从我使用以下代码的用户那里获取一个文件:
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string sFileName = dlg.FileName;
//my code goes here
}
现在,一切正常,但我想在同一个对话框中放置 3 个单选按钮,这意味着我现在可以从中得到两件事对话框
string sFileName = dlg.FileName; //same as in case of traditional dialog box
//some thing like this which tells which radio button is selected:
dlg.rbTypes.Selected
如何实现这一点?
I am working on winforms application in C#. What I want to achieve is to get a file from user for which I am using the following code:
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string sFileName = dlg.FileName;
//my code goes here
}
Now, everything is working fine but I want to put 3 radio buttons in the same dialog box, meaning I would now get two things from this dialog box
string sFileName = dlg.FileName; //same as in case of traditional dialog box
//some thing like this which tells which radio button is selected:
dlg.rbTypes.Selected
How do I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是可能的,我成功地使用
SaveFileDialog
进行了相同类型的自定义,这非常有趣。请点击以下链接:
另外我自己的问题也会帮助你:
您必须为此,请使用
WinAPI
,并且您需要在自己的调用GetOpenFileName
中编写ShowDialog
方法Windows 函数位于其中,而不是调用 .net 的OpenFileDialog
。GetOpenFileName
将创建窗口OpenFileDialog
。 (请参阅 http://msdn.microsoft .com/en-us/library/ms646927%28v=vs.85%29.aspx)。这与编写 HookProc 过程并捕获其中的 WM_INITDIALOG、CDN_INITDONE 等事件一起将帮助您完成您想要的操作。要添加单选按钮等,您必须调用 Windows 函数,例如
CreateWindowEx
和SendMessage
....第二个链接具有自定义的确切方向...
求任何澄清...
Yes, that's possible, I did the same kind of customization with
SaveFileDialog
successfully and it's pretty interesting.Follow the following links:
Also my own questions too will help you:
You have to use the
WinAPI
for this and you need to write theShowDialog
method in your own calling theGetOpenFileName
windows function inside it, instead of calling .net'sOpenFileDialog
. TheGetOpenFileName
will create the windowsOpenFileDialog
. (Refer to http://msdn.microsoft.com/en-us/library/ms646927%28v=vs.85%29.aspx). This together with writing the HookProc procedure and catching events such asWM_INITDIALOG, CDN_INITDONE
inside it will help you do what you want.To add radio buttons etc., you have to call the windows functions such as
CreateWindowEx
andSendMessage
....The 2nd link has the exact direction to the customization...
Ask for any clarifications...
在 XP 上,您需要使用钩子过程方法和 GetOpenFileName API。在 Vista 及更高版本上,这将导致一个看起来可怕的文件对话框,其实用性有限,例如无法搜索。在 Vista 上,您应该使用 IFileDialog,并且要自定义对话框,您需要 IFileDialogCustomize 接口。因为新的 Vista 对话框作为 COM 接口公开,所以它们很容易在 .net 中使用。
On XP you need to use the hook procedure method and the GetOpenFileName API. On Vista and later this will result in a horrid looking file dialog with limited utility, e.g. no search. On Vista you should use IFileDialog and to customise the dialog you need the IFileDialogCustomize interface. Because the new Vista dialogs are exposed as COM interfaces they are quite easy to consume in .net.