Skip to content

WIDTH


设置或获取显示的行数和列数

语法

Width [columns] [, rows]
Width Lprint columns
Width { #filenum | devicename }, columns
result = Width( )

参数

columns

输出的列数(以字符为单位)

rows

输出的行数(以字符为单位)

filenum

要应用的文件号

devicename

要应用的设备名称

返回值

返回32位 Long,其中高字为当前设置的行数,低字为当前设置的列数。

说明

设置输出设备(控制台、打印机或文本文件)的最大字符列数。若发送到设备的文本达到宽度限制,将自动生成回车符。

Width 用作函数时,低字返回当前控制台宽度,高字返回当前高度。

若未指定设备,Width 对当前活动的控制台/图形屏幕生效,并可附加第二个参数指定最大行数。

在图形模式下,Width 通过设置允许的字符高度*宽度对来间接选择字体大小(参见 Screen (Graphics))。若 rows / cols 是无效组合,则不对屏幕显示做任何更改。

有效字体高度为8像素、14像素和16像素。字体宽度均固定为8像素。

(参见第二个示例)

在图形模式下使用 Width 命令也会强制清屏(Cls)。

示例

start GeSHi

vb
Dim As Long w
w = Width
Print "rows: " & HiWord(w)
Print "cols: " & LoWord(w)

end GeSHi

start GeSHi

vb
''Set up a graphics screen
Const W = 320, H = 200
ScreenRes W, H

Dim As Long twid
Dim As UInteger tw, th

'' Fetch and print current text width/height:
twid = Width()
tw = LoWord(twid): th = HiWord(twid)
Print "Default for current screen (8*8)"
Print "Width:  " & tw
Print "Height: " & th
Sleep

Width W\8, H\16 '' Use 8*16 font

twid = Width()
tw = LoWord(twid): th = HiWord(twid)
Print "Set to 8*16 font"
Print "Width:  " & tw
Print "Height: " & th
Sleep

Width W\8, H\14 '' Use 8*14 font

twid = Width()
tw = LoWord(twid): th = HiWord(twid)
Print "Set to 8*14 font"
Print "Width:  " & tw
Print "Height: " & th
Sleep

Width W\8, H\8 '' Use 8*8 font

twid = Width()
tw = LoWord(twid): th = HiWord(twid)
Print "Set to 8*8 font"
Print "Width:  " & tw
Print "Height: " & th
Sleep

end GeSHi

平台差异

  • 在 Windows 控制台窗口模式下,可使用任何大于 0 的值。
  • 在 DOS 或 Windows 全屏控制台模式下,有效尺寸取决于硬件能力。
  • Linux 不允许应用程序更改控制台大小。

与 QB 的差异

  • columns 仅限于 4080rows 可以为 2530435060,具体取决于图形硬件和使用的屏幕模式。

另请参阅

  • Loword
  • Hiword
  • Csrlin
  • Pos

返回 目录

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