Integrated Application Platform › Forums › General › Change background color of Editor Control
- This topic has 4 replies, 3 voices, and was last updated 10 years ago by
gmauro.
-
AuthorPosts
-
March 2, 2013 at 11:47 am #747
mauro-g
ParticipantHi, there is a way to change the background color of an EditorControl ?
For example:w1 = Window(#(Vert (Editor font: “Verdana” size: 16 readonly:true)))
w1.Vert.Editor.Set(“Hello”)Could I change the usual gray color of the background read-only window?
March 4, 2013 at 3:20 pm #966j_ferguson
ModeratorYes, there is a method for EditorControl to do that, but when readonly, it looks like the gray color overrides any background color that you set, so it only seems to work when the readonly option is turned off.
// works with the readonly option commented
w1 = Window(Object(‘Vert’ Object(‘Editor’ font: “Verdana” size: 16 /*readonly:true*/)))
w1.Vert.Editor.Set(“Hello”)
w1.Vert.Editor.SetBgndColor(RGB(50,50,255))March 6, 2013 at 12:59 pm #967gmauro
ParticipantThank you! After some research I discovered that if you catch the CTLCOLORSTATIC message, you can change the readonly background color too!
So, if you add something like this to the EditControl:
CTLCOLORSTATIC(wParam)
{
if .textcolor isnt ""
SetTextColor(wParam, .textcolor)
SetBkColor(wParam, .color)
return .brush
}SetBgndColor(…) will change the background even if the control is read-only! 🙂
Now my problem is that if you use that code, then the readonly background color will always be the same of the not-readonly window…
March 6, 2013 at 3:22 pm #968j_ferguson
ModeratorI suppose you could add a method SetReadOnlyBgndColor to EditControl that would behave similarly to SetBgndColor except its color and brush would be used in the CTLCOLORSTATIC message. Then you could have different colors for both states.
March 6, 2013 at 6:15 pm #969gmauro
ParticipantYes, 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
-
AuthorPosts
- You must be logged in to reply to this topic.