Results 1 to 3 of 3

Thread: Modify return value of ShowDialog method

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    40

    Modify return value of ShowDialog method

    The ShowDialog method of a WindowsForm returns a DialogResult Enum, but how do you modify the value that is returned?

    Thanks. Lance

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I don't think you can change the enum that you can pass back, but you do have control as to what is passed back. I got this from the msdn library.

    This code will make a button (an OK button on a form) make the dialog result be an OK result.
    VB Code:
    1. Private Sub InitializeMyButton()
    2.     ' Create and initialize a Button.
    3.     Dim button1 As New Button()
    4.    
    5.     ' Set the button to return a value of OK when clicked.
    6.     button1.DialogResult = DialogResult.OK
    7.    
    8.     ' Add the button to the form.
    9.     Controls.Add(button1)
    10. End Sub 'InitializeMyButton

    Here is the enumeration members that are available:

    The Button.DialogResult property and the Form.ShowDialog method use this enumeration.

    Abort The dialog box return value is Abort (usually sent from a button labeled Abort).

    Cancel The dialog box return value is Cancel (usually sent from a button labeled Cancel).

    Ignore The dialog box return value is Ignore (usually sent from a button labeled Ignore).

    No The dialog box return value is No (usually sent from a button labeled No).

    None Nothing is returned from the dialog box. This means that the modal dialog continues running.

    OK The dialog box return value is OK (usually sent from a button labeled OK).

    Retry The dialog box return value is Retry (usually sent from a button labeled Retry).

    Yes The dialog box return value is Yes (usually sent from a button labeled Yes).

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    40
    Thanks. That is exactly what I was looking for.

    Now I have another question though ... Is it possible to show a Form as Modal without using the ShowDialog method? For example, I would like to do the following:

    Code:
    'Prevent the existing ShowDialog method from being Called
    Private Shadows Function ShowDialog() as DialogResult
    End Function
    
    'Create the ShowDialog method that I want people to use
    Public Overloads Function ShowDialog(ByVal something As Whatever) as DialogResult
    
        'Put some code here
    
        'Now, I would like to show the Class as a Modal Form
        'and wait for the user to press one of the "DialogResult" Buttons,
        'but I don't know how to do that
    
        'Put some more code here
    
        'Indicate the Button that was pressed
        Return Me.DialogResult
    
    End Function

    Thanks for any help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width