16. januar 2006 - 13:11Der er
7 kommentarer og 1 løsning
centreret vindue
Når man bruger følgende koder skifter vinduet størelse, men øverst venstre hjørne bliver samme sted på skærmen. Jeg vil gerne at vinduet altid er centreret, både på tværs og lodret. Er det mugligt?
Så hjar desværre ikke nogen gode idéer - bortset fra at du evt med et api kan program kan teste skærmopløsningen og så sætte antal pixels i forhold til det.
prøv at køre denne makro (xl2000 -> ) Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _ ByVal nIndex As Long) As Long Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _ ByVal hdc As Long) As Long
Const HORZRES = 8 Const VERTRES = 10
Function ScreenResolution() Dim lRval As Long Dim lDc As Long Dim lHSize As Long Dim lVSize As Long lDc = GetDC(0&) lHSize = GetDeviceCaps(lDc, HORZRES) lVSize = GetDeviceCaps(lDc, VERTRES) lRval = ReleaseDC(0, lDc) ScreenResolution = lHSize & "x" & lVSize End Function
Sub test()
Dim lExcelVandret As Long Dim lExcelLodret As Long Dim vScreenVandret Dim vScreenLodret Dim temp temp = Split(ScreenResolution(), "x") lExcelVandret = Application.Width / 2 lExcelLodret = Application.Height / 2 vScreenVandret = (CLng(temp(0)) * 0.75) / 2 vScreenLodret = (CLng(temp(1)) * 0.75) / 2 Application.Left = vScreenVandret - lExcelVandret Application.Top = vScreenLodret - lExcelLodret
Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _ ByVal nIndex As Long) As Long Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _ ByVal hdc As Long) As Long
Const HORZRES = 8 Const VERTRES = 10
Function ScreenResolution() Dim lRval As Long Dim lDc As Long Dim lHSize As Long Dim lVSize As Long lDc = GetDC(0&) lHSize = GetDeviceCaps(lDc, HORZRES) lVSize = GetDeviceCaps(lDc, VERTRES) lRval = ReleaseDC(0, lDc) ScreenResolution = lHSize & "x" & lVSize End Function
Sub test()
Dim lExcelVandret As Long Dim lExcelLodret As Long Dim vScreenVandret As Long Dim vScreenLodret As Long Dim temp temp = ScreenResolution() lExcelVandret = Application.Width / 2 lExcelLodret = Application.Height / 2 vScreenVandret = (CLng(Left(temp, InStr(1, temp, "x") - 1)) * 0.75) / 2 vScreenLodret = (CLng(Right(temp, Len(temp) - InStr(1, temp, "x"))) * 0.75) / 2 Application.Left = vScreenVandret - lExcelVandret Application.Top = vScreenLodret - lExcelLodret
Jeg har prøvet igen, jag havde ikke lagt koden ind i et nyt modul, nu virker det tak.
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.