Results 1 to 6 of 6

Thread: [RESOLVED] dynamic radiobutton issue

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    9

    Resolved [RESOLVED] dynamic radiobutton issue

    Trying to create a set of controls that can be used repeatedly without copy and paste code, including a textbox, a set of radiobuttons and then another textbox. Having a major problem in that I can only get one radiobutton to show up. The code I've created for it is below and as I've found this board helpful in the past I was hoping someone can help me out and explain what I've done wrong.
    vb.net Code:
    1. Public Class QuestionDisplay
    2.     Inherits Windows.Forms.GroupBox
    3.     'Form Controls
    4.     Dim m_Question As New Windows.Forms.TextBox
    5.     Dim m_Comment As New Windows.Forms.TextBox
    6.     Dim m_GroupBox As New Windows.Forms.GroupBox
    7.     Dim m_rbtn1 As New Windows.Forms.RadioButton
    8.     Dim m_rbtn2 As New Windows.Forms.RadioButton
    9.     Dim m_rbtn3 As New Windows.Forms.RadioButton
    10.     Dim m_rbtn4 As New Windows.Forms.RadioButton
    11.     Dim m_rbtn5 As New Windows.Forms.RadioButton
    12.     'Positions
    13.     Dim m_xPos As Integer
    14.     Dim m_yPos As Integer
    15.  
    16.     Public Sub New(ByVal xpos As Integer, ByVal ypos As Integer)
    17.         m_xPos = xpos
    18.         m_yPos = ypos
    19.         Me.Width = 470
    20.         Me.Height = 37
    21.         Me.Location = New Point(5, 26)
    22.         SetPositions()
    23.     End Sub
    24.  
    25.     Private Sub SetPositions()
    26.         'ADD Question to GBO
    27.         m_Question.Location = New Point(1, 10)
    28.         m_Question.Width = 180
    29.         m_Question.Height = 20
    30.         m_Question.Name = "m_Question"
    31.         Me.Controls.Add(m_Question)
    32.  
    33.         m_GroupBox.Location = New Point(190, 4)
    34.         m_GroupBox.Width = 100
    35.         m_GroupBox.Height = 30
    36.         m_GroupBox.Name = "m_GroupBox"
    37.         PositionRbtns()
    38.         AddRbtnsToGroupBox()
    39.         Me.Controls.Add(m_GroupBox)
    40.  
    41.         'Add Comment to GBO
    42.         m_Comment.Location = New Point(300, 10)
    43.         m_Comment.Width = 170
    44.         m_Comment.Height = 20
    45.         m_Comment.Name = "m_Comment"
    46.         Me.Controls.Add(m_Comment)
    47.     End Sub
    48.  
    49.     Private Sub PositionRbtns()
    50.         m_rbtn1.Location = New Point(5, 10)
    51.         m_rbtn1.Name = "m_rbtn1"
    52.         m_rbtn2.Location = New Point(25, 10)
    53.         m_rbtn2.Name = "m_rbtn2"
    54.         m_rbtn3.Location = New Point(45, 10)
    55.         m_rbtn3.Name = "m_rbtn3"
    56.         m_rbtn4.Location = New Point(65, 10)
    57.         m_rbtn4.Name = "m_rbtn4"
    58.         m_rbtn5.Location = New Point(85, 10)
    59.         m_rbtn5.Name = "m_rbtn5"
    60.     End Sub
    61.  
    62.     Private Sub AddRbtnsToGroupBox()
    63.         m_GroupBox.Controls.Add(m_rbtn1)
    64.         m_GroupBox.Controls.Add(m_rbtn2)
    65.         m_GroupBox.Controls.Add(m_rbtn3)
    66.         m_GroupBox.Controls.Add(m_rbtn4)
    67.         m_GroupBox.Controls.Add(m_rbtn5)
    68.     End Sub
    69. End Class
    Last edited by shadowsofsorrow; Oct 21st, 2011 at 02:28 AM.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: dynamic radiobutton issue

    Could you please wrap your code in [highlight="vb.net"][/highlight] tags to make it easier for people to read. Thank you! Also, your question is regarding vb.net so I have requested the thread moved.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    9

    Re: dynamic radiobutton issue

    Sorry, did not realise there was such a thing

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: dynamic radiobutton issue

    Thread moved from the 'VB6 and Earlier' forum to the 'VB.Net' (VB2002 and later) forum (thanks Nightwalker83 )

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: dynamic radiobutton issue

    The code looks reasonable, but the positioning of the radiobuttons doesn't seem quite right. You are holding Y fixed and changing X. Technically, that should work, but in most cases, you see the X held constant and Y being changed such that the radio buttons stack vertically rather than forming a horizontal line.

    EDIT: After looking at how you size the group box, I guess you meant to have it the way you do. However, you are adding all the radio buttons to the groupbox, which isn't as big as the whole control. I wonder whether or not you are not getting overlapping issues. You might comment out the control that is being displayed, and see whether that causes the next control to be displayed.
    Last edited by Shaggy Hiker; Oct 21st, 2011 at 09:04 AM.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    9

    Re: dynamic radiobutton issue

    Yeah that thing was it I didn't realise it would create the radiobutton with a bigger size than what it looked like it had, setting a default size fixed the problem, thanks a lot

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