[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to launch and focus a form from another's when launched

Posted on 2011-09-14
11
Medium Priority
?
321 Views
Last Modified: 2013-12-17
I have a .Net 4 Windows Forms project with Visual Studio 2010 using c#.

I have a FormProduct and FormSearch.  When I launch FormProduct I want it to show FormSearch and for the focus to be on FormSearch.  I have tried this in the constructor of FormProduct but while FormSearch is displayed the focus goes to FormProduct.  I suspect I am opening the form too early but I'm not sure which event to use instead.

Once opened how can I test to be sure the form is still open?  I keep a reference to the form butI don't know how to check to see if the user has closed it.
0
Comment
Question by:canuckconsulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Expert Comment

by:momonana
ID: 36535025
put in the constructor this line to open anther window and bring it to the front

Mohammed Naguib
Thanks
0
 

Expert Comment

by:momonana
ID: 36535034
Sorry but the code didn't attached well  

put in the constructor this line to open anther window and bring it to the front

//--------------------------------------------------------
Application.OpenForms["FormSearch "].BringToFront();
//--------------------------------------------------------
Mohammed Naguib
Thanks    
0
 

Author Comment

by:canuckconsulting
ID: 36535061
This did not work for me.  Here is the code:

public FormProduct()
        {
            _formSearch = new FormSearch(this);
            _formSearch.Show();
            Application.OpenForms[_formSearch.Name].BringToFront();
            InitializeComponent();
        }

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:momonana
ID: 36535305
There is the full code of the two forms
the key here is to define every form to the another one

try it and it will work
I'm Sure  
//this is the code for FormProduct 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class FormProduct : Form
    {
        private FormSearch _formSearch;
        

        private void FormProduct_Load(object sender, EventArgs e)
        {
            

        }

        public FormProduct()
        {
            _formSearch = new FormSearch(this);
            _formSearch.Show();
            Application.OpenForms[_formSearch.Name].BringToFront();
            InitializeComponent();
        }
          
    }
}

Open in new window

//this is the code for FormSearch

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class FormSearch : Form
    {
        private FormProduct formProduct;

        public FormSearch()
        {
            InitializeComponent();
        }

        public FormSearch(FormProduct formProduct)
        {
            // TODO: Complete member initialization
            this.formProduct = formProduct;
        }
    }
}

Open in new window

0
 

Author Comment

by:canuckconsulting
ID: 36535366
I created a new project and this does not work.  I have uploaded the project here:

http://www.sendspace.com/file/oj192v

0
 

Accepted Solution

by:
momonana earned 1500 total points
ID: 36535441
the final solution

is in the event (Shown)  of the FormProduct put this






private void FormProduct_Shown(object sender, EventArgs e)
        {
 this.SendToBack();
        }

Open in new window

0
 

Expert Comment

by:momonana
ID: 36535705
do not forget to evaluate my answers i need points so much

thanks
0
 
LVL 4

Expert Comment

by:AnuTiji
ID: 36535748
Hi

To show the form search in front of formProduct please try the below code in the constructor of the FormProduct

public partial class FormProduct : Form
    {
        public FormProduct()
        {
            InitializeComponent();
            FormSearch forms = new FormSearch();
            forms.Show();
            forms.TopMost = true;        
        }
    }
0
 
LVL 8

Expert Comment

by:jagrut_patel
ID: 36535764
If your design permits then why not show the FormSearch as modal dialog instead?

In the Shown event of FormProduct put,

FormSearch frm = new FormSearch();
frm.ShowDialog();

With model dialog you can even utitlize its DialogResult to know exactly how the search form closed like OK or Cancel.
0
 

Expert Comment

by:momonana
ID: 36535910
as like i said to you canuckconsulting make everything we did lately in the project and
in Shown event of formproduct put this line

this.SendToBack();

it will send the formproduct behind the FormSearch

Thanks
Mohamed Naguib
0
 

Author Closing Comment

by:canuckconsulting
ID: 36536988
In the end I simply did as follows in the Shown event.  Thanks for your help.

        private void FormProduct_Shown(object sender, EventArgs e)
        {
            _formSearch.Show();
        }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 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