Hallo,
ist es möglich, einem Edit-Feld einen Placeholder zu verpassen (Beispiel)?
Mir ist klar, dass das nicht so einfach geht, aber geht das evtl. über irgendwelche Tricks (DllCall o.Ä.)?
Vielen Dank
SAPlayer
GUI: Placeholder im Edit
Moderator: jNizM
Re: GUI: Placeholder im Edit
Das erste was mir da in den Sinn kommt, wäre, dem Edit eine normale Voreinstellung zu geben und das Edit dann zu leeren, sobald es ein Klick Event empfängt.
Edit: Und vielleicht erst die Schriftfarbe auf Grau setzen und dann nach dem Klick auf Schwarz.
Allerdings müsste man auch erkennen, wenn aus dem Edit herausgeklickt wird (oder in ein anderes). Dann müsste man natürlich wieder Schriftfarbe und Inhalt ändern, falls es noch leer ist.
Edit: Und vielleicht erst die Schriftfarbe auf Grau setzen und dann nach dem Klick auf Schwarz.
Allerdings müsste man auch erkennen, wenn aus dem Edit herausgeklickt wird (oder in ein anderes). Dann müsste man natürlich wieder Schriftfarbe und Inhalt ändern, falls es noch leer ist.
"Nothing is quieter than a loaded gun." - Heinrich Heine
Re: GUI: Placeholder im Edit
Das ist schonmal nicht so schlecht, jedoch müsste man dann bei Gui, Submit (bzw. GuiControlGet) unterscheiden können, ob der eingetragene Wert der Placeholder ist oder der echte Wert (es kann ja sein, dass jemand Name heißt ).
Außerdem ist der Text nicht grau
Vielleicht findet ja jemand noch eine bessere Lösung.
Außerdem ist der Text nicht grau
Vielleicht findet ja jemand noch eine bessere Lösung.
Re: GUI: Placeholder im Edit
Doch, theoretisch kann man ja auch die Schriffarbe im Edit mit GuiControl ändern, aber trotzdem stimme ich dir zu, dass die Lösung relativ unelegant ist.SAPlayer wrote:Außerdem ist der Text nicht grau
"Nothing is quieter than a loaded gun." - Heinrich Heine
Re: GUI: Placeholder im Edit
In diesem Thread postet VxE ein funktionsfähiges Beispiel:
http://www.autohotkey.com/board/topic/5 ... nner-work/
Allerdings scheint es bei mir nicht ganz zu funktionieren, es wird immer nur der erste Buchstabe des übergebenen Strings angezeigt. (statt "First Name" und "Last Name")
Sowohl unter Win7 Home SP1 als auch bei WinXP Professional SP2.
http://www.autohotkey.com/board/topic/5 ... nner-work/
Allerdings scheint es bei mir nicht ganz zu funktionieren, es wird immer nur der erste Buchstabe des übergebenen Strings angezeigt. (statt "First Name" und "Last Name")
Sowohl unter Win7 Home SP1 als auch bei WinXP Professional SP2.
"Nothing is quieter than a loaded gun." - Heinrich Heine
Re: GUI: Placeholder im Edit
Danke!
Habe etwas gefunden und mir daraus das gemacht (getestet unter ANSI 32bit):
Habe etwas gefunden und mir daraus das gemacht (getestet unter ANSI 32bit):
Code: Select all
/*
## Funktion: SetEditPlaceholder
## Beschreibung: Setzt einen Platzhalter für ein Edit-Feld. Dieser ist nur sichtbar, solange nichts in dem Feld steht. Entspricht dem Attribut placeholder in HTML.
## Parameter:
# control: Entweder ein HWND oder die zugewiesene Variable (als String!) des Steuerelements.
# string: Der Text, der als Platzhalter im Steuerelement stehen soll.
# showalways: Bestimmt, ob der Text auch angezeigt werden soll, während das Steuerelement Fokus hat. Standard: 0 (deaktiviert)
## return: "" (kein besonderer Wert)
*/
SetEditPlaceholder(control, string, showalways = 0){
if control is not number
GuiControlGet, control, HWND, %control%
if(!A_IsUnicode){
VarSetCapacity(wstring, (StrLen(wstring) * 2) + 1)
DllCall("MultiByteToWideChar", UInt, 0, UInt, 0, UInt, &string, Int, -1, UInt, &wstring, Int, StrLen(string) + 1)
}
else
wstring := string
DllCall("SendMessageW", "UInt", control, "UInt", 0x1501, "UInt", showalways, "UInt", &wstring)
return
}
Re: GUI: Placeholder im Edit
cool! das muss ich ausprobieren! jetzt und sofort!
EDIT:
Prima!!!!!!!!!!!!!!!!!!!!!!!!!
EDIT:
Code: Select all
Gui, Add, Edit, w100 hwndhEditA
Gui, Add, Edit, wp hwndhEditB
SetEditPlaceholder(hEditA,"First Name",1)
SetEditPlaceholder(hEditB,"Last Name",1)
Gui, Show
return
GuiClose:
ExitApp
Code: Select all
EditShowBalloonTip(h, title, text, timeout=1000) {
ControlGetPos,x,y,,t,,ahk_id %h%
ToolTip, %title%`n%text%, %x%, % (y+t)
SetTimer, RemoveToolTip, %timeout%
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
}
SetEditPlaceholder(control, string, showalways = 0){
if control is not number
GuiControlGet, control, HWND, %control%
if(!A_IsUnicode){
VarSetCapacity(wstring, (StrLen(wstring) * 2) + 1)
DllCall("MultiByteToWideChar", UInt, 0, UInt, 0, UInt, &string, Int, -1, UInt, &wstring, Int, StrLen(string) + 1)
}
else
wstring := string
DllCall("SendMessageW", "UInt", control, "UInt", 0x1501, "UInt", showalways, "UInt", &wstring)
return
}
Gui, Add, Picture, y6 x6 w48 h-1 Icon161, %A_Windir%\system32\shell32.dll
Gui, Add, Edit, yp+4 x+2 w100 hwndhEditA gOnChangeEditA vA
Gui, Add, Edit, y+2 xp wp hwndhEditB gOnChangeEditB Password
Gui, Add, Button,y+2 x6 w150 gSub Default, &Submit
Gui, Show,w162 h84,Form1
SetEditPlaceholder(hEditA,"User Name",1)
SetEditPlaceholder(hEditB,"Password",1)
return
Sub:
MsgBox, 64, Form1, Login Successful! :D
GuiClose:
ExitApp
OnChangeEditA:
EditShowBalloonTip(hEditA,"User Name","Enter your User Name here.")
return
OnChangeEditB:
EditShowBalloonTip(hEditB,"Password","Enter your Password here.")
return
~Enter::
~Tab::
ToolTip
return
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Who is online
Users browsing this forum: No registered users and 66 guests