-
Aug 31st, 2015, 12:43 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Trying to calculate a set placement for dynamic radio buttons?
I have a groupbox that dynamically loads radiobuttons horizontally. The problem that I'm having is that the "Width" property of the radiobutton stays the same regardless of what the "Text" property is. I've set the rdo.AutoSize = True and that still doesn't help. Below is the code that sets this up.
Code:
Dim iLeft As Integer = 13
For Each row As DataRow In EH.DataSet.Tables(0).Rows
Dim rdo As New RadioButton
rdo.Top = 19
rdo.Left = iLeft
rdo.Text = row("calibrationType")
rdo.Tag = row("calibrationType_ID")
rdo.Name = "rdo" & row("calibrationType_ID")
rdo.Font = New Font(rdo.Font, FontStyle.Regular)
rdo.AutoSize = True
iLeft += (rdo.Width + 2)
rdo.Size = New Point(19, iLeft)
grpCalibrationType.Controls.Add(rdo)
Next
What am I doing wrong?
Thanks,
-
Aug 31st, 2015, 01:44 PM
#2
Re: Trying to calculate a set placement for dynamic radio buttons?
My guess is that by setting the .Size property you're overriding the .AutoSize property. I'm thinking you might have meant to set the .Position property instead of the .Size property.
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Aug 31st, 2015, 01:46 PM
#3
Thread Starter
PowerPoster
Re: Trying to calculate a set placement for dynamic radio buttons?
I have since removed the .Size property and unfortunately it didn't matter.
-
Aug 31st, 2015, 01:47 PM
#4
Re: Trying to calculate a set placement for dynamic radio buttons?
With autosize on, the control will resize itself based on the size of the text. So to have all of the radio buttons the same width, you will want that turned off and then manually set the width property to some value.
And this...
Code:
rdo.Size = New Point(19, iLeft)
is most certainly an issue (maybe a typo?). you can assign a Point to something that require a Size.
Originally Posted by dolot
My guess is that by setting the .Size property you're overriding the .AutoSize property
That's not the case. With the AutoSize set, the size property is overridden and the control is sized based on its contents.
Last edited by kebo; Aug 31st, 2015 at 01:52 PM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 31st, 2015, 02:06 PM
#5
Re: Trying to calculate a set placement for dynamic radio buttons?
Originally Posted by kebo
That's not the case. With the AutoSize set, the size property is overridden and the control is sized based on its contents.
That's right. Been coding so much in JavaScript lately that my windows forms knowledge is getting rusty.
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Aug 31st, 2015, 02:40 PM
#6
Thread Starter
PowerPoster
Re: Trying to calculate a set placement for dynamic radio buttons?
I don't know what's going on with it. It doesn't make sense so I just provided a value that would equally space out the RDO's...
-
Aug 31st, 2015, 02:59 PM
#7
Re: Trying to calculate a set placement for dynamic radio buttons?
Just set your iLeft variable after you place the radioButton, it does not have a fixed width before that
Code:
Dim iLeft As Integer = 13
For Each row As DataRow In EH.DataSet.Tables(0).Rows
Dim rdo As New RadioButton
rdo.Top = 19
rdo.Left = iLeft
rdo.Text = row("calibrationType")
rdo.Tag = row("calibrationType_ID")
rdo.Name = "rdo" & row("calibrationType_ID")
rdo.Font = New Font(rdo.Font, FontStyle.Regular)
rdo.AutoSize = True
grpCalibrationType.Controls.Add(rdo)
iLeft += (rdo.Width + 2)
Next
Last edited by kaliman79912; Aug 31st, 2015 at 11:34 PM.
Reason: I was using my own tables
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Aug 31st, 2015, 04:13 PM
#8
Thread Starter
PowerPoster
Re: Trying to calculate a set placement for dynamic radio buttons?
What do you mean "place it"? I thought that's what I'm trying to doing...
-
Aug 31st, 2015, 06:46 PM
#9
Re: Trying to calculate a set placement for dynamic radio buttons?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 31st, 2015, 11:29 PM
#10
Re: Trying to calculate a set placement for dynamic radio buttons?
Originally Posted by blakemckenna
What do you mean "place it"? I thought that's what I'm trying to doing...
I mean "place it" as in Add it to the grpCalibrationType.Controls collection, I know that is what you are trying to do but you are not, you just set the properties to the new object but you have not placed it in the collection before you set the variable iLeft.
This line:
grpCalibrationType.Controls.Add(rdo)
must be before this one:
iLeft += (rdo.Width + 2)
Last edited by kaliman79912; Aug 31st, 2015 at 11:33 PM.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Sep 1st, 2015, 08:48 AM
#11
Thread Starter
PowerPoster
Re: Trying to calculate a set placement for dynamic radio buttons?
Kaliman,
That worked...but why did it work?
Thanks,
-
Sep 1st, 2015, 09:08 AM
#12
Re: Trying to calculate a set placement for dynamic radio buttons?
It worked because the width (and other properties) are not really set on the object until it is actually created. This object is a radio button, so it is a control. When you create the object with Dim you are creating it virtually, it is like it's soul but it does not have a body, and since it does not have a body some properties that depend on the physical state of the control are not set. Sure, there is a width, but that is the one created when the "soul" was created, changing the text will never affect the width unless the control has a body. And you are giving birth to the control the moment it is placed in a collection.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Sep 1st, 2015, 09:35 AM
#13
Thread Starter
PowerPoster
Re: Trying to calculate a set placement for dynamic radio buttons?
That is probably the best explanation of object instantiation I've ever heard. Thanks!!! That makes total sense!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|