lundi 20 avril 2015

Visual Basic Forms Rotating text within a label

Basically I need to have text within a label, or other container of a given size that can be rotated. But act like a label; the text wraps to next line when it can't fit on one line and is centre aligned.

Looking around I found graphics.DrawString and graphics.RotateTransform I tried messing around with them using some tutorials and managed to rotate text to 90 degrees using this.

Private Sub painted(sender As Object, e As PaintEventArgs) Handles label1.Paint
        Dim fontObj As Font
        fontObj = New System.Drawing.Font("Times", 10, FontStyle.Bold)
        e.Graphics.TranslateTransform(sender.width - 15, 10)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString("Test", fontObj, Brushes.Black, 0, 0)
    End Sub

However this doesn't solve the problem of text wrapping and I'm still not entirely sure how exactly this works. I'm looking for a sub that could take parameters of a label control, a string, and a rotation angle(90,180,270) and then draw that string inside the control so that it is all visible without changing the size of the control.

So my question is: is it possible? and if so where do I start and how should I go about it?

Aucun commentaire:

Enregistrer un commentaire