自定义打开文件对话框 [英] Customizing OpenFileDialog

查看:291
本文介绍了自定义打开文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在C#WinForms应用程序。我想实现的是获得用户一个文件,我现在用的是下面的code:

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
}

现在,一切工作正常,但我想提出3单选按钮在同一个对话框,这意味着我现在想从该对话框中获得两件事情

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?

推荐答案

是的,这是可能的,我也做了同样的定制,以 SaveFileDialog 成功和它的pretty有趣。

Yes, that's possible, I did the same kind of customization with SaveFileDialog successfully and it's pretty interesting.

请按照下面的链接:

HTTP://www.$c$cproject.com/KB/对话框/ OpenFileDialogEx.aspx

HTTP://www.$c$cproject.com/KB/ CS / getsavefilename.aspx

HTTP://www.$c$cproject.com/KB/对话框/ CustomizeFileDialog.aspx

也是我自己的问题,也将帮助您:

Also my own questions too will help you:

<一个href=\"http://stackoverflow.com/questions/5404278/change-default-arrangement-of-save-and-cancel-buttons-in-savefiledialog\">Change保存的默认设置和取消按钮在SaveFileDialog

<一个href=\"http://stackoverflow.com/questions/5512752/how-to-stop-overwriteprompt-when-creating-savefiledialog-using-getsavefilename\">How停止使用overwriteprompt 则GetSaveFileName创建SaveFileDialog时

How to stop overwriteprompt when creating SaveFileDialog using GetSaveFileName

您必须使用 WinAPI的对于这一点,你需要写在自己的调用了的ShowDialog 方法 GetOpenFileName 里面的窗口功能,而不是调用.NET的打开文件对话框。在 GetOpenFileName 将创建窗口打开文件对话框。 (请参阅 http://msdn.microsoft。 COM / EN-US /库/ ms646927%28V = vs.85%29.aspx )。这一起编写程序HOOKPROC和追赶的事件,如 WM_INITDIALOG,CDN_INITDONE 里面它会帮助你做你想做的。

You have to use the WinAPI for this and you need to write the ShowDialog method in your own calling the GetOpenFileName windows function inside it, instead of calling .net's OpenFileDialog. The GetOpenFileName will create the windows OpenFileDialog. (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 as WM_INITDIALOG, CDN_INITDONE inside it will help you do what you want.

要添加单选按钮等,你必须调用Windows函数,如函数CreateWindowEx SendMessage函数 .. ..

To add radio buttons etc., you have to call the windows functions such as CreateWindowEx and SendMessage....

第二环节都有确切的方向,以自定义...

The 2nd link has the exact direction to the customization...

询问任何澄清...

这篇关于自定义打开文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆