Solved

Opening a form and running a sub - can it also be dialog?

Posted on 2006-11-16
8
173 Views
Last Modified: 2010-04-23
hi there

I would like to open a form as a dialog form.  However I also need to call a sub on the opened form (I call the same form in a lot of places so the sub I am running is important, and I load child forms onto the loaded form) i.e.

dim f as form1
f.showdialog()
f.getresults(id, date)

obviously f.getresults(id, date) wouldn't be called, but I do want the characteristics of the dialog in that I don't want the user to be able to move away from the form until it is closed.

Can I have the best of both worlds somehow?
0
Comment
Question by:DavidGreenfield
  • 5
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17956285
Is there no reason why you cannot do it this way ?

f.getresults(id, date)
f.showdialog()
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956439
a proper way of doing it would be handling the dialog close event from form1 and get the values there:

dim f as form1
AddHandler f.FormClosing, AddressOf f_closing
f.ShowDialog()


    Private Sub f_closing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
        Dim f As Form1 = DirectCast(sender, Form1)

        somevar = f.getresults(id, date)

    End Sub
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956443
excuse me not from form1, i meant from the form that calls the form1
0
 

Author Comment

by:DavidGreenfield
ID: 17956522

Yes it is a little bit more compilcated that I have explained.

I have a generic "pop up" form with all the graphics in.  and I call a sub in this to load any form I want.

Sometimes the form I am loading needs to run a sub, where I tell the pop up not to load as dialog so I am able to do this.  What I really want is either to be able to switch the dialog on, or to mimick the dialog action.

so actually:

dim f as form1
popup.load(f,false) - where false means no dialog
f.getresults(id, date)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17956523
what i posted is the proper way if you need to retrieve values, obviously when displayed dialog has started to close, and still has the variables in memory.
if you need to run a sub when the form is loading you can pretty much hook to any event in the dialog.

dim f as form1
AddHandler f.Load, AddressOf f_load
f.ShowDialog()

etc
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956557
maybe write your own Show sub, so inside the dialog you could have something like:
public shared sub MyShow(byval boolDialog as boolean)
  dim f as new form1
  if boolDialog then
    f.showdialog
  else
    f.show
  end if
end sub

and call from your popup
f.MyShow(true) or f.MyShow(false)
0
 

Author Comment

by:DavidGreenfield
ID: 17956982
hi newyuppie,

your method does work, I had to change my code slightly - but it is now working.

Thank you very much!
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17957010
you're welcome, thanks for the points
NY
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now