Label an Picturebox anpassen

Also, in VB müsste das ganze ja eig. so aussehen, oder?

Code:
Private Sub pictureBox1_Paint(object sender, EventArgs e)
    Dim sf As StringFormat()
    sf.LineAlignment = StringAlignment.Center;
    sf.Alignment = StringAlignment.Center;
    e.Graphics.DrawString("mein Text", SystemFonts.DefaultFont, SystemBrushes.WindowText, pictureBox1.Bounds, sf);
End Sub
 
Glaube schon allerdings fehlt glaube noch ein new
Code:
    Dim sf As New StringFormat()
Na so halt ungefähr :D
Damit das Objekt instanziiert wird.
Und disposen muss man das ganze noch.

Spyke (www.iv-interactive.de)
 
Stimmt, des New hab ich vergessen, sorry :D

Warum ist der Code eigentlich in nem Eventhandler? Er will das Ganze doch zu Beginn zeichnen, oder? Dann gehörts eigentlich in den Konstruktor.

lg
 
hi

Bei mir zeigt der trozdem fehler an (Siehe anhang) wo ich nicht weis wie ich die wegbekomme
hauptsächlich object und e.
 

Anhänge

  • Fehler.JPG
    Fehler.JPG
    20,9 KB · Aufrufe: 18
Zuletzt bearbeitet:
Warum ist der Code eigentlich in nem Eventhandler? Er will das Ganze doch zu Beginn zeichnen, oder? Dann gehörts eigentlich in den Konstruktor.
Damit der Text gezeichnet wird wenn die Zeichnen Aufforderung vom System kommt :D

@hary die Semikolons müssen bei VB glaube weg und object glaube groß schreiben, also Object.

Edit:
und nicht EventArgs sondern PaintEventArgs müsste es sein, einfach mal die Hilfe zum Paint Ereignis anschaun.

Spyke (www.iv-interactive.de)
 
hi
Ich hab nochmal etwas rumprobiert habs hinbekommen das mir keine fehler mehr gezeigt werden aber leider auch der text nicht was hab ich falschgemacht ?


PHP:
    Private Sub PictureBox1_paint(ByVal sender As System.Object, ByVal e As PaintEventArgs)
        Dim sf As New StringFormat()
        sf.LineAlignment = StringAlignment.Center
        sf.Alignment = StringAlignment.Center
        e.Graphics.DrawString("mein Text", SystemFonts.DefaultFont, SystemBrushes.WindowText, PictureBox1.Bounds, sf)
    End Sub
 
Zuletzt bearbeitet:
Hi,

Ich hab da auch nen Code gefunden und der scheint in Ordnung zu sein, doch es wird einfach kein Text ausgeworfen?:confused:


Code:
' This example creates a PictureBox control on the form and draws to it. 
' This example assumes that the Form_Load event handling method is connected 
' to the Load event of the form.
Private pictureBox1 As New PictureBox()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill
    pictureBox1.BackColor = Color.White
    ' Connect the Paint event of the PictureBox to the event handling method.
    AddHandler pictureBox1.Paint, AddressOf Me.pictureBox1_Paint

    ' Add the PictureBox control to the Form.
    Me.Controls.Add(pictureBox1)
End Sub 'Form1_Load


Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    ' Create a local version of the graphics object for the PictureBox.
    Dim g As Graphics = e.Graphics

    ' Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control", _
        New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
    ' Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _ 
        pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub 'pictureBox1_Paint

Kann jemand mal den Code abchecken?:confused:

Das währe Liebenswürdig!:suspekt:
 
Zurück