Solved

How two form in different Monitor

Posted on 2011-09-13
10
527 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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

Technology Partners: 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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

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