vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Top-Preis! AP-Access-Tools-CD Volume 1  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Re: StartUpPosition 1 - Fenstermitte 
Autor: B.Th.
Datum: 01.09.25 17:13

Subs im Modul

' === Fenster exakt mittig auf Monitor der Referenzform setzen ===
Public Sub CenterFormOnSameMonitor(ByVal frmToCenter As Form, ByVal _
  referenceForm As Form)
    Dim hMonitor As Long
    Dim mi As MONITORINFO
    Dim hwndTarget As Long
 
    hMonitor = MonitorFromWindow(referenceForm.hWnd, MONITOR_DEFAULTTONEAREST)
    mi.cbSize = Len(mi)
 
    If GetMonitorInfo(hMonitor, mi) <> 0 Then
        Dim monitorLeft As Long
        Dim monitorTop As Long
        Dim monitorWidth As Long
        Dim monitorHeight As Long
        Dim winWidth As Long
        Dim winHeight As Long
        Dim newLeft As Long
        Dim newTop As Long
 
        ' Monitor-Infos holen (in echten Pixeln)
        monitorLeft = mi.rcWork.Left
        monitorTop = mi.rcWork.Top
        monitorWidth = mi.rcWork.Right - mi.rcWork.Left
        monitorHeight = mi.rcWork.Bottom - mi.rcWork.Top
 
        ' Fenstergröße (in Pixeln!)
        winWidth = frmToCenter.Width \ Screen.TwipsPerPixelX
        winHeight = frmToCenter.Height \ Screen.TwipsPerPixelY
 
        ' Neue Position berechnen (zentriert im Arbeitsbereich des Monitors)
        newLeft = monitorLeft + ((monitorWidth - winWidth) \ 2)
        newTop = monitorTop + ((monitorHeight - winHeight) \ 2)
 
        ' Fensterposition setzen (in Pixeln!)
        hwndTarget = frmToCenter.hWnd
        Call SetWindowPos(hwndTarget, 0, newLeft, newTop, 0, 0, SWP_NOSIZE Or _
          SWP_NOZORDER Or SWP_NOACTIVATE)
    End If
End Sub
' === Form relativ zur Referenzform positionieren ===
Public Sub PositionFormRelativeToForm(ByVal frmToMove As Form, ByVal _
  referenceForm As Form, ByVal position As String, Optional ByVal spacing As _
  Long = 10)
    Dim refLeft As Long
    Dim refTop As Long
    Dim refWidth As Long
    Dim refHeight As Long
    Dim winWidth As Long
    Dim winHeight As Long
    Dim newLeft As Long
    Dim newTop As Long
 
    ' Konvertiere Referenz-Form-Koordinaten in Pixel
    refLeft = referenceForm.Left \ Screen.TwipsPerPixelX
    refTop = referenceForm.Top \ Screen.TwipsPerPixelY
    refWidth = referenceForm.Width \ Screen.TwipsPerPixelX
    refHeight = referenceForm.Height \ Screen.TwipsPerPixelY
 
    ' Ziel-Form-Größe in Pixel
    winWidth = frmToMove.Width \ Screen.TwipsPerPixelX
    winHeight = frmToMove.Height \ Screen.TwipsPerPixelY
 
    Select Case LCase(position)
        Case "right"
            newLeft = refLeft + refWidth + spacing
            newTop = refTop + (refHeight - winHeight) \ 2
 
        Case "left"
            newLeft = refLeft - winWidth - spacing
            newTop = refTop + (refHeight - winHeight) \ 2
 
        Case "below"
            newLeft = refLeft + (refWidth - winWidth) \ 2
            newTop = refTop + refHeight + spacing
 
        Case "above"
            newLeft = refLeft + (refWidth - winWidth) \ 2
            newTop = refTop - winHeight - spacing
 
        Case "center"
            newLeft = refLeft + (refWidth - winWidth) \ 2
            newTop = refTop + (refHeight - winHeight) \ 2
 
        Case Else
            ' Default: center
            newLeft = refLeft + (refWidth - winWidth) \ 2
            newTop = refTop + (refHeight - winHeight) \ 2
    End Select
 
    ' Position mit SetWindowPos setzen (in echten Pixeln)
    Call SetWindowPos(frmToMove.hWnd, 0, newLeft, newTop, 0, 0, SWP_NOSIZE Or _
      SWP_NOZORDER Or SWP_NOACTIVATE)
End Sub
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
StartUpPosition 1 - Fenstermitte141B.Th.01.09.25 16:54
Re: StartUpPosition 1 - Fenstermitte55B.Th.01.09.25 17:13
Re: StartUpPosition 1 - Fenstermitte56B.Th.01.09.25 17:15
Re: StartUpPosition 1 - Fenstermitte38B.Th.02.09.25 18:16

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel