Solved

How two form in different Monitor

Posted on 2011-09-13
10
519 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
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.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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