Skip to content

COLOR


设置用于控制台输出和文本图形输出的前景色/背景色

语法

declare function Color ( byval foreground as ulong , byval background as ulong ) as ulong

用法

Color [foreground] [, background]
result = Color [( [foreground] [, background] )]

参数

foreground

要设置的前景色

background

要设置的背景色

返回值

返回一个32位值,低字包含当前前景色,高字包含当前背景色。

在高彩/真彩模式下,仅返回前景色,占用全部32位。如需返回当前图形模式颜色(前景色和背景色),请参阅 ScreenControl

新旧颜色值可在同一时间获取和设置。

说明

Color 语句设置当前前景色和/或背景色。当你不向 CircleDrawLine (Graphics)ClsPaintPrintPResetPSet 指定颜色时,它们将使用此函数最后设置的颜色(如适用)。Color 接受的颜色值取决于当前图形模式。

模式含义
1前景色为屏幕颜色(范围0-15)。背景色为要使用的模拟CGA调色板:0(绿、红、棕)、1(青、品红、白)、2(与0相同,但使用亮色)或3(与1相同,但使用亮色)
2, 11前景色为当前调色板中的颜色索引(范围0-1)。背景色为当前调色板中的颜色索引(范围0-1)。
7, 8前景色为当前调色板中的颜色索引(范围0-15)。背景色为当前调色板中的屏幕颜色索引(范围0-15)。
9前景色为当前调色板中的颜色索引(范围0-63)。背景色为当前调色板中的屏幕颜色索引(范围0-63)。
12前景色为当前调色板中的颜色索引(范围0-15)。背景色为当前调色板中的颜色索引(范围0-15)。
13及以上前景色为当前调色板中的颜色索引(范围0-255)。背景色为当前调色板中的颜色索引(范围0-255)。

如果使用超过8bpp的颜色深度,前景色和背景色为 &hAARRGGBB 格式的直接 RGB 颜色值,其中 AARRGGBB 分别为alpha、红、绿和蓝分量,范围为 &h00-&hFF(十进制0-255)。在高彩/真彩模式下,可使用 RGBRGBA 宏来获取有效颜色值。

进入 Screen (Graphics) 模式时会自动设置默认调色板

示例

start GeSHi

vb
' Sets 320x240 in 32bpp color depth
Screen 14, 32

' Sets orange foreground and dark blue background color
Color RGB(255, 128, 0), RGB(0, 0, 64)

' Clears the screen to the background color
Cls                    

' Prints "Hello World!" in the middle of the screen
Locate 15, 14
Print "Hello World!"

Sleep

end GeSHi

start GeSHi

vb
Dim c As Ulong

'retrieve current color values
c = Color()

'extract color values from c using LOWORD and HIWORD
Print "Console colors:"
Print "Foreground: " & LoWord(c)
Print "Background: " & HiWord(c)

end GeSHi

start GeSHi

vb
' In 32-bit color depth, Function Color() returns only the foreground color

#include "fbgfx.bi"

'' screencontrol expects integer/uinteger
Dim As Long fgcolor, bkcolor

ScreenRes 500, 500, 32
Width 500\8, 500\16
Color &HFFFF00, &H0000FF
Cls

Print "From Function Color():"
Print "  Foreground Color: "; Hex(Color(), 8)
Print

ScreenControl FB.GET_COLOR, fgcolor, bkcolor
Print "From Sub ScreenControl():"
Print "  Foreground Color: "; Hex(fgcolor, 8)
Print "  Background Color: "; Hex(bkcolor, 8)

Sleep

end GeSHi

与 QB 的差异

  • QB 不支持直接颜色模式。
  • 无边框参数。

另请参阅

  • RGB
  • RGBA
  • LOWORD
  • HIWORD
  • Locate
  • Palette
  • Screen (Graphics)

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系