[DllImport("user32.dll", EntryPoint="SetWindowPos")] static extern bool SetWindowPos(int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
/// <summary> /// The MoveWindow function changes the position and dimensions of the specified window. For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. For a child window, they are relative to the upper-left corner of the parent window's client area. /// </summary> /// <param name="hWnd">Handle to the window.</param> /// <param name="X">Specifies the new position of the left side of the window.</param> /// <param name="Y">Specifies the new position of the top of the window.</param> /// <param name="nWidth">Specifies the new width of the window.</param> /// <param name="nHeight">Specifies the new height of the window.</param> /// <param name="bRepaint"> /// Specifies whether the window is to be repainted. /// If this parameter is TRUE, the window receives a message. /// If the parameter is FALSE, no repainting of any kind occurs. /// This applies to the client area, the nonclient area (including the title bar and scroll bars), /// and any part of the parent window uncovered as a result of moving a child window. /// </param> /// <returns> /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// To get extended error information, call GetLastError. /// </returns> /// <remarks> /// If the bRepaint parameter is TRUE, the system sends the WM_PAINT message to the window procedure immediately after moving the window (that is, /// the MoveWindow function calls the UpdateWindow function). If bRepaint is FALSE, the application must explicitly invalidate or redraw any parts /// of the window and parent window that need redrawing. MoveWindow sends the WM_WINDOWPOSCHANGING, /// WM_WINDOWPOSCHANGED, WM_MOVE, WM_SIZE, and WM_NCCALCSIZE messages to the window. /// </remarks> [DllImport("user32.dll", CharSet=CharSet.Auto)] static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); }
Ja, det kan jeg da egentlig godt se. Det er lidt pudsigt - hvis man spørger på MainWindowHandle én gang, hvor den er 0 (vinduet ikke sat), og anden gang man spørger, er den stadig 0 - også selvom den er sat.
Derimod laver man en Thread.Sleep(4000); hvorefter man kalder MainWindowHandle, kører det hele som det skal.
Der er også mange andre muligheder du kan lege med. Prøv f.eks. AnimateWindow. Når du har fået ovenstående til at funke, er det lige til højrebenet med de andre window kommandoer fra user32.dll.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.