Solved

How two form in different Monitor

Posted on 2011-09-13
10
517 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now