Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Forms changing focus

I have a main form which launches a small form with a few options for a report. The user picks their options, then clicks the show report button. At this stage, I open another form which displays the form, and close the small form with the options.

However, at this point (when the small form closes) the focus shifts from the new form with the report to the main form. Any ideas on how I can keep the focus on the report?

Ben
Wednesday, January 22, 2003

Seems like all you need to do is (a) get a reference to the form you want to receive the focus after your options form is closed, and then (b) call the Activate() method on it.  Step (a) is the tricky part.  In VB6, the Forms collection would make this much easier... you'll probably have to implement your own collection to keep references to open forms and decide which one should get the focus.

Sam Gray
Wednesday, January 22, 2003

There might be an easier way to do this. Are you creating the report from from your "options" dialog? If so, why not create the report from your main form instead?

From the main form, create your options dialog. Show the dialog. When the user presses OK (or Show Report) close the form but don't show the report form. Then, create and show the report form the main form. Here is some pseudo-code

frmMain.RunMyReport
{
  frmOptions.ShowModal
  if the user pressed OK then
  {
    frmReport.Init(pass in options collected from frmOptions)
    frmReport.ShowModal
  } 
}

Bryan Bedard
Thursday, January 23, 2003

Thanks Bryan, that sounds like the way to go for sure, I'll give it a go.

Ben
Thursday, January 23, 2003

*  Recent Topics

*  Fog Creek Home