Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Los siguientes ejemplos de cdigo muestran las diferencias entre las tcnicas de codificacin de Visual Basic 6.0 y Visual Basic 2008.
Nota:
En Visual Basic 6.0, la unidad de medida predeterminada son los twips; en Visual Basic 2008 son los pxeles
' Visual Basic 6.0 Private Sub Form_Paint() ' Draw a solid black line 200 twips from the top of the form. Line (0, 200) - (ScaleWidth, 200), vbBlack End Sub VB ' Visual Basic Private Sub Form1_Paint(ByVal sender As Object, ByVal e _ As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a solid black line 25 pixels from the top of the form. e.Graphics.DrawLine(Pens.Black, 0, 25, Me.Width, 25) End Sub
Nota:
En Visual Basic 6.0, la unidad de medida predeterminada son los twips; en Visual Basic 2008 son los pxeles
' Visual Basic 6.0 Private Sub Form_Paint() ' Draw a dotted line 200 twips from the top of the form. Me.DrawStyle = vbDot Line (0, 200) - (ScaleWidth, 200), vbBlack
End Sub VB ' Visual Basic Private Sub Form1_Paint1(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a dotted black line 25 pixels from the top of the form. Dim LPen As New System.Drawing.Pen(System.Drawing.Color.Black) LPen.DashStyle = Drawing2D.DashStyle.Dot e.Graphics.DrawLine(LPen, 0, 25, Me.Width, 25) End Sub
Dibujar un crculo
El cdigo siguiente muestra el dibujo de un crculo en un formulario en tiempo de ejecucin. En el ejemplo de Visual Basic 6.0, se utiliza el mtodo Circle; acepta las coordenadas X e Y del punto central, el radio y, opcionalmente, un color como argumentos. El ejemplo de Visual Basic 2008 utiliza el mtodo DrawEllipse que acepta un objeto Pen, las coordenadas X e Y del ngulo superior izquierdo del rectngulo delimitador, el ancho y el alto como argumentos.
Nota:
En Visual Basic 6.0, la unidad de medida predeterminada son los twips; en Visual Basic 2008 son los pxeles
' Visual Basic 6.0 Private Sub Form_Paint() ' Draw a 1000 twip diameter red circle Circle (500, 500), 500, vbRed End Sub VB ' Visual Basic Private Sub Form1_Paint3(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a 70 pixel diameter red circle. e.Graphics.DrawEllipse(Pens.Red, 0, 0, 70, 70) End Sub
Nota:
En Visual Basic 6.0, la unidad de medida predeterminada son los twips; en Visual Basic 2008 son los pxeles
' Visual Basic 6.0 Private Sub Form_Paint() ' Draw a solid red rectangle. FillColor = vbRed FillStyle = vbSolid Line (10, 10)- (1000, 500), vbRed, B ' Draw a rectangle filled with a crosshatch pattern. FillColor = vbBlack FillStyle = vbCross
Line (10, 500)- (1000, 1000), vbBlack, B End Sub VB ' Visual Basic Private Sub Form1_Paint4(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a solid red rectangle. Dim SBrush As New System.Drawing.SolidBrush _ (System.Drawing.Color.Red) e.Graphics.DrawRectangle(Pens.Red, 2, 2, 70, 40) e.Graphics.FillRectangle(SBrush, 2, 2, 70, 40) ' Draw a rectangle filled with a crosshatch pattern. Dim HBrush As New System.Drawing.Drawing2D.HatchBrush( _ System.Drawing.Drawing2D.HatchStyle.Cross, _ System.Drawing.Color.Black, System.Drawing.Color.Transparent) e.Graphics.DrawRectangle(Pens.Black, 2, 40, 70, 40) e.Graphics.FillRectangle(HBrush, 2, 40, 70, 40) End Sub
El cdigo siguiente indica los mtodos de grficos para mostrar una cadena de texto en un formulario en tiempo de ejecucin. El ejemplo de Visual Basic 6.0 utiliza el mtodo Print. El ejemplo de Visual Basic 2008 utiliza el mtodo DrawString. ' Visual Basic 6.0 Private Sub Form_Paint() Me.Font.Size = 24 Me.Font.Bold = True Me.ForeColor = vbRed Print "Hello World!" End Sub VB ' Visual Basic Private Sub Form1_Paint6(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim TextFont As New System.Drawing.Font("Arial", 24, FontStyle.Bold) Dim TextBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red) e.Graphics.DrawString("Hello World!", TextFont, TextBrush, 10, 10) TextFont.Dispose() TextBrush.Dispose() End Sub
TextSize = e.Graphics.MeasureString("Hello World!", TextFont) e.Graphics.DrawRectangle(Pens.Black, 10, 10, TextSize.Width, TextSize.Height) TextFont.Dispose() TextBrush.Dispose() End Sub
Nota:
En Visual Basic 6.0, la unidad de medida predeterminada son los twips; en Visual Basic 2008 son los pxeles
' Visual Basic 6.0 Private Sub Form_Paint() Dim PixelColor As Long Picture1.Picture = LoadPicture("C:\Windows\Greenstone.bmp") PixelColor = Picture1.Point(10, 10) FillColor = PixelColor Line (0, 0)-(100, 500), PixelColor, B End Sub
VB ' Visual Basic Private Sub Form1_Paint9(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim Pict1 As New Bitmap("C:\Windows\Greenstone.bmp") Picture1.Image = Pict1 Dim PixelColor As Color = Pict1.GetPixel(4, 4) Dim PixelBrush As New SolidBrush(PixelColor) e.Graphics.FillRectangle(PixelBrush, 0, 0, 100, 100) End Sub