Integrated Application Platform › Forums › General › Change background color of Editor Control › Re: Re: Change background color of Editor Control
March 6, 2013 at 6:15 pm
#969
Participant
Yes, I have modified EditControl in this way:
in the New method you must replace:
New(mandatory = false, readonly = false, style = 0, bgndcolor = "",
textcolor = "", hidden = false, tabover = false)
{
...
...
if Object?(bgndcolor)
bgndcolor = RGB(bgndcolor[0], bgndcolor[1], bgndcolor[2])
.SetBgndColor(bgndcolor)
if Object?(textcolor)
textcolor = RGB(textcolor[0], textcolor[1], textcolor[2])
.textcolor = textcolor
}
with this:
New(mandatory = false, readonly = false, style = 0, hidden = false, tabover = false
bgndcolor = "", textcolor = "", bgndcolor_readonly = "", textcolor_readonly = "")
{
...
...
if Object?(bgndcolor)
bgndcolor = RGB(bgndcolor[0], bgndcolor[1], bgndcolor[2])
.SetBgndColor(bgndcolor)
if Object?(bgndcolor_readonly)
bgndcolor_readonly = RGB(bgndcolor_readonly[0], bgndcolor_readonly[1], bgndcolor_readonly[2])
if (bgndcolor_readonly == "")
.SetReadOnlyBgndColor(RGB(240, 240, 240))
else
.SetReadOnlyBgndColor(bgndcolor_readonly)
if Object?(textcolor)
textcolor = RGB(textcolor[0], textcolor[1], textcolor[2])
.textcolor = textcolor
if Object?(textcolor_readonly)
textcolor_readonly = RGB(textcolor_readonly[0], textcolor_readonly[1], textcolor_readonly[2])
.textcolor_readonly = textcolor_readonly
}
Then you have to add these methods:
SetReadOnlyBgndColor(color)
{
.bgndcolor_readonly = color is "" ? RGB(240, 240, 240) : color
.bgndbrush_readonly = color is "" ? GetStockObject(SO.WHITE_BRUSH) : CreateSolidBrush(color)
.color_readonly = .bgndcolor_readonly
.brush_readonly = .bgndbrush_readonly
.Repaint()
}
CTLCOLORSTATIC(wParam) //this is for the readonly case
{
if .textcolor_readonly isnt ""
SetTextColor(wParam, .textcolor_readonly)
SetBkColor(wParam, .color_readonly)
return .brush_readonly
}
With these mods, you can do something like:
w1 = Window(#(Vert (Editor font: “Verdana” size: 16 readonly: false)))
w1.Vert.Editor.Set(“Hello”)
w1.Vert.Editor.SetBgndColor(RGB(255,0,0))
w1.Vert.Editor.SetReadOnlyBgndColor(RGB(0,255,0))
w1.Vert.Editor.SetReadOnly(true) // <-- this will make the editor readonly and the background green w1.Vert.Editor.SetReadOnly(false) // <-- this will make the editor editable and the background red