12

我正在用 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

我如何实现这一目标?

4

2 回答 2

11

是的,这是可能的,我成功地做了同样的定制,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

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

更改 SaveFileDialog 中保存和取消按钮的默认排列

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

您必须为此使用WinAPI,并且您需要自己编写ShowDialog方法来调用其中的GetOpenFileNamewindows 函数,而不是调用 .net 的OpenFileDialog. 将GetOpenFileName创建 windows OpenFileDialog。(请参阅http://msdn.microsoft.com/en-us/library/ms646927%28v=vs.85%29.aspx)。这与编写 HookProc 过程并在其中捕获诸如此类的事件一起WM_INITDIALOG, CDN_INITDONE将帮助您做您想做的事情。

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

第二个链接有定制的确切方向......

要求任何澄清...

于 2011-05-23T05:25:26.997 回答
3

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.

于 2011-05-23T06:52:08.977 回答