Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How two form in different Monitor

Posted on 2011-09-13
10
Medium Priority
?
530 Views
Last Modified: 2013-12-17
Hi,

My application should display two screens, I have created 2 forms but I can not display both at the same time or when I do the main form loses focus.

Thx
0
Comment
Question by:abgconsulting
[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
10 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36528347
>>or when I do the main form loses focus

Only one form can have the focus at one time, it is impossible for both to have the focus simultaneously.
0
 

Author Comment

by:abgconsulting
ID: 36528371
I know that but i want thethe focus for the principal form
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36528590
How do you display the second form ?
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 5

Expert Comment

by:DerZauberer
ID: 36528818
Are you using Windows Forms?

Then maybe you can use some windows api to make a portion of one window appear on the desktop as if it was a second window. Maybe that's what you want ... Form with a button and a panel and another button on panel, panel beeing "detached" on button1 click ... you can then click buttons on detached panel without main form loosing focus...

    public partial class Form1 : Form
    {

        [DllImport("User32", CharSet=CharSet.Auto, ExactSpelling=true)]
        internal static extern IntPtr SetParent(IntPtr hWndChild, int hWndParent);        
        [DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", SetLastError = true)]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
 
        private const int GWL_STYLE = -16;
        private const uint WS_BORDER = 0x800000;
        private const uint WS_POPUP = 0x80000000;
        private const uint WS_CAPTION = 0x00C00000;
        private const uint WS_SYSMENU = 0x00080000;


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr pnlHandle = this.panel1.Handle;
            SetWindowLong(pnlHandle, GWL_STYLE, GetWindowLong(pnlHandle, GWL_STYLE) | WS_CAPTION | WS_BORDER);
            SetParent(pnlHandle, 0);
        }
    }

Open in new window

0
 

Author Comment

by:abgconsulting
ID: 36528956
Hi DerZauberer,

Yes i am using form
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36528986
To repeat myself:

How do you display the second form ?  (The behaviour is something to do with that, telling what you do will be a big help to getting the behaviour you want).
0
 
LVL 40
ID: 36529186
With the following code in the main form:

Form2 frm = new Form2();
frm.Show();
this.Focus();

Open in new window

0
 

Author Comment

by:abgconsulting
ID: 36529295
The second is displaying in another screen, i want to show it at the same time with the main form.

This code below is what i 'hve done to open the customerscreen at same time with formMain but does'nt work.

Now i m trying to instatiate a new customer screen form in formMain class call the Form customer show() in the load and close() in the closing but it doesn't work i h've the formSplash in the foregroun i cannot access to the main  
private void FormSplash_Shown(object sender, EventArgs e)
        {
            DialogResult result;
            FormLogin formLogin = new FormLogin();
            FormMain formMain = new FormMain();
            FormCustomer formCustomer = new FormCustomer();

            // FormMain.InitDevice

            do
            {
                result = formLogin.ShowDialog();
                // cancel
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
                // OK
                else if (result == DialogResult.OK)
                {

                    if (Project.Services.ValidateLogin(formLogin.tbUserName.Text, formLogin.tbPwd.Text))
                    {

                        FormCustomer formCustomer = new FormCustomer();
                        formCustomer.ShowDialog();
                        formMain.ShowDialog();
                    }
                }

            } while (result == DialogResult.OK);
            // FormMain.CloseDevice

Open in new window

0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 36529408
                       formCustomer.ShowDialog();
                        formMain.ShowDialog();


ShowDialog will open a form AND WAIT until it closes.
At the first of those two lines you show the first form and force the code to wait until that form is closed before the second form is opened (which also forces the code to wait until that for is closed).

At least one of those forms should be shown with a Show() not a ShowDialog().  Also look at the Application.Run code in a completely new windows form application.  I guess you don't have code like that in your app either - which could cause problems with the message loop.
0
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 500 total points
ID: 36529443
To clarify so everyone is on the same page.
The problem is just that you want both forms to be useable at the same time so you can switch between them correct? Just as if they were different windows or something.

In that case, Andy's last post is good. The normal behaviour of forms is to have the child form steal focus until it is dismissed. All you need to do is use Show() instead of ShowDialog() for the new one. It doesn't matter how the first one was created.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

721 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