Results 1 to 13 of 13

Thread: [RESOLVED] Trying to calculate a set placement for dynamic radio buttons?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [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,
    Blake

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    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

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Trying to calculate a set placement for dynamic radio buttons?

    I have since removed the .Size property and unfortunately it didn't matter.
    Blake

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    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.

    Quote 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

  5. #5
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Trying to calculate a set placement for dynamic radio buttons?

    Quote Originally Posted by kebo View Post
    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

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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...
    Blake

  7. #7
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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...
    Blake

  9. #9
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: Trying to calculate a set placement for dynamic radio buttons?

    nm... bogus post
    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

  10. #10
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Trying to calculate a set placement for dynamic radio buttons?

    Quote Originally Posted by blakemckenna View Post
    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

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Trying to calculate a set placement for dynamic radio buttons?

    Kaliman,

    That worked...but why did it work?

    Thanks,
    Blake

  12. #12
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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!
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width