Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Setting the width of a toolbar button
posted

Hi,

I am using the UltraWebToolbar in perhaps a slightly unusual way, and that is to implement a dyanamic breadcrumbs trial. It is all working fine except for one small problem, and that is the width of the buttons I am using to implement each component of the trial. I'd like the width of the button to match the width of the text it contains, but I cannot find a way of accomplishing this. I know that I can set a fixed width for a button but given that the text is dynamic, this presents a problem. Is there any kind of "auto fit" property I set anywhere to tell the button to match to the size of the text, rather than expanding so that the whole width of the page is used?

I hope that makes sense and that somebody is able to provide an answer.

Thanks,

Ben

  • 370
    posted

    Ben

    I've had to do something similar before with labels on the toolbar, I acheived it by using the System.Drawing.Graphics.MeasureString method. 

      Dim graphic As Drawing.Graphics = _
        Drawing.Graphics.FromImage(
    New Drawing.Bitmap(1, 1, Drawing.Imaging.PixelFormat.Format32bppArgb))

      Dim stringLength As Int16 = graphic.MeasureString(charString, Font).Width

    You'll need to create a Font object for the second parameter.

    Andy