Positioning a Group Box at Runtime - Help

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2007
Posts: 49
Reputation: Mr.Wobbles is an unknown quantity at this point 
Solved Threads: 2
Mr.Wobbles Mr.Wobbles is offline Offline
Light Poster

Positioning a Group Box at Runtime - Help

 
0
  #1
Apr 11th, 2008
I am writing a program that will take input from the user in the form of a tree-view and create a form and a database based on the tree-view. I have everything working except the group-box control for the boolean expression. I will give a sample code of the text boxes that do work and then I will give the code that is not working.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. For Each babyNode In childNode.Nodes
  2. If babyNode.Text.ToString = "Small Text ( Less than 255 Characters )" Then
  3. Dim TextField As New System.Windows.Forms.TextBox
  4. Dim labelField As New System.Windows.Forms.Label
  5. 'Create and position the label field
  6. With labelField
  7. .Name = fieldName & "label:"
  8. .Text = fieldName
  9.  
  10. iSizW = .Size.Width
  11. iSizH = .Size.Height
  12.  
  13. .Left = iLocX
  14. .Top = iLocY
  15.  
  16. tabPage.Controls.Add(labelField)
  17. End With
  18. 'Create and position the text field
  19. With TextField
  20. .Name = fieldName
  21. .Multiline = False
  22. .WordWrap = False
  23. .MaxLength = 255
  24. .Text = babyNode.NextNode.Text.ToString
  25. .Visible = True
  26.  
  27. iSizW = .Size.Width
  28.  
  29. iLocX = iLocX + iSizW + 5
  30.  
  31. .Left = iLocX
  32. .Top = iLocY
  33.  
  34. tabPage.Controls.Add(TextField)
  35. End With
  36. 'Increment the Location for the next label field
  37. iLocX = iLocX + iSizW + 10
  38.  
  39. 'Check to see if the control is going to run of the form, if it
  40. 'is then go down to the next row
  41. If (iLocX + iSizW > Me.Size.Width - 20) Then
  42. iLocX = 5
  43. iLocY = iLocY + iSizH + 5
  44. End If
  45. Exit For

That works perfectly. This is the group box control that is not working:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ElseIf babyNode.Text.ToString = "Boolean (True or False)" Then
  2. Dim tempX As Integer
  3. tabPage.Controls.Add(groupBoxItem)
  4. With groupBoxItem
  5. .Name = fieldName
  6. .Text = fieldName
  7. .Width = 217
  8. .Height = 40
  9.  
  10. iSizW = .Width
  11. iSizH = .Height
  12.  
  13. iLocX = iLocX + iSizW + 5
  14.  
  15. .Left = iLocX
  16. .Top = iLocY
  17.  
  18. .Controls.Add(booleanTrueField)
  19. With booleanTrueField
  20. .Text = "True"
  21. .Top = 14
  22. iSizW = .Size.Width
  23. tempX = .Location.X
  24. .Left = tempX + 5
  25. If babyNode.NextNode.Text.ToString = "True" Then
  26. .Checked = True
  27. End If
  28. End With
  29.  
  30. .Controls.Add(booleanFalseField)
  31. With booleanFalseField
  32. .Text = "False"
  33. .Top = 14
  34. .Left = tempX + iSizW + 5
  35. tempX = .Location.X
  36. iSizW = .Size.Width
  37. If babyNode.NextNode.Text.ToString = "False" Then
  38. .Checked = True
  39. End If
  40. End With
  41. MsgBox("Adding Field: " & .Name.ToString & vbCr & "X: " & .Location.X & vbCr & "Y: " & .Location.Y)
  42. End With
  43.  
  44. 'Increment the Location for the next control
  45. iLocX = iLocX + iSizW + 10
  46.  
  47. If (iLocX + iSizW > Me.Size.Width - 20) Then
  48. iLocX = 5
  49. iLocY = iLocY + iSizH + 5
  50. End If
  51. Exit For

Currently I am using Visual Studio 2005, VB 6 I think. If there are any questions, I would be happy to answer them - thanks in advance for any help I do receive.

P.S. in tests it seems to position them semi-correctly (at least not in the same spot) as indicated by messages I receive by the program - but when the form loads they are either one on top of another, or whichever is not the most recent addition is gone.
Last edited by Mr.Wobbles; Apr 11th, 2008 at 1:32 pm.
Mr.Wobbles~
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 49
Reputation: Mr.Wobbles is an unknown quantity at this point 
Solved Threads: 2
Mr.Wobbles Mr.Wobbles is offline Offline
Light Poster

Re: Positioning a Group Box at Runtime - Help

 
0
  #2
Apr 11th, 2008
Goodness, This was a simple fix, something that occurs when I stare at code to long - I miss the obvious. I was only declaring the group box at the beginning and therefore using the same one every time I ran the code. So I moved the group box intialization to after the ElseIf and everything works great. --
Mr.Wobbles~
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC