Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Color of Edit and Text
#1
okay i would like to know how to do 2 things

1.make the edit a color(just like where you type make that a color)

2.make where you type in an edit the text a color

I would really appreciate if anyone could help

Thanks
#2
Function Dialog_edit_colors
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
e3="red text"
if(!ShowDialog("Dialog_edit_colors" &Dialog_edit_colors &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 145 99 "Form"
;1 Button 0x54030001 0x4 4 82 48 14 "OK"
;2 Button 0x54030000 0x4 56 82 48 14 "Cancel"
;3 Edit 0x54030080 0x204 8 38 128 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010601 "*" ""

ret
;messages
int textcolor=0xff
int backcolor=0x00ff00
int-- hbrush

sel message
,case WM_INITDIALOG
,hbrush=CreateSolidBrush(backcolor)
,
,ret 1
,case WM_DESTROY
,DeleteObject hbrush
,
,case WM_COMMAND goto messages2
,
,case WM_CTLCOLOREDIT
,if(lParam=id(3 hDlg))
,,SetTextColor wParam textcolor ;;text
,,SetBkMode wParam TRANSPARENT
,,ret hbrush ;;background
,;Similarly, you can use other WM_CTLCOLORx messages for other control classes and dialog itself.
,
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

another example
Function Dialog_font_sample
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;Shows how to set fonts and colors.

str controls = "6 3"
str lb6 e3
e3="Text"
lb6="item1[]item2"
if(!ShowDialog("Dialog_font_sample" &Dialog_font_sample &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 173 99 "Dialog Fonts"
;4 Static 0x54000000 0x4 10 22 48 14 "Text"
;6 ListBox 0x54230101 0x200 104 20 60 34 ""
;3 Edit 0x54030080 0x204 10 38 82 16 ""
;1 Button 0x54030001 0x4 4 82 48 14 "OK"
;2 Button 0x54030000 0x4 56 82 48 14 "Cancel"
;5 Button 0x54020007 0x4 4 6 166 54 "Text"
;END DIALOG
;DIALOG EDITOR: "" 0x2020103 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,__Font-- f
,f.Create("Courier New" 14 1)
,f.SetDialogFont(hDlg "3-5")
,f.SetDialogFontColor(hDlg 0xff0000 "3 4")
,
,__Font-- f2
,f2.Create("Comic Sans MS" 7 2)
,f2.SetDialogFont(hDlg "2")
,
,__Font-- f3
,f.SetDialogFontColor(hDlg 0x008000 "6")
,
,;note: __Font variables must not be local because they must exist while the dialog is open.
,;note: in a dialog, use different __Font variables for different fonts.

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
Thanks Gin

the first one with color edits works perfectly

but in the second one it errors on the first __Font--

it says unknown identifier

could you please fix it or tell me what to change?

should it be an int?

Thanks again bro
#4
okay im trying to make one with multiple color edits
this is the code
but only the first one works
do you think you could please fix the code
thanks

\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4 8 9"
str e3 e4 si8 si9
si8="$qm$\findhtm.ico"
si9="$qm$\findhtm.ico"
if(!ShowDialog("TEST_COLOR" &TEST_COLOR &controls)) ret

BEGIN DIALOG
0 "" 0x90C80A44 0x100 0 0 169 95 "Logginer"
2 Button 0x54030000 0x4 114 70 48 14 "Close"
3 Edit 0x54030080 0x200 46 16 116 14 ""
4 Edit 0x54030080 0x200 46 44 116 14 ""
5 Static 0x54000000 0x0 32 18 48 12 "ID"
6 Static 0x54000000 0x0 12 46 48 12 "Password"
7 Static 0x54000000 0x0 20 72 74 10 "THIS IS A TEST"
8 Static 0x54000003 0x0 6 70 16 16 ""
9 Static 0x54000003 0x0 94 70 16 16 ""
END DIALOG
DIALOG EDITOR: "" 0x2020105 "" ""

ret
messages
int textcolor=0xFF
int background=0xF
int-- jbrush
if(message=WM_INITDIALOG) DT_Init(hDlg lParam)
int param=DT_GetParam(hDlg)

sel message
,case WM_INITDIALOG
,jbrush=CreateSolidBrush(background)
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2

,case WM_CTLCOLOREDIT
,if(lParam=id(3 hDlg))
,,SetTextColor wParam textcolor
,,SetBkMode wParam TRANSPARENT
,,ret jbrush

,case WM_CTLCOLOREDIT
,if(lParam=id(4 hDlg))
,,SetTextColor wParam textcolor
,,SetBkMode wParam TRANSPARENT
,,ret jbrush


ret
messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
#5
don't need two "case WM_CTLCOLOREDIT". Just remove the second.

__Font has been added in some of recent QM versions. Your older QM version does not know what it is.
#6
Thanks bro that worked perfectly

is there a way to just make the text color change and not even mess with the back ground

for example not even having the create brush or anything

Thanks
#7
Not sure is it the best way but works. Replace

ret jbrush

to

ret COLOR_WINDOW+1

And remove all code where is used jbrush.
#8
Is there a way to make this work dynamically? For example, if I click on a box, have it turn colored, but when I click on a second box, have the first box turn white again, and the second box turn colored?
#9
replace

if(lParam=id(3 hDlg))

to

if(lParam=GetFocus)
#10
When I have an colored background in an editfield, the text within that editfield becomes unreadable when it is being modified.

Example, put cursor somewhere within the asterisk and edit/modify the text.

Function tst_backgr
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 32 19 152 87 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "3"
str e3="AAAA***AAAA"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
int textcolor=0x000000
int backcolor=0x00ffff
int-- hbrush
sel message
,case WM_INITDIALOG
,,hbrush=CreateSolidBrush(backcolor)
,case WM_DESTROY
,case WM_DESTROY
,,DeleteObject hbrush
,case WM_CTLCOLOREDIT
,,if(lParam=id(3 hDlg))
,,,SetTextColor wParam textcolor ;;text
,,,SetBkMode wParam TRANSPARENT
,,,ret hbrush ;;background
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

EDIT:
Is there a redraw that must be done to avoid unreadable text?
#11
It seems multiline Edit controls don't redraw.
Replace

SetBkMode wParam TRANSPARENT

with

SetBkColor wParam backcolor
#12
Thank you! It works!


Forum Jump:


Users browsing this thread: 2 Guest(s)