|
-
Oct 5th, 2011, 10:12 PM
#1
Thread Starter
Lively Member
Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?
I have some code that runs on "Ok" for OpenFileDialogs and SaveFileDialogs.
If the user presses cancle without selecting something, the program crashes and gives me a headache because it sets off a chain reaction that I won't get into detail about.
So is there a way to make it so that "Cancle" is grayed out or something on the Dialog Boxes?
If not, is there an alternative that could solve this problem?
Edit: The code that causes the crash (and subsequent headache) doesn't run directly from the "Ok" action
Last edited by Lucien Montierre; Oct 5th, 2011 at 10:15 PM.
Reason: Extra Detail
-
Oct 5th, 2011, 10:21 PM
#2
Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?
how are you calling it? You do know that the ShowDialog method will return the a DialogResult that will tell you if they clicked, OK, Save, Open or Cancel...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDialog As New ColorDialog()
' Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = False
' Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = True
' Sets the initial color select to the current text color,
MyDialog.Color = TextBox1.ForeColor
' Update the text box color if the user clicks OK
If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
TextBox1.ForeColor = MyDialog.Color
End If
End Sub
Documentation: http://msdn.microsoft.com/en-us/libr...t40c.aspx#Y357
-tg
-
Oct 5th, 2011, 10:49 PM
#3
Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?
Do you really think that preventing the user from not choosing a file would be the best solution? What if the file they want doesn't exist? Should they just leave your program running with the dialogue showing indefinitely?
There are two ways to handle a OFD or SFD. You can do as tg has shown and test the value returned by ShowDialog, or you can handle the FileOK event. In both cases, your code will not be executed unless the user clicks OK. Unless your system is corrupt in some way, you must simply not be writing the code correctly. As you haven't shown us the code, we can only guess at what the problem might be.
-
Oct 5th, 2011, 11:26 PM
#4
Thread Starter
Lively Member
Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?
vb Code:
If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
End If
Did the trick, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|