What is a powerful way to make a form bring a front?

What is a powerful way to make the form transfer before all other applications using a Windows C # application?

+3
source share
6 answers

Use the SetWindowsPos () api function

+1
source

Powerfully forcing the user to click the icon of your application window on the taskbar.

+15
source

.TopMost true

+7

, :

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace LicenseManager {

  public static class WinApi {

    [DllImport( "user32.dll" )]
    static extern bool SetWindowPos( IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags );

    static private IntPtr HWND_TOPMOST = new IntPtr( -1 );

    private const uint SWP_NOSIZE = 0x0001;
    private const uint SWP_NOMOVE = 0x0002;

    static public void MakeTopMost( Form f ) {
      SetWindowPos( f.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
    }

  }
}
+6

this.BringToFront();

.

+5

. , winforms , MakeTopMost form.load. , winforms MSI, Windows .

, , . , MakeWindowNormal form.shown, , Windows, (. http://msdn.microsoft.com/en-us/library/86faxx0d(v=vs.110).aspx ). ( , ), .

static public void MakeWindowNormal(Form f)
{
    SetWindowPos(f.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
+1

Source: https://habr.com/ru/post/1715676/


All Articles