Fragen zur Textausrichtung und Positionierng von Buttons und Tabs disablen

  • Hallo!
    Erstmal möchte ich sagen, dass ich es wirklich klasse finde, dass es ein solch tolles Forum für Autoit gibt :)
    Ich schaue hier gerne hinein und die meisten meiner Fragen werden dann schon gelöst.

    Doch drei Fragen bleiben offen :(

    1. Wenn ich einen Button erstelle, würde ich gerne den Text auf dem Button rechtsbündig machen ?(

    2. Die Fenstergröße ändert sich einmal. Doch dadurch verrutschen die Buttons und die Labels... Kann man die irgendiwe fest positionieren?
    Mir ist klar, dass man die Buttons mit Abfragen, ob das Fenster größer als am Anfang ist und durch guictrlsetpos binden kann, doch ich hoffe auf eine einfachere Lösung ^^

    3. Ich habe zwei Gui-Tabs erstellt, die nicht anklickbar sein sollen (bis auf dem ersten ^^)
    Soweit kam ich mit Guictrlsetstate auch schon, doch leider sehen die Tabs so aus, als ob man sie anklicken könnte, denn die Schrift ist schwarz und der Hintergrund normal.
    Bei Textlabeln ist aber die Schriftart heller und der Hintergrund dunkler. Folglich sieht man sofort, dass man die Labels nicht anklicken kann.
    Ich hätte also gerne das Design der Textlabels auf die Tabs übertragen ;)

    Nun, um das dritte Problem zu lösen, habe ich daher Labels auf die Tabs gesetzt. Allerdings sind mir die bei verschiedenen Bildschirmgrößen von den Tabs gerutscht und das Ergebnis sieht daher furchtbar aus :(

    Spoiler anzeigen
    [autoit]


    #include <GuiConstantsEx.au3>
    #include <AVIConstants.au3>
    #include <TreeViewConstants.au3>
    #include <StaticConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $Name, $msg, $Rasse, $Rasse2, $Neu, $Exit, $Tab2, $Tab1
    Global $laden, $x
    GLobal $pos[2]

    [/autoit] [autoit][/autoit] [autoit]

    Global $size = 11.7, $font = "Arial"

    [/autoit] [autoit][/autoit] [autoit]

    Example()

    [/autoit] [autoit][/autoit] [autoit]

    Func Example()

    [/autoit] [autoit][/autoit] [autoit]

    ; GUI
    GuiCreate("Meine Gui", 600, 400)
    GUISetFont($Size, "", "", $Font)

    [/autoit] [autoit][/autoit] [autoit]

    $x = GuiCtrlCreateTab(0, 0, 600, 500)
    Disable()

    [/autoit] [autoit][/autoit] [autoit]

    ; Erster Tab
    GuiCtrlCreateTabItem("Tab1")

    [/autoit] [autoit][/autoit] [autoit]

    $Neu = GuiCtrlCreatebutton("Erstellen", 266,47,160,27)
    GUICtrlSetOnEvent($Neu, "OnNeu")
    ;GUICtrlSetStyle(-2, $SS_RIGHT)

    [/autoit] [autoit][/autoit] [autoit]

    $laden = Guictrlcreatebutton("Laden", 160, 47, 60, 27)
    GUICtrlSetOnEvent($Laden, "OnLaden")
    ;GUICtrlSetStyle(-2, $SS_RIGHT)

    [/autoit] [autoit][/autoit] [autoit]

    Guictrlcreatelabel("oder", 223, 50)
    GuiCTRlsetfont(-1, $size+0.5, "", 2)

    [/autoit] [autoit][/autoit] [autoit]

    $Exit = GUICtrlCreateButton("Exit", 340, 220, 50, 20)
    GUICtrlSetOnEvent($Exit, "OnExit")

    [/autoit] [autoit][/autoit] [autoit]

    ; Zweiter Tab
    $Tab2 = GuiCtrlCreateTabitem("Tab2")
    GUICtrlSetState($Tab2, $GUI_DISABLE)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    while(1)
    Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    ;--------------- Functions ---------------
    Func OnNeu()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Onloeschen()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func onLaden()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Disable()
    Guictrlsetstate($x, $gui_disable)
    GUICTRLSETFONT($x, 13)
    ;Guictrlsetbkcolor($x, 0xECE9D7) ;funktioniert leider nicht...
    ;GUICtrlSetColor($x, 0xECE9D7) ; ""

    [/autoit] [autoit][/autoit] [autoit]

    Guictrlcreatelabel("Tab2", 88,5,58, 20)
    Guictrlsetstate(-1, $gui_disable)
    GUICTRLSETFONT(-2, 12)
    Endfunc

    [/autoit] [autoit][/autoit] [autoit]

    Func OnExit()
    If @GUI_CtrlId = $Exit Then
    Else
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]


    Habe den Quelltext stark vereinfacht ;)


    Wäre toll, wenn jemand die Antworten wüsste :)

    Liebe Grüße
    Elodie

    Einmal editiert, zuletzt von Elodie (24. Mai 2009 um 18:44)

  • Hallo Elodie,

    zu 1. fällt mir im Moment keine Lösung ein
    zu 2. schau dir dázu GUICtrlSetResizing in der Hilfe an
    zu 3. fällt mir im Moment keine Lösung ein, aber bei deinem Löungansatz siehe 2.

    Hab dein DemoSkript mal größen veränderbar gemacht (Erklärungen im Skript)

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GuiConstantsEx.au3>
    #include <AVIConstants.au3>
    #include <TreeViewConstants.au3>
    #include <StaticConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $Name, $msg, $Rasse, $Rasse2, $Neu, $Exit, $Tab2, $Tab1
    Global $laden, $x
    Global $pos[2]

    [/autoit] [autoit][/autoit] [autoit]

    Global $size = 11.7, $font = "Arial"

    [/autoit] [autoit][/autoit] [autoit]

    Example()

    [/autoit] [autoit][/autoit] [autoit]

    Func Example()

    [/autoit] [autoit][/autoit] [autoit]

    ; GUI
    ; GUICreate("Meine Gui", 600, 400)
    GUICreate("Meine Gui", 600, 400,-1,-1, $WS_SIZEBOX + $WS_SYSMENU +$WS_MAXIMIZEBOX +$WS_MINIMIZEBOX)
    GUISetFont($size, "", "", $font)

    [/autoit] [autoit][/autoit] [autoit]

    $x = GUICtrlCreateTab(0, 0, 600, 500) ;Soll nicht höher sein als die GUI => anpassen
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) ;ist an allen 4 Seiten verankert
    GUICtrlSetState($x, $GUI_DISABLE)
    GUICtrlSetFont($x, 13)

    [/autoit] [autoit][/autoit] [autoit]

    ; Erster Tab
    GUICtrlCreateTabItem("Tab1")

    $Neu = GUICtrlCreateButton("Erstellen", 266, 47, 160, 27)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP) ;behält die Breite und ist links und oben verankert
    GUICtrlSetOnEvent($Neu, "OnNeu")
    ;GUICtrlSetStyle(-2, $SS_RIGHT)

    [/autoit] [autoit][/autoit] [autoit]

    $laden = GUICtrlCreateButton("Laden", 160, 47, 60, 27)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP) ;behält die Breite und ist links und oben verankert
    GUICtrlSetOnEvent($laden, "OnLaden")
    ;GUICtrlSetStyle(-2, $SS_RIGHT)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel("oder", 223, 50)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP) ;behält die Breite und ist links und oben verankert
    GUICtrlSetFont(-1, $size + 0.5, "", 2)

    [/autoit] [autoit][/autoit] [autoit]

    $Exit = GUICtrlCreateButton("Exit", 340, 220, 50, 20)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKRight + $GUI_DOCKBottom) ;behält die Breite und ist rechts und unten verankert
    GUICtrlSetOnEvent($Exit, "OnExit")

    [/autoit] [autoit][/autoit] [autoit]

    ; Zweiter Tab
    $Tab2 = GUICtrlCreateTabItem("Tab2")
    GUICtrlSetState($Tab2, $GUI_DISABLE)
    GUICtrlCreateTabItem("")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Disable()
    GUISetState()
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While (1)
    Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>Example

    [/autoit] [autoit][/autoit] [autoit]

    ;--------------- Functions ---------------
    Func OnNeu()
    EndFunc ;==>OnNeu

    [/autoit] [autoit][/autoit] [autoit]

    Func Onloeschen()
    EndFunc ;==>Onloeschen

    [/autoit] [autoit][/autoit] [autoit]

    Func onLaden()
    EndFunc ;==>onLaden

    [/autoit] [autoit][/autoit] [autoit]

    Func Disable()
    GUICtrlSetState($x, $GUI_DISABLE)
    GUICtrlSetFont($x, 13)
    ;Guictrlsetbkcolor($x, 0xECE9D7) ;funktioniert leider nicht...
    ;GUICtrlSetColor($x, 0xECE9D7) ; ""

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel("Tab2", 88, 5, 58, 20) ;Die Werte stimmen nicht => anpassen
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP) ;behält die Breite und ist links und oben verankert
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-2, 12)
    EndFunc ;==>Disable

    [/autoit] [autoit][/autoit] [autoit]

    Func OnExit()
    If @GUI_CtrlId = $Exit Then
    Else
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Exit
    EndFunc ;==>OnExit

    [/autoit]


    Viel Spass damit

    mfg (Auto)Bert
    PS.: geposteten Quelltext bitte immer in AutoIT-TAG's einschliesen und bei längerem Skript unbedingt Spoiler,

  • Hi

    zu 1: $BS_RIGHT = 0x0200

    zu 3: folgendes Beispiel aus dem englischen Forum zeigt, wie man die Tabitems einfärben kann.
    Du kannst versuchen, es so zu verändern, daß nur die Schriftfarbe grau wird:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiTab.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $ODT_TAB = 101
    Global Const $ODS_SELECTED = 0x0001
    Global Const $ODA_DRAWENTIRE = 0x1

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $ODS_FOCUS = 0x0010

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Draw Tab", 300, 200)

    [/autoit] [autoit][/autoit] [autoit]

    $hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED)

    [/autoit] [autoit][/autoit] [autoit]

    $TabItem_1 = GUICtrlCreateTabItem("TabItem 1")
    GUICtrlCreateLabel("", 10, 33, 277, 155)
    GUICtrlSetBkColor(-1, 0xDDAA11)
    GUICtrlSetState(-1, $GUI_DISABLE)

    [/autoit] [autoit][/autoit] [autoit]

    $TabItem_2 = GUICtrlCreateTabItem("TabItem 2")
    GUICtrlCreateLabel("", 10, 33, 277, 155)
    GUICtrlSetBkColor(-1, 0x99BBEE)
    GUICtrlSetState(-1, $GUI_DISABLE)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateTabItem("")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlTab_SetCurSel($hTab, 1)
    _GUICtrlTab_SetCurSel($hTab, 0)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $DRAWITEMSTRUCT

    $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
    "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam)

    If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG

    Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID")
    Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID")
    Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction")
    Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState")
    Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm")
    Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC")

    If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG

    Local $iTextColor, $itmText

    Switch $itmID
    Case 0
    $iBrushColor = 0x11AADD
    Case 1
    $iBrushColor = 0xEEBB99
    EndSwitch

    DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)

    Local $iBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    $iBrush = $iBrush[0]

    Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)

    DLLCall("user32.dll","int","FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)

    Local $tBuffer = DllStructCreate("char[256]")
    DllStructSetData($tBuffer, 1, "Item" & $itmID)
    $itmText = DllStructGetData($tBuffer, 1)

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)

    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _
    "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)

    _WinAPI_SelectObject($hDC, $iBrushOld)
    _WinAPI_DeleteObject($iBrush)

    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]

    lgE

    • Offizieller Beitrag

    Hab das Bsp. von eukalyptus mal etwas verändert. Farbsetzung für die TabItem in einem globalen Array und Fonteinstellung für das aktive Tab.

    Spoiler anzeigen
    [autoit]

    #include <FontConstants.au3>
    #include <TabConstants.au3>
    #include <WinAPI.au3>
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiTab.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $ODT_TAB = 101
    Global Const $ODS_SELECTED = 0x0001
    Global Const $ODA_DRAWENTIRE = 0x1
    Global Const $ODS_FOCUS = 0x0010

    [/autoit] [autoit][/autoit] [autoit]

    Global $aColTabItem[2] = [0x11AADD,0xEEBB99] ; TabItem-Color

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Draw Tab", 300, 200)
    $hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED)
    $TabItem_1 = GUICtrlCreateTabItem("TabItem 1")
    GUICtrlCreateLabel("", 10, 33, 277, 155)
    GUICtrlSetBkColor(-1, 0xDDAA11)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $TabItem_2 = GUICtrlCreateTabItem("TabItem 2")
    GUICtrlCreateLabel("", 10, 33, 277, 155)
    GUICtrlSetBkColor(-1, 0x99BBEE)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateTabItem("")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlTab_SetCurSel($hTab, 1)
    _GUICtrlTab_SetCurSel($hTab, 0)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
    "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam)
    If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG
    If DllStructGetData($DRAWITEMSTRUCT, "itmAction") <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG
    Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID")
    Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC")

    [/autoit] [autoit][/autoit] [autoit]

    Local $iTextColor, $itmText, $iBrushColor = $aColTabItem[$itmID]

    [/autoit] [autoit][/autoit] [autoit]

    DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    $iBrush = $iBrush[0]

    [/autoit] [autoit][/autoit] [autoit]

    Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)
    DLLCall("user32.dll","int","FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)
    Local $tBuffer = DllStructCreate("char[256]")
    DllStructSetData($tBuffer, 1, "Item" & $itmID)
    $itmText = DllStructGetData($tBuffer, 1)

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _
    "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SelectObject($hDC, $iBrushOld)
    _WinAPI_DeleteObject($iBrush)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Hier wird der Font des aktiven Tabs gesetzt: Param1 (14)=Schriftgröße, Param5 (600)=width, letzter=Fontname
    Local $hFont = _WinAPI_CreateFont(14,0,0,0,600,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial')
    _WinAPI_SelectObject($hDC, $hFont)
    _WinAPI_DeleteObject($hFont)

    [/autoit] [autoit][/autoit] [autoit]

    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]
  • Antworten der 1. und 2. Frage haben super geklappt, herzlichen Dank :)
    Beim 3. Problem experimentiere ich noch herum ;)

    Da gibt's aber noch ein kleines weiteres Problem ^^
    Ich versuche gerade kleine gif-Bilder auf die Buttons zu positionieren.
    Problem: Sobald man den button anklicken möchte, verschwinden die Bildchen...
    Ziel: Später sollen dann die Bilder beim Mouseover durch Avis, wegen der Animation, ersetzt werden (Thema zum Mouseover habe ich schon gefunden :) )