Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling behaviour of input forms with a controller class

Status
Not open for further replies.

SpankySpanky

Programmer
May 25, 2005
21
AU
I was hoping to get some advice for a problem I am having.

I need to call up a sequence of forms to get user input in a certain order. You click a button on a main form and it opens a dialog for the first step where you enter data, then when you click NEXT it hides and the next step appears.

I thought I would try and use good design, and create a FormController class which instantiates the forms and can show and hide the forms in a particular order and in response to custom events that are raised by pressing buttons on the forms.

It works but the problem is that if I hide one form then show the next there is an ugly flicker because there is a time when neither form is visible. I wanted to avoid this by showing the second form before hiding the first.

But I cant seem to get this to work properly because code wont resume in the FormController until the first form has been closed. I can force it to work by using Form.Show instead of Form.ShowDialog but then the forms are not modal and you can move focus back to the main form.

I tried passing the main form as a parameter to the Form.ShowDialog function so it would be parent for each dialog form. But then I cannot close form1 AFTER showing form2 (to avoid flicker) because execution wont resume in the FormController class until form1 is closed.

Can anybody suggest an elegant solution? All the forms are built so throwing them away and putting it all on one form is an unpleasant option. I previously had form1 invoking form2 invoking form3 but I thought it would be better design practice to have an external sequencer class to control the forms in an orderly fashion.

I would greatly appreciate any comments.

Thanks
 
Try doing a showdialog on form2 prior to unloading form1. The zorder should take care of any flicker, especially if form2 is the same size/position as form1, or larger.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
On the parent form, keep a collection of the forms you open. Each time you open a form, add it to the collection, each time you close (not hide) a form, remove it. Add a public method to hide all of the forms except the one passed in:

Code:
class ParentForm
 inherits windows.forms.form

 '...

 private OpenForms as new collection

 Public Sub HideNotMe(ShownForm as form)
   dim f as form
   for each f in OpenForms
     if not f.equals(ShownForm) then f.visible=false
   next
 end sub

end class

Then on your child forms, On visibility change:

Code:
Private Sub frm_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.VisibleChanged
  if me.visible=true then
    ctype(me.parentform, [ParentFormType]).hidenotme(me)
  end if
End Sub

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top