0

I had a question about Dialogs in VB.NET. I am working on a point of sale program, and at one point during a sale, I have a few windows that pop up. For example, a user will go into a sale that is window A. In window A, they have the option of entering products, etc., and if they choose a 'repair' product, it opens window B, allowing them to choose options. In window B, there is a button that pops up window C that allows them to attach products TO the repair. My issue is with window B opening window C.

Because I open window B as a Dialog (in order to check if DialogResult.OK is true), any window I open with B is non-touchable, as B is a Dialog and requires attention before going to any other windows/forms.

My question is - is there any way to still use a dialog, but allow for manipulating other open forms while the dialog is up, and if not, what would be the best way to check if the user selected OK, or cancelled out of the window?

The only solution I can think of right now would be to open window C as a dialogue as well (it's actually a UserControl, and I'm still trying to find where in the code it's actually getting openned/called), or to create a variable that is passed in to the form, and then passed back out when it's closed, that basically sets a flag to either continue or cancel...

Any advice/ideas??

Chris Hobbs
  • 745
  • 2
  • 9
  • 27
  • I just found something called a 'Modeless Dialog Form', that is apparently exactly what I'm looking for, but having trouble finding instances of how to implement it.... any ideas? – Chris Hobbs Jun 17 '14 at 19:58
  • For 'Modeless Dialog Form' Dim frmFoo As New FooForm() frmFoo.Show() – Horaciux Jun 17 '14 at 20:11
  • Ah, so then I wouldn't be able to use the 'If DialogResult = DialogResult.OK' check at the end... dangit! Thanks for the reply though! – Chris Hobbs Jun 17 '14 at 20:12
  • 1
    I think you would need to call `Dim frmC As New FormC() frmC.ShowDialog(Me)` where `Me` is the instance of FormB. – Chris Dunaway Jun 18 '14 at 15:31

2 Answers2

0

If I were to explain this using code, this answer would be very long, so instead I'm going to give you a high level overview.

.Show() vs .ShowDialog()

The link below will take you off to Microsofts website to explain the technical differences between these two. However in laymans terms, .ShowDialog() will create the form where it is the only window allowed to have focus in the application. Forms that are called in this instance are hierarchical, in that if you open them in order of 1,2,4,3 then they must be closed in the 3,4,2,1 order. Forms that are opened with just .Show() can be focused at any time.

How to: Display Modal and Modeless Windows Forms

Form.FormBorderStyle property

This property controls how the OS will display the window. The different options under this selection changes the way the window behaves. Depending on the options that are chosen you can make a window that only has a close button on it, or it may not even have a title bar at all. Setting this option to None will take away all controls of the form and only leave you with the Me.ClientArea to work with. When you want a completely custom GUI, this is how you do it but you have to implement your own controls for everything, closing the form, size handles, the ability to move the form on the screen, etc...

Form.FormBorderStyle Property

Passing data between forms

When someone asks how to pass data back and forth between forms, they are usually talking about modeless forms that were created using .Show(). The most common thing I see on SO is to use the tag property of an object (a form is an object that has this property too) to pass data back and forth. While I won't say this is a bad practice, I will recommend creating public properties on your forms. These can be set from a separate form and you can perform additional actions when setting the values (be careful though, this way of doing things isn't thread safe). If you are using a Modeless form as though it were a Modal form, then you can simply override the .Dispose property to return a value or you can create a method named DialogResult that will return the value you need. The caveat to using a DialogResult or similar method is that if the form has been disposed then you can't access the value you wanted to return.

Community
  • 1
  • 1
0

You can use myNewForm.Show(Me) for the Window you want to be shown as a dialog. This will show myNewForm as a child of the current form, but lets you interact with the current form.

Timo Schwarzer
  • 399
  • 4
  • 17