Improve company productivity with a Business Account.Sign Up

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

How to Create Scrollable forms?

Dear Gurus,

        I am working on a programme such that it will create a series of label control follow by textbox control(pairs) during runtime. These are like Questions and Answers form. The catch is that we do not know how many Questions we have (read from a file). And the important part is the interface is going to be like a web browser where you can scroll down(scroll bar on the right side of screen). However, form object in VB 5.0 has no scroll bar and I am not allowed to use more than one form. Is there anyway to achieve that? How can I combine a form object and a V scroll bar control to achieve the effect?

      I had tried out some OCX control(freeware on the internet) called scrollbox.zip but I can't even register the OCX control to begin with.

        Thanks for any help I might get.

0
happydanny
Asked:
happydanny
  • 4
1 Solution
 
happydannyAuthor Commented:
Edited text of question
0
 
happydannyAuthor Commented:
Edited text of question
0
 
happydannyAuthor Commented:
I have posted this to Newsgroup but seems that no gurus is able solve the problem. Any takers?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
anthonycCommented:
Happy.. this is not too difficult.

Do this:

1)  Add a Vertical Scroll bar to your form.  Put it on the right side, and put this code in your resize event

private sub Form_Resize()
  'Resize the scrollbar so it takes the entire window
  if me.windowstate <> vbMinimized then
    vScroll1.move me.scalewidth - vscroll1.width, 0, vscroll1.width, me.scaleheight
  end if

2)  Set the VScroll1.min = 1 and the max = #questions

3)  Add 1 textbox and 1 label to your form.  Make them invisible, and set their index property to 0

4)  Write Code to load textbox/label pairs for you

private sub LoadPairs(nCount as integer)
  const sSep as single = 500

  dim nI   as integer
  dim sTop as single

  for ni = 1 to ncount
     load text1(ni)
     load label1(ni)
   
     sTop = sTop + sSep
     with label1(ni)
        .left = 60 'or whatever left you want to use
        .top = sTop
        .visible = true
     end with

     with text1(ni)
        .left = 3000
        .top = stop
        .visible = true
     end with
  next ni
end sub


5)  Now for the scrolling code

private sub vScroll1_Change()
   dim nI as integer
   const sSep as single = 500

   'The scrollbar contains which question we want on the top.
   'We must then reposition everything else based on that.

   for ni = 1 to text1().ubound
      label1(ni).top = ((ni - vscroll1.value) + 1) * sSep
      text1(ni).top = label1(ni).top
   next ni
end sub


0
 
MirkwoodCommented:
Use a picture box and two scrollbars. Place all your controls on the picturebox.
Now you can set the left and the top property of the picture to the negative value of the scrollbar values.

I can also send you some code that does this. Post a comment here and mail to Mirkwood@hotmail.com
0
 
happydannyAuthor Commented:
Dear anthonyc,

        Thanks for your fabulous answer. However, after reading Mirkwood's answer, I think it is an easier method to my goal.
        If it is possible I would like to take a look at Mirkwood's code.
        I had already setup the values including adjusting for Vscroll.max dynamically so that it scrolls smoothly for both cases when control boxes are longer than one page and when control boxes fit nicely into just one page!
        I still had some doubt about constructing a control array to when I read the questions from a txt file.
        I still had some doubt about constructing a control array when I read the questions from a txt file. I hope Mircwood's answer can kindly show me how to achieve that.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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