Einen wunderschönen Guten Tag,
nun zu Corona Zeiten muß man sich beschäftigen. Also habe ich mein altes SetXY-Modul überarbeitet.
Da ich mit dem Form-Designer nicht warm werde, erstelle ich meine GUIs auf alt hergebrachte Weise.
Nur das ändern derselben ist manchmal nervig. Aber das kennt Ihr ja.
Wer also die Tradition hochhält, für den ist GotoXY gedacht. Als GotoXY.pbi abspeichern.
Code: Alles auswählen
;GotoXY, Gadgets verschieben, ab PB 5.41 x86 Windows 10 - Apr./Mai 2020 by HJBremer
;V.2.04 2 neue Flags: #goGadgetTop + #goGadgetLeft
;V.2.05 move ist jetzt ein flag, wert für move steht in value
; Parameter move kann #goCenter sein, gedacht für #goLeft #goRight um Vertikal zu zentrieren
; Parameter move kann #goTop, #goBottom, #goLeft, #goRight sein um X+Y zu verschieben
DeclareModule GotoXY
Declare.i GotoXY(pbnr, parent, flag, gap=10, moveflag=0, value=0)
; pbnr = Gadget welches verschoben wird
; parent = Gadget auf das Bezug genommen wird
; gap = x und/oder y Abstand zwischen pbnr + parent, kann positiv/negativ sein
; move = flag für zusätzlich verschieben, #goLeft, #goRight, #goTop, #goBottom, #goCenter=vertikal
; value = für move
; flags
If Defined(goLeft, #PB_Constant) = 0
XIncludeFile "gotoxy-const.pbi"
EndIf
Declare.i SetGadgetSize(pbnr, w=2, h=0)
Declare.i WriteText(pbnr, text$, fcolor=#PB_Default, bcolor=#PB_Default, fontid=#PB_Default)
EndDeclareModule
Module GotoXY
EnableExplicit
Procedure.i GotoXY(pbnr, parent, flag, gap=10, moveflag=0, value=0)
If IsGadget(pbnr) = 0 : Debug "Gadget gibt es nicht: " + pbnr : ProcedureReturn : EndIf
Protected x = GadgetX(pbnr), y = GadgetY(pbnr) ;x y Gadget Werte
Protected w = GadgetWidth(pbnr), h = GadgetHeight(pbnr) ;w h Gadget Werte
Protected px, py, pw, ph, pth, parenttyp = #PB_GadgetType_Unknown ;Parent Werte
If IsGadget(parent) : parenttyp = GadgetType(parent) : EndIf
If parenttyp = #PB_GadgetType_Unknown ; parent = Window
px = WindowX(parent): py = WindowY(parent)
pw = WindowWidth(parent): ph = WindowHeight(parent)
Else ; parent = Gadget
px = GadgetX(parent): py = GadgetY(parent)
pw = GadgetWidth(parent): ph = GadgetHeight(parent)
If parenttyp = #PB_GadgetType_Panel : pth = GetGadgetAttribute(parent, #PB_Panel_TabHeight) : EndIf
EndIf
Select flag
Case #goLeft: x = px - w - gap: y = py ;links neben dem Parent oben
Case #goRight: x = px + pw + gap: y = py ;rechts neben dem Parent oben
Case #goLeftBottom: x = px - w - gap: y = py + ph - h ;links neben dem Parent unten
Case #goRightBottom: x = px + pw + gap: y = py + ph - h ;rechts neben dem Parent unten
Case #goTopLeft: x = px: y = py - h - gap ;über dem Parent links (oder #goTop)
Case #goTopRight: x = px + pw - w: y = py - h - gap ;über dem Parent rechts
Case #goTopCenter: x = px + ((pw - w)/2): y = py - h - gap ;über dem Parent Mitte
Case #goBottomLeft: x = px: y = py + ph + gap ;unter dem Parent links (#goBottom)
Case #goBottomRight: x = px + pw - w: y = py + ph + gap ;unter dem Parent rechts
Case #goBottomCenter: x = px + ((pw - w)/2): y = py + ph + gap ;unter dem Parent Mitte
Case #goGadgetFill: x = gap: y = gap: w=pw-(2*gap): h=ph-(2*gap) ;ganzes Fenster ausfüllen
Case #goGadgetWidth: w = pw ;gleiche Breite wie Parent
Case #goGadgetHeight: h = ph ;gleiche Höhe wie Parent
Case #goGadgetTop: h = py - y - gap ;bis zur oberen Seite Parent (Gadgets) - Abstand
Case #goGadgetLeft : w = px - x - gap ;bis zur linken Seite Parent (Gadgets) - Abstand
Case #goGadgetRight: w = px + pw - x ;bis zur rechten Seite Parent (Gadgets)
Case #goGadgetBottom: h = py + ph - y ;bis zur unteren Seite Parent (Gadgets)
Case #goWindowRight: w = pw - x - gap ;bis zum Rand vom Parent (Window) - Abstand
Case #goWindowBottom: h = ph - y - gap - pth ;bis zum Rand vom Parent (Window) - Abstand
;- Oder Kombinationen für Parent = Window, Container, Panel (+ anstatt | geht auch)
Case #goTopLeft|#goInside: x = gap: y = gap ;Inside oben links (oder #goTop)
Case #goTopRight|#goInside: x = pw - w - gap: y = gap ; oben rechts
Case #goTopCenter|#goInside: x = (pw - w) / 2: y = gap ; oben mitte
Case #goBottomLeft|#goInside: x = gap: y = ph - h - gap - pth ; unten links (#goBottom)
Case #goBottomRight|#goInside: x = pw - w - gap: y = ph - h - gap - pth ; unten rechts
Case #goBottomCenter|#goInside: x = (pw - w) / 2: y = ph - h - gap - pth ; unten mitte
Default: Debug "unbekanntes Flag " + flag: ProcedureReturn
EndSelect
If parenttyp = #PB_GadgetType_Frame And flag & #goInside : x + px : y + py : EndIf ;innerhalb eines Frame
Select moveflag
Case #goLeft: x - value
Case #goRight: x + value
Case #goTop: y - value
Case #goBottom: y + value
Case #goCenter: y + ((ph-h) / 2)
EndSelect
ResizeGadget(pbnr, x, y, w, h)
;Debug Str(pbnr) + ":" + Str(x) + "," + Str(y + moveY) + "," + Str(w) + "," + Str(h)
EndProcedure
EndModule
UseModule GotoXY
Code: Alles auswählen
;16.05.2020 - für GotoXY.pbi
EnumerationBinary
#goLeft ; oben links neben dem parent, auch für moveflag
#goRight ; oben rechts neben dem parent, auch für moveflag
#goLeftBottom ; unten links neben dem parent
#goRightBottom ; unten rechts neben dem parent
#goTopLeft ; oben links über dem parent
#goTopRight ; oben rechts über dem parent
#goTopCenter ; mittig über dem parent
#goBottomLeft ; unten links unter dem parent
#goBottomRight ; unten rechts unter dem parent
#goBottomCenter ; mittig unter dem parent
#goGadgetFill ; füllt ganzes Window, Container etc aus
#goGadgetWidth ; gleiche Breite wie Parent
#goGadgetHeight ; gleiche Höhe wie Parent
#goGadgetTop ; Höhe bis zur oberen Seite Parent (Gadgets) - Abstand
#goGadgetLeft ; Breite bis zur linken Seite Parent (Gadgets) - Abstand
#goGadgetRight ; Breite bis zur rechten Seite Parent (Gadgets)
#goGadgetBottom ; Höhe bis zur unteren Seite Parent (Gadgets)
#goWindowRight ; Breite bis zum RAND vom Parent (Window)
#goWindowBottom ; Höhe bis zum Rand vom Parent (Window)
#goInside ; für Oder-Kombinationen, wenn Parent = Window, Container, Panel !!! (+ anstatt | geht auch)
#goCenter ; nur für moveflag, verschiebt vertikal in Verbindung mit #goLeft + #goRight
EndEnumeration
#goTop = #goTopLeft ; auch für moveflag
#goBottom = #goBottomLeft ; auch für moveflag
; Muster CMD Datei Windows x64 ab 'echo off' z.B. mit Notepad erstellen (Semikolon entfernen)
;
; als gotoxy.cmd speichern (ANSI File), im gleichen Verzeichnis wie gotoxy-const.pbi !
; Doppelclick auf CMD-Datei und gotoxy.res ins PB Resident-Verzeichnis kopieren.
; ev. Verzeichnisname anpassen
; @echo off
; @prompt --$g
;
; echo.
; echo wenn die gotoxy.res im Resident-Verzeichnis vorher nicht geloescht wird, ist das Ergebnis meistens Mist !!!
;
; set pbvz=C:\Programme\PureBasic572x64
;
; %pbvz%\Compilers\pbcompiler.exe gotoxy-const.pbi /resident gotoxy.res /IGNORERESIDENT /CREATERESIDENT
;
; pause