Conceptual Differences
In Visual Basic 2008, there is no equivalent for the Line control, and lightweight controls are no longer supported. However, there are ways to draw lines on a form both at design time and at run time.
| Note: |
|---|
| The optional Visual Basic Power Packs controls include LineShape, OvalShape, and RectangleShape controls that can be used to replace the Line and Shape controls. In addition to duplicating the behavior of the Visual Basic 6.0 Line and Shape controls, these controls add new capabilities. These include gradient fills, run time selection, and run time events. |
You can download the Visual Basic Power Packs from the Microsoft Visual Basic 2005 Power Packs page on the MSDN Web site.
At design time, you can
draw a vertical or
horizontal line on a form by
adding a
At run time, you can draw
vertical, horizontal, or
diagonal lines in a form's
In Visual Basic 6.0, you can use a Line control to draw a line on top of a container control such as a PictureBox or Frame control by adding a Line control to the container.
In Visual Basic 2008, you
can achieve the same effect
by calling the
Code Changes for the Line Control
Drawing Horizontal or Vertical Lines
Note: In Visual Basic 6.0, the default unit of measurement is twips; in Visual Basic 2008, it is pixels.
Copy Code
' Visual Basic 6.0 Private Sub Form_Load() ' Draw a horizontal line 200 twips from the top of the form. Line1.X1 = 0 Line1.X2 = Me.Width Line1.Y1 = 200 Line1.Y2 = 200 Line1.BorderColor = vbRed Line1.BorderWidth = 1 ' Draw a vertical line 200 twips from the left of the form. Line1.Y1 = 0 Line1.Y2 = Me.Height Line1.X1 = 200 Line1.X2 = 200 Line1.BorderColor = vbBlue Line1.BorderWidth = 1
Visual Basic Copy Code
' Visual Basic 2008 ' Using Label controls. Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim Line1 As New System.Windows.Forms.Label Dim Line2 As New System.Windows.Forms.Label ' Draw a horizontal line 14 pixels from the top of the form. Line1.Location = New System.Drawing.Point(0, 14) Line1.Size = New System.Drawing.Size(Me.Width, 1) Line1.BorderStyle = BorderStyle.None Line1.BackColor = System.Drawing.Color.Red Line1.Text = "" Controls.Add(Line1) ' Draw a vertical line 14 pixels from the left of the form. Line2.Location = New System.Drawing.Point(14, 0) Line2.Size = New System.Drawing.Size(1, Me.Height) Line2.BorderStyle = BorderStyle.None Line2.BackColor = System.Drawing.Color.Blue Line2.Text = "" Controls.Add(Line2) End Sub
Visual Basic Copy Code
' Visual Basic 2008 ' Using Graphics methods. Private Sub Form1Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a horizontal line 28 pixels from the top of the form. e.Graphics.DrawLine(Pens.Red, 0, 28, Me.Width, 28) ' Draw a vertical line 28 pixels from the left of the form. e.Graphics.DrawLine(Pens.Blue, 28, 0, 28, Me.Height) End Sub
Drawing a Diagonal Line
Note: In Visual Basic 6.0, the default unit of measurement is twips; in Visual Basic 2008, it is pixels.
Copy Code
' Visual Basic 6.0 Private Sub Form_Load() ' Draw a diagonal line from the top left to the lower right. Line1.X1 = 0 Line1.X2 = Me.ScaleWidth Line1.Y1 = 0 Line1.Y2 = Me.ScaleHeight Line1.BorderColor = vbBlack Line1.BorderWidth = 1 End Sub
Visual Basic Copy Code
' Visual Basic 2008 Private Sub FormPaint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a diagonal line from the top left to the lower right. e.Graphics.DrawLine(Pens.Black, 0, 0, Me.ClientSize.Width, _ Me.ClientSize.Height) End Sub
Upgrade Notes
You can download the Visual Basic Power Packs from the Microsoft Visual Basic 2005 Power Packs page on the MSDN Web site.
See Also
Concepts
'En 2016 obtengo esto de msd..., para WINDOWS FORMS, en
Private Sub InitializePictureBox()
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.PictureBox1.BorderStyle = _
System.Windows.Forms.BorderStyle.FixedSingle
Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Me.PictureBox1.Location = New System.Drawing.Point(72, 112)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(160, 136)
Me.PictureBox1.TabStop = False
End Sub
Private Sub InitializeOpenFileDialog()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
' Set the file dialog to filter for graphics files.
Me.OpenFileDialog1.Filter = _
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
' Allow the user to select multiple images.
Me.OpenFileDialog1.Multiselect = True
Me.OpenFileDialog1.Title = "My Image Browser"
End Sub
Private Sub fileButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles FileButton.Click
OpenFileDialog1.ShowDialog()
End Sub
' This method handles the FileOK event. It opens each file
' selected and loads the image from a stream into PictureBox1.
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles OpenFileDialog1.FileOk
Me.Activate()
Dim file, files() As String
files = OpenFileDialog1.FileNames
' Open each file and display the image in PictureBox1.
' Call Application.DoEvents to force a repaint after each
' file is read.
For Each file In files
Dim fileInfo As System.IO.FileInfo = New System.IO.FileInfo(file)
Dim fileStream As System.IO.FileStream = fileInfo.OpenRead()
PictureBox1.Image = System.Drawing.Image.FromStream(fileStream)
Application.DoEvents()
fileStream.Close()
' Call Sleep so the picture is briefly displayed,
'which will create a slide-show effect.
System.Threading.Thread.Sleep(2000)
Next
PictureBox1.Image = Nothing
End Sub
Vuelta al Principio Última actualización: sábado, 04 de junio de 2016 Visitantes: