3

Is it possible to set the OpenFileDialog's cancel button enable = false? If so, How?

I'm using winforms

Edit

OpenFileDialog file_open_dialog = new OpenFileDialog();
Rye
  • 2,273
  • 9
  • 34
  • 43
  • Could you be a little more specific? A simple line of code showing how you are opening your dialog box now would be very helpful. I have no idea if you are talking about a file dialog box or some class called OpenDialog or a method of some other class called OpenDialog. If you are talking about a Form object the method is ShowDialog(), not OpenDialog(), so I really have no idea what you're talking about. –  Oct 14 '10 at 04:22
  • 1
    @ Dan :(+1) Why can't we go for a Custom control(A custom control for `OpenFileDialog` (overriding the existing `openFileDialog`)) – Thorin Oakenshield Oct 14 '10 at 04:36
  • @Pramodh i think its not possible to override an existing openfiledialog usercontrol. – Rye Oct 14 '10 at 08:39
  • @ Rye : Try with `Windows Forms Control Library`. – Thorin Oakenshield Oct 14 '10 at 08:55
  • You probably want to check out these articles: http://www.codeproject.com/KB/dialog/CustomizeFileDialog.aspx http://msdn.microsoft.com/en-us/library/ms996463.aspx http://www.codeproject.com/KB/dialog/OpenFileDialogEx.aspx – Pedery Oct 14 '10 at 04:42

2 Answers2

4

I don't believe so, and with good reason! Are you sure that you want to disable the Cancel button? Being that this is a modal dialog this would prevent the user from continuing (and hence making your application unusable) until they selected a file - there are almost certainly going to be scenarios where this simply isn't possible, or the user doesn't want to be forced into saving a file.

Of course I could be wrong and there could be a completely legit scenario that I'm not aware of - however I'm afraid that Microsoft were also unaware of this scenario and so the OpenFileDialog doesn't support disabling the cancel button.

I'm afraid that if you really don't want a cancel button you will need to create your own clone of the dialog.

Justin
  • 84,773
  • 49
  • 224
  • 367
0

handle the cancel in a loop if you want? might frustrate users ;)

do
  {}
while (openFileDialog1.ShowDialog() != DialogResult.OK);
da Bich
  • 494
  • 1
  • 4
  • 13