| You are here: | About>Computing & Technology>Visual Basic> Using VB.NET> How to return from a VB.NET Dialog |
![]() | Visual Basic |
How to return from a VB.NET DialogHow DialogResult, Forms, and Buttons Work TogetherDialogs in VB.NET use object oriented properties and methods to tell the calling program what happened in the dialog. Using the VB 6 COM architecture, a dialog was an object that returned a value after it was called to tell your program whether it was successful or not. The COM Way ReturnValue = showModalDialog() VB.NET does things the OOP way. Rather than calling an object which returns a value, the object sets the value of a property that can be used by the calling program. The VB.NET OOP Way DialogWindow.ShowDialog() A dialog window (or sometimes, "dialog box") displays information or gets a response and then closes. A good example is the file selection window that you use to select a directory and open a file. But there are lots of them to select fonts, pick colors or just display a message. In VB.NET, a dialog is a modal window. This means that the dialog window must be closed before other windows in the application are active. For example, if the dialog selects a file, then the file must be selected or the window must be canceled before other forms in the application will respond. The key to using VB.NET dialog windows is the DialogResult property. This is a property available in all windows. But it's not useful unless the window is displayed using the ShowDialog method that displays a modal window because the value is None. DialogResult is an interesting property because it is part of both Form and Button objects. You can set the design time property of a Button to determine the default action when it's clicked. If the Button is contained in a Form that has been displayed using ShowDialog, then the Button DialogResult property is assigned to the Form automatically. But you can also set it from any other code. For example, if you added a LinkLabel component, you could set it with: Private Sub LinkLabel1_LinkClicked(ByVal ... Any value except None will close the modal parent form and control will return to the statement following the ShowDialog method that opened the form. So the only real benefit is that you don't actually have to write event code for the button to close the modal parent form and return. VB.NET provides templates that already contain the code and properties to implement all this. For example, the VB.NET 2005 Express AboutBox is an excellent example of a dialog. (Change the contents of this template using the Assembly Information... button in the Applications tab of the project properties.) -------- It's up to you to write the code that will use the value in DialogResult. If it was set to Abort, for example, your application might shut down. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


