none
Desenhando no PictureBox RRS feed

  • Pergunta

  • Estou tentando desenhar um gráfico ou escrever algo no PictureBox mas não consigo fazendo desta forma:

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim fonte As New Font("Arial", 10)
    
            Dim po As New PointF(0, 10)
    
            PictureBox1.CreateGraphics.DrawString("a", fonte, Brushes.Black, po)
        End Sub

    Estou fazendo algo errado? 

    quarta-feira, 25 de julho de 2012 23:09

Respostas

  • Isso te ajudará:

    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.Windows.Forms
    
    Public Class Form4
        Inherits System.Windows.Forms.Form
    
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            Dim blueBrush As New SolidBrush(Color.Blue)
            Dim redBrush As New SolidBrush(Color.Red)
            Dim greenBrush As New SolidBrush(Color.Green)
            ' Create a rectangle
            Dim rect As New Rectangle(20, 20, 200, 100)
            ' The text to be drawn
            Dim drawString As [String] = "Hello GDI+ World!"
            ' Create a Font
            Dim drawFont As New Font("Verdana", 14)
            Dim x As Single = 100.0F
            Dim y As Single = 100.0F
            ' String format
            Dim drawFormat As New StringFormat
            ' Set string format flag to direction vertical
            ' which draws text vertical
            drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
            ' Draw string
            e.Graphics.DrawString("Drawing text", New Font("Tahoma", 14), greenBrush, rect.Location.X, rect.Location.Y)
            e.Graphics.DrawString(drawString, New Font("Arial", 12), redBrush, 120, 140)
            e.Graphics.DrawString(drawString, drawFont, blueBrush, x, y, drawFormat)
            ' Dispose
            blueBrush.Dispose()
            redBrush.Dispose()
            greenBrush.Dispose()
            drawFont.Dispose()
        End Sub
    
        Private Sub Form4_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load        
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)        
            Me.ClientSize = New System.Drawing.Size(292, 273)
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        End Sub
    End Class

    http://www.java2s.com/Tutorial/VB/0300__2D-Graphics/GraphicsDrawString.htm

    quinta-feira, 26 de julho de 2012 12:30