ConsoleRectangle
Esto es el equivalente a la clase System.Drawing.Rectangle, para representar la posición y tamaño de un rectángulo (dibujable) en el búfer de salida de una consola.
Decisiones (o limitaciones) de diseño:
EDITO: implementación extendida.
Ejemplo de uso:
Esto es el equivalente a la clase System.Drawing.Rectangle, para representar la posición y tamaño de un rectángulo (dibujable) en el búfer de salida de una consola.
Decisiones (o limitaciones) de diseño:
Las propiedades son de solo lectura (para quitarme de lios). Es decir, para hacer cambios en el tamaño o posición del rectángulo, hay que crear una nueva instancia.- ya no lo son- No permite la asignación de coordenadas negativas (puesto que tampoco lo permite el método Console.SetCursorPos()), ni un tamaño (anchura ni altura) igual a cero, aunque esto último no se tiene en cuenta si se usa el constructor por defecto.
EDITO: implementación extendida.
Código [Seleccionar]
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Stores a set of four integers that represent the location and size of a (printable) rectangle on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<ComVisible(True)>
<Serializable>
Public Structure ConsoleRectangle
#Region " Properties "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the location of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The location of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public Property Location As Point
Get
Return Me.location_
End Get
Set(value As Point)
Me.UpdateLocation(value)
End Set
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' ( Backing field of <see cref="ConsoleRectangle.Location"/> property. )
''' <para></para>
''' The location of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
Private location_ As Point
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the x-coordinate of the upper-left corner of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The x-coordinate of the upper-left corner of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public ReadOnly Property X As Integer
Get
Return Me.Location.X
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the y-coordinate of the upper-left corner of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The y-coordinate of the upper-left corner of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public ReadOnly Property Y As Integer
Get
Return Me.Location.Y
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the y-coordinate of the top edge of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The y-coordinate of the top edge of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public ReadOnly Property Top As Integer
Get
Return Me.Y
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the x-coordinate of the left edge of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The x-coordinate of the left edge of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public ReadOnly Property Left As Integer
Get
Return Me.X
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the y-coordinate that is the sum of the <see cref="ConsoleRectangle.Y"/>
''' and <see cref="ConsoleRectangle.Height"/> property values of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The y-coordinate that is the sum of the <see cref="ConsoleRectangle.Y"/>
''' and <see cref="ConsoleRectangle.Height"/> property values of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public ReadOnly Property Bottom As Integer
Get
Return (Me.Y + Me.Height)
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the x-coordinate that is the sum of <see cref="ConsoleRectangle.X"/>
''' and <see cref="ConsoleRectangle.Width"/> property values of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The x-coordinate that is the sum of <see cref="ConsoleRectangle.X"/>
''' and <see cref="ConsoleRectangle.Width"/> property values of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public ReadOnly Property Right As Integer
Get
Return (Me.X + Me.Width)
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the size of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The size of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public Property Size As Size
Get
Return Me.size_
End Get
Set(value As Size)
Me.UpdateSize(value)
End Set
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' ( Backing field of <see cref="ConsoleRectangle.Size"/> property. )
''' <para></para>
''' The size of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
Private size_ As Size
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the width of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The width of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public ReadOnly Property Width As Integer
Get
Return Me.Size.Width
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets the height of this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The height of this <see cref="ConsoleRectangle"/>.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public ReadOnly Property Height As Integer
Get
Return Me.Size.Height
End Get
End Property
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the character to print the left border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The character to print the left border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public Property CharLeft As Char
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the character to print the top border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The character to print the top border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public Property CharTop As Char
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the character to print the right border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The character to print the right border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public Property CharRight As Char
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Gets or sets the character to print the bottom border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' The character to print the bottom border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(True)>
Public Property CharBottom As Char
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Tests whether all numeric properties of this System.Drawing.Rectangle have values of zero.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <value>
''' This property returns <see langword="True"/> if the
''' <see cref="ConsoleRectangle.Width"/>, <see cref="ConsoleRectangle.Height"/>,
''' <see cref="ConsoleRectangle.X"/>, and <see cref="ConsoleRectangle.Y"/> properties
''' of this <see cref="ConsoleRectangle"/> all have values of zero;
''' otherwise, <see langword="False"/>
''' </value>
''' ----------------------------------------------------------------------------------------------------
<Browsable(False)>
Public ReadOnly Property IsEmpty As Boolean
Get
Return (Me.Location = Point.Empty) AndAlso (Me.Size = Size.Empty)
End Get
End Property
#End Region
#Region " Constructors "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Initializes a new instance of the <see cref="ConsoleRectangle"/> structure.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' A <see cref="Rectangle"/> that contains the location and size for this <see cref="ConsoleRectangle"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub New(ByVal rect As Rectangle)
Me.New(rect.Location, rect.Size, "▌"c, "▀"c, "▐"c, "▄"c)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Initializes a new instance of the <see cref="ConsoleRectangle"/> structure.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' A <see cref="Rectangle"/> that contains the location and size for this <see cref="ConsoleRectangle"/>.
''' </param>
'''
''' <param name="charLeft">
''' The character to print the left border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charTop">
''' The character to print the top border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charRight">
''' The character to print the right border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charBottom">
''' The character to print the bottom border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub New(ByVal rect As Rectangle,
ByVal charLeft As Char, ByVal charTop As Char,
ByVal charRight As Char, ByVal charBottom As Char)
Me.New(rect.Location, rect.Size, charLeft, charTop, charRight, charBottom)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Initializes a new instance of the <see cref="ConsoleRectangle"/> structure.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="location">
''' The location for this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="size">
''' The size for this <see cref="ConsoleRectangle"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub New(ByVal location As Point, ByVal size As Size)
Me.New(location, size, "▌"c, "▀"c, "▐"c, "▄"c)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Initializes a new instance of the <see cref="ConsoleRectangle"/> structure.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="location">
''' The location for this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="size">
''' The size for this <see cref="ConsoleRectangle"/>.
''' </param>
'''
''' <param name="charLeft">
''' The character to print the left border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charTop">
''' The character to print the top border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charRight">
''' The character to print the right border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
'''
''' <param name="charBottom">
''' The character to print the bottom border of this <see cref="ConsoleRectangle"/> on a console output buffer.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <exception cref="ArgumentNullException">
''' </exception>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub New(ByVal location As Point, ByVal size As Size,
ByVal charLeft As Char, ByVal charTop As Char,
ByVal charRight As Char, ByVal charBottom As Char)
Me.UpdateLocation(location)
Me.UpdateSize(size)
Me.CharLeft = charLeft
Me.CharTop = charTop
Me.CharRight = charRight
Me.CharBottom = charBottom
End Sub
#End Region
#Region " Public Methods "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Writes the bounds of this <see cref="ConsoleRectangle"/> on the current console output buffer.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub Write()
For row As Integer = 0 To (Me.Height - 1)
For column As Integer = 0 To (Me.Width - 1)
If (row = 0) Then
Console.SetCursorPosition((Me.X + column), (Me.Y + row))
Console.Write(Me.CharTop)
ElseIf (row = (Me.Height - 1)) Then
Console.SetCursorPosition((Me.X + column), (Me.Y + row))
Console.Write(Me.CharBottom)
End If
Next column
Console.SetCursorPosition(Me.X, (Me.Y + row))
Console.Write(Me.CharLeft)
Console.SetCursorPosition(Me.X + (Me.Width - 1), (Me.Y + row))
Console.Write(Me.CharRight)
Next row
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Enlarges this <see cref="ConsoleRectangle"/> by the specified amount.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="width">
''' The amount to inflate this <see cref="ConsoleRectangle"/> horizontally.
''' </param>
'''
''' <param name="height">
''' The amount to inflate this <see cref="ConsoleRectangle"/> vertically.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub Inflate(ByVal width As Integer, ByVal height As Integer)
Dim rc As Rectangle = Me
rc.Inflate(width, height)
Me.Size = rc.Size
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Enlarges this <see cref="ConsoleRectangle"/> by the specified amount.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="size">
''' The amount to inflate this <see cref="ConsoleRectangle"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub Inflate(ByVal size As Size)
Me.Inflate(size.Width, size.Height)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Adjusts the location of this <see cref="ConsoleRectangle"/> by the specified amount.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="x">
''' The horizontal offset.
''' </param>
'''
''' <param name="y">
''' The vertical offset.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub Offset(ByVal x As Integer, ByVal y As Integer)
Dim rc As Rectangle = Me
rc.Offset(x, y)
Me.Location = rc.Location
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Adjusts the location of this <see cref="ConsoleRectangle"/> by the specified amount.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="location">
''' The amount to offset the location.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Sub Offset(ByVal location As Point)
Me.Offset(location.X, location.Y)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Returns a <see cref="String"/> that represents this <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' A <see cref="String"/> that represents this <see cref="ConsoleRectangle"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Overrides Function ToString() As String
If (Me.Width = 1) AndAlso (Me.Height = 1) Then
Return Me.CharLeft
ElseIf (Me.Height = 1) Then
Dim sb As New StringBuilder()
Dim lastColumnIndex As Integer = (Me.Width - 1)
For column As Integer = 0 To lastColumnIndex
Select Case column
Case 0
sb.Append(Me.CharLeft)
Case lastColumnIndex
sb.Append(Me.CharRight)
Case Else
sb.Append(Me.CharTop)
End Select
Next column
Return sb.ToString()
ElseIf (Me.Width = 1) Then
Dim sb As New StringBuilder()
For row As Integer = 0 To (Me.Height - 1)
sb.Append(Me.CharLeft)
sb.AppendLine()
Next row
Return sb.ToString()
Else
Dim sb As New StringBuilder()
Dim lastRowIndex As Integer = (Me.Height - 1)
For row As Integer = 0 To lastRowIndex
Select Case row
Case 0
sb.Append(Me.CharLeft)
sb.Append(New String(Me.CharTop, Math.Max((Me.Width - 2), 1)))
sb.Append(Me.CharRight)
Case lastRowIndex
sb.Append(Me.CharLeft)
sb.Append(New String(Me.CharBottom, Math.Max((Me.Width - 2), 1)))
sb.Append(Me.CharRight)
Case Else
sb.Append(Me.CharLeft)
sb.Append(New String(" "c, Math.Max((Me.Width - 2), 1)))
sb.Append(Me.CharRight)
End Select
sb.AppendLine()
Next row
Return sb.ToString()
End If
End Function
#End Region
#Region " Operators "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Performs an implicit conversion from <see cref="ConsoleRectangle"/> to <see cref="Rectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' The source <see cref="ConsoleRectangle"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' The resulting <see cref="Rectangle"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Widening Operator CType(ByVal rect As ConsoleRectangle) As Rectangle
Return New Rectangle(rect.Location, rect.Size)
End Operator
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Performs an implicit conversion from <see cref="Rectangle"/> to <see cref="ConsoleRectangle"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' The source <see cref="Rectangle"/>.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' The resulting <see cref="ConsoleRectangle"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Widening Operator CType(rect As Rectangle) As ConsoleRectangle
Return New ConsoleRectangle(rect)
End Operator
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Tests whether two <see cref="Rectangle"/> and <see cref="ConsoleRectangle"/> structures have equal location and size.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' The <see cref="Rectangle"/> to compare with the <see cref="ConsoleRectangle"/> structure.
''' </param>
'''
''' <param name="consoleRect">
''' The <see cref="ConsoleRectangle"/> to compare with the <see cref="Rectangle"/> structure.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' <see langword="True"/> if the two <see cref="Rectangle"/> and <see cref="ConsoleRectangle"/> structures have equal location and size;
''' otherwise, <see langword="False"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Operator =(rect As Rectangle, consoleRect As ConsoleRectangle) As Boolean
Return (rect.Location = consoleRect.Location) AndAlso (rect.Size = consoleRect.Size)
End Operator
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Determine whether two <see cref="Rectangle"/> and <see cref="ConsoleRectangle"/> structures differ in location or size.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="rect">
''' The <see cref="Rectangle"/> to compare with the <see cref="ConsoleRectangle"/> structure.
''' </param>
'''
''' <param name="consoleRect">
''' The <see cref="ConsoleRectangle"/> to compare with the <see cref="Rectangle"/> structure.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' <see langword="True"/> if the two <see cref="Rectangle"/> and <see cref="ConsoleRectangle"/> structures differ in location or size;
''' otherwise, <see langword="False"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Operator <>(rect As Rectangle, consoleRect As ConsoleRectangle) As Boolean
Return Not (rect = consoleRect)
End Operator
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Tests whether two <see cref="ConsoleRectangle"/> structures have equal location, size and characters.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="left">
''' The <see cref="ConsoleRectangle"/> structure that is to the left of the equality operator.
''' </param>
'''
''' <param name="right">
''' The <see cref="ConsoleRectangle"/> structure that is to the right of the equality operator.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' <see langword="True"/> if the two <see cref="ConsoleRectangle"/> structures have equal location, size and characters;
''' otherwise, <see langword="False"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Operator =(left As ConsoleRectangle, right As ConsoleRectangle) As Boolean
Return (left.Location = right.Location) AndAlso
(left.Size = right.Size) AndAlso
(left.CharLeft = right.CharLeft) AndAlso
(left.CharTop = right.CharTop) AndAlso
(left.CharRight = right.CharRight) AndAlso
(left.CharBottom = right.CharBottom)
End Operator
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Tests whether two <see cref="ConsoleRectangle"/> structures differ in location, size or characters.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="left">
''' The <see cref="ConsoleRectangle"/> structure that is to the left of the equality operator.
''' </param>
'''
''' <param name="right">
''' The <see cref="ConsoleRectangle"/> structure that is to the right of the equality operator.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' <see langword="True"/> if if any of the two <see cref="ConsoleRectangle"/> structures differ in location, size or characters;
''' otherwise, <see langword="False"/>.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Public Shared Operator <>(left As ConsoleRectangle, right As ConsoleRectangle) As Boolean
Return Not (left = right)
End Operator
#End Region
#Region " Private Methods "
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Updates the location value specified in <see cref="ConsoleRectangle.Location"/> property.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="newLocation">
''' The new location.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <exception cref="ArgumentException">
''' Positive value is required for coordinate.
''' </exception>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Private Sub UpdateLocation(ByVal newLocation As Point)
If (Me.location_ = newLocation) Then
Exit Sub
End If
If (newLocation.X < 0) Then
Throw New ArgumentException(paramName:=NameOf(newLocation),
message:=String.Format("Positive value is required for '{0}' coordinate.", NameOf(newLocation.X)))
ElseIf (newLocation.Y < 0) Then
Throw New ArgumentException(paramName:=NameOf(newLocation),
message:=String.Format("Positive value is required for '{0}' coordinate.", NameOf(newLocation.Y)))
End If
Me.location_ = newLocation
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Updates the size value specified in <see cref="ConsoleRectangle.Size"/> property.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="newSize">
''' The new size.
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <exception cref="ArgumentException">
''' Value greather than zero is required.
''' </exception>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepThrough>
Private Sub UpdateSize(ByVal newSize As Size)
If (Me.size_ = newSize) Then
Exit Sub
End If
If (newSize.Width <= 0) Then
Throw New ArgumentException(paramName:=NameOf(Size),
message:=String.Format("Value greather than zero is required for '{0}'", NameOf(newSize.Width)))
ElseIf (newSize.Height <= 0) Then
Throw New ArgumentException(paramName:=NameOf(Size),
message:=String.Format("Value greather than zero is required for '{0}'", NameOf(newSize.Height)))
End If
Me.size_ = newSize
End Sub
#End Region
End Structure
Ejemplo de uso:
Código [Seleccionar]
Public Module Module1
Public Sub Main()
Dim rc1Pos As New Point(2, Console.CursorTop + 2)
Dim rc1 As New ConsoleRectangle(rc1Pos, New Size(32, 4), "▌"c, "▀"c, "▐"c, "▄"c)
rc1.Write()
Dim rc2Pos As New Point(2, Console.CursorTop + 2)
Dim rc2 As New ConsoleRectangle(rc2Pos, New Size(32, 4), "X"c, "X"c, "X"c, "X"c)
rc2.Write()
Dim rc3Pos As New Point(2, Console.CursorTop + 2)
Dim rc3 As New ConsoleRectangle(rc3Pos, New Size(11, 5), "▌"c, "▀"c, "▐"c, "▄"c)
rc3.Write()
Dim rc4Pos As New Point(rc3Pos.X + (rc3.Width \ 2), rc3Pos.Y + +(rc3.Height \ 2))
Dim rc4 As New ConsoleRectangle(rc4Pos, rc3.Size, "X"c, "X"c, "X"c, "X"c)
rc4.Write()
Console.SetCursorPosition(rc1.X + 9, rc1.Y)
Console.Write(" Hello World ")
Console.SetCursorPosition(rc1.X + 6, rc1.Y + 2)
Console.Write(" By ElektroStudios ")
Console.CursorVisible = False
Console.ReadKey(intercept:=True)
End Sub
End Module