Radiobutton Autosize does not increase the height (Windows forms)

  • Thread starter Thread starter BillE
  • Start date Start date
B

BillE

I am using VB.NET, VS 2005
Add a windows form and in design view:

Add a Radiobutton to the windows form
Set AutoSize = True for the radiobutton
Set the MaximumSize width to 90 for the radiobutton
Enter text for the radiobutton which is longer than the default
Run it - the height of the radiobutton does not increase, and the text is
truncated.

If the MaximumSize for the width is not set, then the autosize increase the
width to accommodate the long text, but the height will not increase if the
maximum width is not adequate.

What am I overlooking?
Thanks
Bill
 
BillE said:
I am using VB.NET, VS 2005
Add a windows form and in design view:

Add a Radiobutton to the windows form
Set AutoSize = True for the radiobutton
Set the MaximumSize width to 90 for the radiobutton
Enter text for the radiobutton which is longer than the default
Run it - the height of the radiobutton does not increase, and the text is
truncated.

If the MaximumSize for the width is not set, then the autosize increase the
width to accommodate the long text, but the height will not increase if the
maximum width is not adequate.

What am I overlooking?
Thanks
Bill

Are you overlooking that the width needed to fit the text is more than 90?
 
I want it to autosize the Height, F.T. Mike. Sorry I didn't explain it
better. I said: "the height will not increase if the
maximum width is not adequate"

If I create a label, for example, with Autosize = true, maximum width = 90,
and the text is too large for the maximum width, then the label expands
vertically. This doesn't appear to happen for a Radio button to display the
complete text.
 
OK, now I understand what you mean, but I don't have a solution. I was
surprised to see that I could include a \n in the string to get a multiline
lable. With no "wrap" or multiline attribute, I'm not sure what you could do.
 
The only thing I can think of is to dynamically calculate how much
horizontal space I have for dynamically created controls, calculate how many
pixels I need for the caption text, and then calculate what the height will
have to be to accommocate the text. PITA.

What I don't understand is why the radio button control has a maximum size
property with a height component when the auto size won't increase the
height! Is it a bug?
 
BillE,

There are lot of controls which have properties which don't do anything.

That is the way OOP in Net is working. The RadioButton is inheritted from
Control. Everytime that you inherrit a class then you get all its
properties.

The base class is Object (that is where by instance to ToString is in). One
of the most famous properties is the "Dispose" which is in the component
class, which is inherited by 20% of the most classes however those are
probably those which are the most frequently used. The effect of this is
that a lot of people think you should use it, while in most cases it is only
a placeholder to put in your own code if you need that.

The same is with your problem, you can use the propertie to put in your own
code (by instance own painting). However don't expect that it is working
forever direct as it is as in other inherited classes. While it even can be
shadowed to stop the behaviour at a higher level. A property from a higher
level stays however always visible.

I hope that this explains a little bit your problem.

Cor
 
I fought this issue for over a day, finally found a reasonable answer (see bold code)...

Dim _rb = New RadioButton
_rb.Name = "RB" & CStr(_cdr.Item("ID"))
_rb.Appearance = Appearance.Normal
_rb.CheckAlign = ContentAlignment.TopLeft
_rb.TextAlign = ContentAlignment.TopLeft
_rb.Text = CStr(_cdr.Item("Description"))
_rb.Font = New Font("Arial", 8, FontStyle.Regular)
_rb.Width = _w
_rb.Height = TextRenderer.MeasureText(_rb.Text, _rb.Font, New Size(_w, 0), TextFormatFlags.WordBreak).Height + 3
_flp2.Controls.Add(_rb)
 
Back
Top