Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

custom background color for Text controls?


  • Please log in to reply
17 replies to this topic
Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Hey guys,

quick and simple: How can I set the background color for a Text control (Gui, Add, Text)?
Here's my code:
Gui, Add, Text, Border vInfoBox
		, Press START button to begin. ; DEBUG: background color "FFFFE1"!?
Oh, and while we're at it, is there a way to directly edit the font weight for a text box - i.e. other than this:
Gui, Font, w700 ; bold
	Gui, Add, Text, Center, Info
	Gui, Font, w400 ; normal

Sorry for those newbie questions, but I hardly ever worked with GUIs before in AHK, and the documentation on this is quite confusing sometimes (damn, that was a lot easier in VB/VBA :O )...

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Ace_NoOne, :)

How can I set the background color for a Text control


I am also interested in a solution.. It has not been possible for me till date.

is there a way to directly edit the font weight for a text box


Gui, Font, s10 Bold
Gui, Add, Text, Center, Info
Gui, Font, s10 Normal

The above is the only way as far as I know.

Regards, :)
kWo4Lk1.png

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
<!-- m -->http://www.autohotke... ... lor colour<!-- m -->
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Yeah, I'd seen that thread - but it kinda confused me more than it helped.
So there's no solution for this yet?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
In short, no.
A possible workaround is to use transparent text over a Picture, if you don't mind using an external file. (Until I manage to use in-memory resources...)
Gui Font, s36 Bold
Gui Add, Picture, x20 y20 w10 h10 vpic, images\bluepixel.bmp
Gui Add, Text, x20 y20 BackgroundTrans, Text over blue background!

GuiControlGet t, Pos
GuiControl Move, pic, w%tw% h%th%
Gui Show, w700 h120
Return

GuiClose:
GuiEscape:
ExitApp

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Inspired by Goyyah's topic on gradients, I made a small improvement:
Gui Font, s24 Bold
Gui Add, Picture, x20 y20 w10 h10 vpic1, bluepixel.bmp
Gui Add, Picture, x20 y60 w10 h10 vpic2, 2pixelsH.bmp
Gui Add, Picture, x20 y100 w10 h10 vpic3, 2pixelsV.bmp
Gui Add, Picture, x20 y140 w10 h10 vpic4, 4pixels.bmp
Gui Add, Text, x20 y20 BackgroundTrans vt1, Text over blue background!
Gui Add, Text, x20 y60 BackgroundTrans vt2, Text over horizontal gradient background!
Gui Add, Text, x20 y100 BackgroundTrans vt3, Text over vertical gradient background!
Gui Add, Text, x20 y140 BackgroundTrans vt4, Text over complex gradient background!

Loop 4
{
	GuiControlGet t, Pos, t%A_Index%
	GuiControl Move, pic%A_Index%, w%tw% h%th%
}
Gui Show, w700 h200
Return

GuiClose:
GuiEscape:
ExitApp
bluepixel.bmp
2pixelsH.bmp
2pixelsV.bmp
4pixels.bmp
Posted Image
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
That's a good workaround, though I'm kinda hesitant to work in such an "unclean" way (don't worry, you don't have to understand my mindset here... ;) ).

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
I just read through the documentation again - there it says:

Sets the background color of the window and/or its controls. [...] ControlColor is applied to all present and future controls in the window

Sound like that's exactly what I wanted - but I still couldn't get it to work...

Oh, by the way: When creating a Text control with the Border option, the control's text will be very close o that border - isn't there a way to add some padding (inner spacing between border and contents)?

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Sound like that's exactly what I wanted - but I still couldn't get it to work...

I think this is what it means:
Gui, Color, Fuchsia
Gui, Font, s20
Gui, Add, Text, cWhite, Some text here...
Gui, Show
Return
GuiEscape:
GuiClose:
ExitApp

I couldn't find a style that gives the control extra padding... if only designing GUIs were as easy as web pages with CSS lol.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005

I think this is what it means:
[...]

Well, you demonstrated how to change the window's background color with the first parameter (WindowColor) - but the second one explicitly says ControlColor!?!

if only designing GUIs were as easy as web pages with CSS

*hint* *hint* *nudge* *nudge* - Chris, my Lord, the people demand a revolution... ;)
Oh, and while we're at it; I wanna be able access controls like in Visual Basic, i.e. GuiWindow.Frame.Control.Property! (Is that object-oriented? :oops: Anyways, creating GUIs in VB is really easy... ) :p

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
[quote name="Titan"]if only designing GUIs were as easy as web pages with CSS lol.[/quote]XAML! Probably the future in Microsoft's way of designing GUI interfaces.
[quote name="Ace_NoOne]Well, you demonstrated how to change the window's background color with the first parameter (WindowColor) - but the second one explicitly says ControlColor!?! [/quote]You truncated the quote. The full sentence is: [quote="AHK's Manual"]Sets the background color of the window and/or its controls. WindowColor is used as the background for the parent window. ControlColor is applied to all present and future controls in the window [quote="AHK's Manual"](with the exception of a few types that do not support a custom color)[/quote].[/quote]Guess what kind of control cannot be changed...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Well, you demonstrated how to change the window's background color with the first parameter (WindowColor) - but the second one explicitly says ControlColor!?!

Oh soz, didn't realize.

Oh, and while we're at it; I wanna be able access controls like in Visual Basic, i.e. GuiWindow.Frame.Control.Property! (Is that object-oriented? :oops: Anyways, creating GUIs in VB is really easy... ) :p

That's because there are programs like MS Visual Studio (Express) and others that offer fancy IDE apps for Basic. Adding controls in AutoHotkey is extremely easy - it's just that it's not so flexible in terms of events, styles and properties. I agree with you, it would be nice to access all sorts of properties for controls but that would be such a huge burden on Chris and might make compiled scripts larger. I think what we got now is fine.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

XAML!

That's interesting but I don't see how it relates to or can be used with AutoHotkey?

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
You mentioned designing GUIs as Web pages, XAML allows to design GUIs in XML, in a graphical way (more SVG than HTML actually). I can't recall if it used CSS, but well, that's the point.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012
This might be a helpful

Gui, Add, Text, [color=#FF0000]0x6[/color] w100,
Gui, Add, Text, xp0 yp0 +BackgroundTrans, This is a test
Gui, Add, Text, [color=#FF00FF]0x5[/color] w100,
Gui, Add, Text, xp0 yp0 +BackgroundTrans, This is a test
Gui, Add, Text, [color=#0000BF]0x4[/color] w100,
Gui, Add, Text, xp0 yp0 +BackgroundTrans, This is a test
Gui, Show

Just use Text styles

SS_BLACKRECT
0x4
Specifies a rectangle filled with the current window frame color. This color is black in the default color scheme.

SS_GRAYRECT
0x5
Specifies a rectangle filled with the current screen background color. This color is gray in the default color scheme.

SS_WHITERECT
0x6
Specifies a rectangle filled with the current window background color. This color is white in the default color scheme.


If someone could find a way to change those colors.

Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.