Solved

Label exactly that width of his text...

Posted on 2004-10-24
257 Views
Last Modified: 2010-05-18
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
Question by:Svenrutten
    2 Comments
     
    LVL 85

    Accepted Solution

    by:
    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
     

    Author Comment

    by:Svenrutten
    That's great!! Didn't think that this would be possible!

    Thanks so much!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now