Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

Positioning elements in a control array.

Hi there,

I'm writing a routine that dynamically adds check boxes onto a form based on the contents of a database; the routine that loads the controls and positions them down the form works fine but i'm having the following problem.

As I create the controls and move them down the form I need to resize the Frame3D control that holds them, move a group of buttons below the frame and also resize the form.  I've tried writing code to do this but i'm having a few problems with the co-ordinate system in VB.

I'm placed the buttons that need moving into a picturebox that now acts as the container, thus I only have to move the picturebox and not all the individual buttons.  However, if I resize the frame, form and move the picturebox by the appropriate amount i'm left with either big gaps or the newly created items are chopped off - why is this?  Is there some kind of weird scaling issue that i'm not aware of??

Thanks

Pete

0
peterwest
Asked:
peterwest
  • 2
  • 2
1 Solution
 
swiltCommented:
It works for me !
What does your code look like ?

Private Sub Command1_Click()
    Const cGap = 240
    Dim bNew As Integer
   
    bNew = Option1.Count
    Load Option1(bNew)
    Option1(bNew).Caption = "Option" & bNew
    Option1(bNew).Top = Option1(bNew - 1).Top + cGap
    Option1(bNew).Visible = True
    Frame1.Height = Frame1.Height + cGap
    Picture1.Top = Picture1.Top + cGap
    Me.Height = Me.Height + cGap
End Sub
0
 
peterwestAuthor Commented:
Hi,

I've had a look at my code again and realised what the problem was - I only want to resize the form and move the button container object when a certain number of items have been added.  This is because up until a point the container holding the control array is not as tall as other container objects on the same row; i've tweaked the code and it works fine now.

You're comment pointed me in the right direction so if you want to post an answer I'll happily pass the points over to you.

Regards

Pete

0
 
swiltCommented:
Glad I could be of some help

Private Sub Command1_Click()
    Const cGap = 240
    Dim bNew As Integer
           
    bNew = Option1.Count
    Load Option1(bNew)
    Option1(bNew).Caption = "Option" & bNew
    Option1(bNew).Top = Option1(bNew - 1).Top + cGap
    Option1(bNew).Visible = True
    Frame1.Height = Frame1.Height + cGap
    Picture1.Top = Picture1.Top + cGap
    Me.Height = Me.Height + cGap
End Sub
0
 
peterwestAuthor Commented:
Cheers
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now