Skip to content

CLS


在文本模式和图形模式下清除屏幕

语法

declare sub Cls ( byval mode as long = 1 )

用法

Cls mode

参数

mode

可选数值变量,取值范围为 02。若省略,默认为 1

说明

可以提供可选的 mode 参数。

若省略,CLS 将清除文本或图形视口。如果使用 View (Graphics) 语句定义了图形视口,则清除图形视口。否则,清除由 View Print 定义的文本视口。(若未明确定义文本视口,则清除整个屏幕。)

若为 0,清除整个屏幕

若为 1,若已定义图形视口则清除图形视口,否则清除文本视口

若为 2,清除文本视口

示例

start GeSHi

vb
'' set the color to light grey text on a blue background
Color 7, 1

'' clear the screen to the background color
Cls

'' print text in the center of the screen
Locate 12, 33
Print "Hello Universe!"

end GeSHi

在图形模式下,如果要将整个屏幕清除为颜色 0,使用 Clear 向屏幕内存写入零可能比调用 CLS 更快。

start GeSHi

vb
Dim scrbuf As Byte Ptr, scrsize As Integer
Dim As Long scrhei, scrpitch
Dim As Integer r = 0, dr = 1

ScreenRes 640, 480, 8

scrbuf = ScreenPtr: Assert( scrbuf <> 0 )
ScreenInfo( , scrhei, , , scrpitch )
scrsize = scrpitch * scrhei

Do
   
    '' lock the screen (must do this while working directly on screenbuffer)
    ScreenLock
       
        '' clear the screen (could use Cls here):
        Clear *scrbuf, 0, scrsize
       
        '' draw circle
        Circle (320, 240), r
       
    ScreenUnlock
   
    '' grow/shrink circle radius
    r += dr
    If r `<= 0 Then dr = 1 Else If r >`= 100 Then dr = -1
   
    '' short pause in each frame (prevents hogging the CPU)
    Sleep 1, 1
   
    '' run loop until user presses a key
Loop Until Len(Inkey) > 0

end GeSHi

与 QB 的差异

另请参阅

  • Color
  • Locate
  • Print
  • ?
  • View (Graphics)

返回 目录

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