• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Label exactly that width of his text...

Hi

I have a problem. I several labels which I can move and they have a transparent background

Now I can edit the text of the label.

So my question: How can I make the label exact that width that it is showing the text and not more? Otherwise I have problems if I place two labels aside of each others...

The Problem is that 'i' takes a half a size then 'B' and so on...

Any solutions?

Thanks a lot

Sven
0
Svenrutten
Asked:
Svenrutten
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Something like this may work:

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Label2.Text = TextBox1.Text
        Dim g As Graphics = Label2.CreateGraphics
        Label2.Width = g.MeasureString(Label2.Text, Label2.Font).Width + 1 ' (a little flub)
        g.Dispose()
    End Sub

~IM
0
 
SvenruttenAuthor Commented:
That's great!! Didn't think that this would be possible!

Thanks so much!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now