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?
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...
Try this code:
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.