Solved

How two form in different Monitor

Posted on 2011-09-13
10
521 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
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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 125 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 125 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
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.
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…

829 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