自定义 OpenFileDialog

发布于 2024-11-08 17:38:53 字数 500 浏览 5 评论 0原文

我正在用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏九 2024-11-15 17:38:53

是的,这是可能的,我成功地使用 SaveFileDialog 进行了相同类型的自定义,这非常有趣。

请点击以下链接:

http://www.codeproject.com/KB/dialog/OpenFileDialogEx.aspx

http://www.codeproject.com/KB/cs/getsavefilename.aspx

http://www.codeproject.com/KB/dialog/CustomizeFileDialog.aspx

另外我自己的问题也会帮助你:

更改“保存”和“取消”按钮的默认排列保存文件对话框

如何在使用 GetSaveFileName 创建 SaveFileDialog 时停止覆盖提示


您必须为此,请使用 WinAPI,并且您需要在自己的调用 GetOpenFileName 中编写 ShowDialog 方法Windows 函数位于其中,而不是调用 .net 的 OpenFileDialogGetOpenFileName 将创建窗口 OpenFileDialog。 (请参阅 http://msdn.microsoft .com/en-us/library/ms646927%28v=vs.85%29.aspx)。这与编写 HookProc 过程并捕获其中的 WM_INITDIALOG、CDN_INITDONE 等事件一起将帮助您完成您想要的操作。

要添加单选按钮等,您必须调用 Windows 函数,例如 CreateWindowExSendMessage....

第二个链接具有自定义的确切方向...

求任何澄清...

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

Follow the following links:

http://www.codeproject.com/KB/dialog/OpenFileDialogEx.aspx

http://www.codeproject.com/KB/cs/getsavefilename.aspx

http://www.codeproject.com/KB/dialog/CustomizeFileDialog.aspx

Also my own questions too will help you:

Change default arrangement of Save and Cancel buttons in SaveFileDialog

How to stop overwriteprompt when creating SaveFileDialog using GetSaveFileName

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.

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...

Ask for any clarifications...

若水微香 2024-11-15 17:38:53

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文