Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In C# WinForms I am trying to create proof of concept. Trying to bring a window on top of other windows without stealing the input focus from what the user was doing before the window came up. Let say user is typing an email, and my form will come up covering email partially or fully, the user should still be able to continue typing an email (obviously user may not see what he /she is typing but still...)

I tried a few things below, could not achieve desired effect.

What I have tried:

C#
public partial class Form1 : Form
    {
        private const int SW_SHOWNA = 4;
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private Timer timer;

        public Form1()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Interval = 2000;

            timer.Tick += Timer_Tick;
            timer.Enabled = true;
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            Console.WriteLine("Raised: {0}", e.ToString());
            
            //this.Visible = true;
            //this.BringToFront();
            this.Activate();
            ShowWindow(this.Handle, SW_SHOWNA);
            //this.Show();
        }

        protected override bool ShowWithoutActivation
        {
            get { return true; }
        }
Posted
Comments
[no name] 17-Jan-20 23:47pm    
You can use "Always On Top" / Top window, but still have to activate the window "under" after showing a "top" window (if it activates). And / or disable focus / activate for that window.
Maciej Los 5-Mar-21 2:50am    
Sounds suspicious to me...

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900