Jump to content

GUI Input, Edit, or Label with rounded corners


Recommended Posts

So, I feel like this is going to be a really stupid question, but I'm going to ask it anyway.

I want to make an input control with rounded corners.  I'd be fine with an edit control with rounded corners, or a label with rounded corners which I could then place a borderless input control over the top of.

It's not going to be extravagant. It's going to be a white control, with (probably) a thin, light gray border, on a white GUI.

I've dug through the forum, but the posts I'm finding are years old, and often take hundreds of lines to accomplish not-exactly what I'm looking for.  I'm hoping someone familiar with modern GUI design will see this and just be like, "Oh yeah, you just do [blank]."

Any help is appreciated.

 

Edit: I built a function based on Nine's code.  I've attached it.

#include <GUIConstants.au3>
#include <GuiEdit.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>


Const $SC_MOVE = 0xF010

Dim $hGUI = GUICreate("Multiple Childs"), $hLabel1, $hLabel2, $iW = 250, $iH = 30, $sBkColor = 0xFFFFFF, $sTxtColor = 0x000000

GUISetFont(10, 500, 0, "Calibri")
GUISetBkColor(0x5D6D7E)
GUISetState()

$hLabel1 = _GuiCtrlCreateRoundedInput($hGUI, "Cats", $iW, $iH, 20, 20, $sBkColor, $sTxtColor, "Input 1", 11, -1, -1, "Segoe UI")

$hLabel2 = _GuiCtrlCreateRoundedInput($hGUI, "Dogs", $iW, $iH, 20, 70, $sBkColor, $sTxtColor, "Input 2", 11, -1, -1, "Segoe UI")


While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop

  EndSwitch
WEnd



Func _GuiCtrlCreateRoundedInput($hParent, $sText, $iWd, $iHt, $iLeft, $iTop, $sBkClr = 0xFFFFFF, $sTxtClr = 0x000000, $sCue = "", $iFontSize = 10, $iFontWt = 500, $iFontAttrib = 0, $sFontName = "Calibri")
    Local $hGui_Inp, $hRgn, $hInp

    $hGui_Inp = GUICreate("", $iWd, $iHt, $iLeft, $iTop, $WS_CHILD, $WS_EX_CONTROLPARENT, $hParent)
    GUISetBkColor($sBkClr)
    GUICtrlCreateLabel("", 0, 0, $iWd, $iHt)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, $sBkClr)

    $hInp = GUICtrlCreateInput($sText, 5, 5, ($iWd - 10), ($iHt - 10), BitOR($ES_UPPERCASE, $SS_CENTERIMAGE), $WS_EX_TOOLWINDOW)
    GUICtrlSetFont(-1, $iFontSize, $iFontWt, $iFontAttrib, $sFontName)
    GUICtrlSetColor(-1, $sTxtClr)
    GUICtrlSetBkColor(-1, $sBkClr)
    _GUICtrlEdit_SetCueBanner(-1, $sCue)

    $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iWd, $iHt, 20, 20)
    _WinAPI_SetWindowRgn($hGui_Inp, $hRgn)

    GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
    GUISetState()

    Return $hGui_Inp

EndFunc ;==>_GuiCtrlCreateRoundedInput


Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then
        If $hWnd = $hGUI Then Return
        Return False
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc ;==>On_WM_SYSCOMMAND

 

Edited by drapdv
Link to comment
Share on other sites

Try this :

#include <GUIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>

Global $hGUI = GUICreate("Test")

Global $iW = 150, $iH = 30
Global $hHelp = GUICreate("", $iW, $iH, 20, 20, $WS_CHILD, 0, $hGUI)
Global $idLabel = GUICtrlCreateLabel("", 0, 0, $iW, $iH)
GUICtrlSetBkColor(-1, 0x6BEFF5)
GUICtrlCreateInput("", 5, 5, $iW - 10, $iH - 10, -1, $WS_EX_TOOLWINDOW)
GUICtrlSetBkColor(-1, 0x6BEFF5)

_WinAPI_SetParent($hHelp, $hGui)
Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20)
_WinAPI_SetWindowRgn($hHelp, $hRgn)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hHelp)

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
  EndSwitch
WEnd

 

Link to comment
Share on other sites

Nine,

Thank you so much for this!  I have just one more question. Is it possible to have more than one label/input child window?  I've tried to add one, using WinMove to position it within the $hGUI parent.  While both display, the first one becomes unresponsive.

Thank you again for your help!

#include <GUIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>

Global $hGUI = GUICreate("Test")

Global $iW = 150, $iH = 30

Global $hLabel1 = GUICreate("", $iW, $iH, 20, 20, $WS_CHILD, 0, $hGUI)
GUICtrlCreateLabel("", 0, 0, $iW, $iH)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlCreateInput("INPUT1", 5, 5, $iW - 10, $iH - 10, -1, $WS_EX_TOOLWINDOW)
GUICtrlSetBkColor(-1, 0xFFFFFF)
WinMove($hLabel1, "", 0, 30, 150, 30)

_WinAPI_SetParent($hLabel1, $hGui)
Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20)
_WinAPI_SetWindowRgn($hLabel1, $hRgn)


Global $hLabel2 = GUICreate("", $iW, $iH, 20, 20, $WS_CHILD, 0, $hGUI)
GUICtrlCreateLabel("", 0, 0, $iW, $iH)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlCreateInput("INPUT2", 5, 5, $iW - 10, $iH - 10, -1, $WS_EX_TOOLWINDOW)
GUICtrlSetBkColor(-1, 0xFFFF00)
WinMove($hLabel2, "", 0, 70, 150, 30)

_WinAPI_SetParent($hLabel2, $hGui)
Global $hRgn2 = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20)
_WinAPI_SetWindowRgn($hLabel2, $hRgn2)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hLabel1)
GUISetState(@SW_SHOW, $hLabel2)

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
  EndSwitch
WEnd
Edited by drapdv
Link to comment
Share on other sites

Here a better approach for multiple children (w/ code revision).  You can tab from one input to the other.

#include <GUIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>

Global $hGUI = GUICreate("Multiple Childs")
GUISetState()

Global $iW = 150, $iH = 30

Global $hLabel1 = GUICreate("", $iW, $iH, 20, 20, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
GUICtrlCreateLabel("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$idInput1 = GUICtrlCreateInput("INPUT1", 5, 5, $iW - 10, $iH - 10, -1, $WS_EX_TOOLWINDOW)
GUICtrlSetBkColor(-1, 0xFFFFFF)

Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20)
_WinAPI_SetWindowRgn($hLabel1, $hRgn)
GUISetState()

Global $hLabel2 = GUICreate("", $iW, $iH, 20, 60, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
GUICtrlCreateLabel("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetBkColor(-1, 0xFFFF00)
$idInput2 = GUICtrlCreateInput("INPUT2", 5, 5, $iW - 10, $iH - 10, -1, $WS_EX_TOOLWINDOW)
GUICtrlSetBkColor(-1, 0xFFFF00)

Global $hRgn2 = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20)
_WinAPI_SetWindowRgn($hLabel2, $hRgn2)
GUISetState()

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
  EndSwitch
WEnd

Not sure about WinMove (did not test), but the problem was not it...

Edited by Nine
Link to comment
Share on other sites

  • 2 weeks later...

Thank you, ioa747.  I appreciate your example, too.  I ended up building a function based on Nine's code, but there may well be advantages to using $GUI_GR_BEZIER.  Again, thank you for replying.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...