DialogResult does not default to None?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: DialogResult does not default to None?

Hybrid View

  1. #1
    Join Date
    May 2013
    Posts
    5

    DialogResult does not default to None?

    VB.NET 2010, Framework 3.5

    All the documentation I see says that the DialogResult's default value is None

    Return Values:
    One of the System.Windows.Forms.DialogResult values. The default value is None.

    The problems I'm seeing. . I open a form via ShowDialog(), the form I open does NOT set a DialogResult value anywhere, it seems no matter how I close the dialog the returning DialogResult is always 'Cancel' not 'None'. Why is it documented to default to 'None' when it seems that the default is 'Cancel'??

    http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

  2. #2
    Join Date
    Aug 2005
    Posts
    198

    Re: DialogResult does not default to None?

    You're confusing the Button's DialogResult property with the Form's ShowDialog return value.
    The ShowDialog's return value will be the DialogResult of the Button clicked - if you clicked with the 'x' on the upper right, then according to ShowDialog's documention, the return value is 'Cancel'. If you clicked on one of your buttons, what is the value of the button's DialogResult property?
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  3. #3
    Join Date
    May 2013
    Posts
    5

    Re: DialogResult does not default to None?

    Indeed I was looking at system.windows.forms.button.dialogresult

    I zeroed in non system.windows.forms.dialogresult instead and notice that there is no default documented so. . I suppose I'll need to assume the default is Cancel.

    http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    I was hoping to see a documented 'default' return value to know what to look for when a form is closed via <Alt><F4>, by Right Clicking the icon in the task bar and choosing <Close> or Xing our via the top right corner etc.

    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim frm As New Form2
            Dim dr As New DialogResult
            dr = frm.ShowDialog()
            Debug.Print(dr.ToString) ' defaults to Cancel  ??
        End Sub
    End Class
    Last edited by NigelTunney; August 23rd, 2013 at 03:22 PM. Reason: Additional info

  4. #4
    Join Date
    Apr 2012
    Posts
    29

    Re: DialogResult does not default to None?

    Quote Originally Posted by NigelTunney View Post
    I was hoping to see a documented 'default' return value to know what to look for when a form is closed via <Alt><F4>, by Right Clicking the icon in the task bar and choosing <Close> or Xing our via the top right corner etc.
    The FormClosing event can provide info on how the Form is going to be closed. That event passes a FormClosingEventArgs which has a property called CloseReason.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center