本文整理汇总了VB.NET中System.Console.SetBufferSize方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.SetBufferSize方法的具体用法?VB.NET Console.SetBufferSize怎么用?VB.NET Console.SetBufferSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Console 的用法示例。
在下文中一共展示了Console.SetBufferSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' This example demonstrates the Console.WindowLeft and
' Console.WindowTop properties.
Imports System.IO
Imports System.Text
Class Sample
Public Shared saveBufferWidth As Integer
Public Shared saveBufferHeight As Integer
Public Shared saveWindowHeight As Integer
Public Shared saveWindowWidth As Integer
Public Shared saveCursorVisible As Boolean
Public Shared Sub Main()
Dim m1 As String = _
"1) Press the cursor keys to move the console window." & vbCrlf & _
"2) Press any key to begin. When you're finished..." & vbCrlf & _
"3) Press the Escape key to quit."
Dim g1 As String = "+----"
Dim g2 As String = "| "
Dim grid1 As String
Dim grid2 As String
Dim sbG1 As New StringBuilder()
Dim sbG2 As New StringBuilder()
Dim cki As ConsoleKeyInfo
Dim y As Integer
'
Try
saveBufferWidth = Console.BufferWidth
saveBufferHeight = Console.BufferHeight
saveWindowHeight = Console.WindowHeight
saveWindowWidth = Console.WindowWidth
saveCursorVisible = Console.CursorVisible
'
Console.Clear()
Console.WriteLine(m1)
Console.ReadKey(True)
' Set the smallest possible window size before setting the buffer size.
Console.SetWindowSize(1, 1)
Console.SetBufferSize(80, 80)
Console.SetWindowSize(40, 20)
' Create grid lines to fit the buffer. (The buffer width is 80, but
' this same technique could be used with an arbitrary buffer width.)
For y = 0 To (Console.BufferWidth / g1.Length) - 1
sbG1.Append(g1)
sbG2.Append(g2)
Next y
sbG1.Append(g1, 0, Console.BufferWidth Mod g1.Length)
sbG2.Append(g2, 0, Console.BufferWidth Mod g2.Length)
grid1 = sbG1.ToString()
grid2 = sbG2.ToString()
Console.CursorVisible = False
Console.Clear()
For y = 0 To (Console.BufferHeight - 2)
If y Mod 3 = 0 Then
Console.Write(grid1)
Else
Console.Write(grid2)
End If
Next y
'
Console.SetWindowPosition(0, 0)
Do
cki = Console.ReadKey(True)
Select Case cki.Key
Case ConsoleKey.LeftArrow
If Console.WindowLeft > 0 Then
Console.SetWindowPosition(Console.WindowLeft - 1, Console.WindowTop)
End If
Case ConsoleKey.UpArrow
If Console.WindowTop > 0 Then
Console.SetWindowPosition(Console.WindowLeft, Console.WindowTop - 1)
End If
Case ConsoleKey.RightArrow
If Console.WindowLeft < Console.BufferWidth - Console.WindowWidth Then
Console.SetWindowPosition(Console.WindowLeft + 1, Console.WindowTop)
End If
Case ConsoleKey.DownArrow
If Console.WindowTop < Console.BufferHeight - Console.WindowHeight Then
Console.SetWindowPosition(Console.WindowLeft, Console.WindowTop + 1)
End If
End Select
Loop While cki.Key <> ConsoleKey.Escape
' end do-while
' end try
Catch e As IOException
Console.WriteLine(e.Message)
Finally
Console.Clear()
Console.SetWindowSize(1, 1)
Console.SetBufferSize(saveBufferWidth, saveBufferHeight)
Console.SetWindowSize(saveWindowWidth, saveWindowHeight)
Console.CursorVisible = saveCursorVisible
End Try
End Sub
End Class
'
'This example produces results similar to the following:
'
'1) Press the cursor keys to move the console window.
'2) Press any key to begin. When you're finished...
'3) Press the Escape key to quit.
'
'...
'
'+----+----+----+-
'| | | |
'| | | |
'+----+----+----+-
'| | | |
'| | | |
'+----+----+----+-
'
开发者ID:VB.NET开发者,项目名称:System,代码行数:115,代码来源:Console.SetBufferSize
注:本文中的System.Console.SetBufferSize方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论