Is there a way to change the text and the background color of an edit control?
I searched the forum and only found a way to change the background but not the text color.

Edit text and background color
Started by
Guest
, May 09 2012 07:41 AM
11 replies to this topic
#1
-
Posted 09 May 2012 - 07:41 AM

Gui Font, cRed Gui Add, Edit, vE1, Text Gui Font ; Restore previous settings Gui Add, Edit, vE2, Text Gui Show
#2
-
Posted 09 May 2012 - 09:07 AM

Hello CodeKiller,
I don't think you understood what I want, I know how to change edit text color, what I want is to change both text color and background color.
The function I found on the forum can change the background color but then it will also change the text color to black no matter what it was before.
I don't think you understood what I want, I know how to change edit text color, what I want is to change both text color and background color.
The function I found on the forum can change the background color but then it will also change the text color to black no matter what it was before.
#3
-
Posted 09 May 2012 - 10:27 AM

But actually you just need to do this, if you want a simpler GUI.
(Press F1 or F2)
(Press F1 or F2)
Gui, Add, Edit, vMyEdit w200 Center, 1234567890 Gui, Show,, My GUI #1 return F1:: Random, col, 111111, 999999 Gui, Color,, %col% return F2:: Random, col2, 111111, 999999 Gui, Font, c%col2% GuiControl, Font, MyEdit return ESC:: GuiClose: ExitApp
#5
-
Posted 09 May 2012 - 01:45 PM

The function I found on the forum can change the background color but then it will also change the text color to black no matter what it was before.
Can you post some code?.
#6
-
Posted 09 May 2012 - 01:51 PM

@tomoe_uehara,
That's amazing, I didn't know it could be so simple, so all I needed to do was
@SKAN,
Actually the only other solution I found was by you here
That works fine but only to change the background, and then it will always change the text to black.
Let me try tomoe_uehara solution for a while and see
Thanks a million tomoe_uehara
That's amazing, I didn't know it could be so simple, so all I needed to do was
Gui, Color,[color=red],[/color]< Color >It seems to change all edit controls background then.
@SKAN,
Actually the only other solution I found was by you here
That works fine but only to change the background, and then it will always change the text to black.
Let me try tomoe_uehara solution for a while and see
Thanks a million tomoe_uehara

#7
-
Posted 09 May 2012 - 04:26 PM

@SKAN,
Actually the only other solution I found was by you here
That works fine but only to change the background, and then it will always change the text to black.
Only one additional line is required:
TextBackgroundColor := 0xD8D0A7 ; A custom color in BGR format. TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor) Gui, Add, Edit, w320 h240 HwndMyTextHwnd, Here is some text that is given`na custom background color. Gui +LastFound GuiHwnd := WinExist() WindowProcNew := RegisterCallback("WindowProc", "" ; "" to avoid fast-mode for subclassing. , 4, MyTextHwnd) ; Must specify exact ParamCount when EventInfo parameter is present. WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd, Int, -4 ; -4 is GWL_WNDPROC , Int, WindowProcNew, UInt) ; Return value must be set to UInt vs. Int. Gui Show return WindowProc(hwnd, uMsg, wParam, lParam) { Critical global TextBackgroundColor, TextBackgroundBrush, WindowProcOld if (uMsg = 0x133 && lParam = A_EventInfo) ; WM_CTLCOLOREDIT = 0x133 { [color=#FF0040]DllCall("SetTextColor", UInt, wParam, UInt,0x0000FF )[/color] DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor ) return TextBackgroundBrush ; Return the HBRUSH to notify the OS that we altered the HDC. } ; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc. return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam) } GuiClose: ExitApp
#8
-
Posted 09 May 2012 - 05:21 PM

Nice SKAN,
But I need a way to change colors for both text and background on demand later after I show the gui, I'm not sure how to achieve that using your function
Could you please demonstrate that?
But I need a way to change colors for both text and background on demand later after I show the gui, I'm not sure how to achieve that using your function

Could you please demonstrate that?
#9
-
Posted 09 May 2012 - 07:28 PM

#10
-
Posted 09 May 2012 - 07:51 PM

Prefer ahkscript.org for the time being.
I think just me wanted to show this topic :
<!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=13&t=77715">viewtopic.php?f=13&t=77715</a><!-- l -->
<!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=13&t=77715">viewtopic.php?f=13&t=77715</a><!-- l -->
#12
-
Posted 10 May 2012 - 07:25 AM
