Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scroll bars on my form 3

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I designed a form on 1600*1200 resolution for my own use which works fine. Obviously on another resolution I'm missing parts of the screen.
Is there a way I can implement scroll bars when resolution is other that 1600*1200?

Phailak
 
The classic way of doing this (book examples abound) is to use a picture box - but that has several drawbacks, not least that you have a bunch of code to write..

Easiest way is to cheat!

Add an MDI form to your application. Set it's title to be the same as your form. Set the Border style on your form to None, and set it's MDIChild property to true.

And that's it. You don't really have to make ANY further changes to your code EXCEPT if you are trying to show your form modally since, unfortunately MDI forms cannot be shown modally.

Regards,
Mike





 
Hail Mike,

I never used MDI forms before, so I'm not quite sure if I follow, the MDI form will have scroll bars?

Phailak
 
Yes, the MDI form will have scroll bars IF your form is bigger than the (resizable) MDI form.

Just try it, and you'll see.
 
Hail,

Thanx I will when I get home tonight. Great cheat BTW ;o)

Phailak
 
Hey Phailak,

If this helped you out could you vote that I helped you out...
 
While this is a good cheat, there is one (large) problem - you can't put controls onto an MDI form, or at least, you can't put controls without an align property.

This limits you to PictureBoxes, CoolBars, ToolBars etc. All of which influence the size and position of the scroll bars.

If I am wrong here Mike could you let me know?

Phailak, does your screen really only work on 1600x1200??? I know its more work, but I generally have code in the Form_Resize event handler which keeps everything in line.

Is it possible to have some more information about what your form does?

Chaz

Hi Mike, btw
 
Hail,

Well, the reason I worked with 1600*1200 was to have everything on one screen. Its an RPG app and I don't want to mess with switching from one from to the other. I have a bunch of buttons, listbox, combo boxes etc...
Some friends want it so I'm trying to fit it otherwise...
I played with resolution on resizing controls and stuff, it works for positionning but Fonts are messed up as well as some controls interlocking or something.

Phailak
 
Actually, its not too difficult to get it close to doing what you want ...

The way to do it is:

Put all of your controls onto a picture box (a BIG picture box ...)

On the form put a horizontal and a vertical scroll bar.

Add the following code to the form

'------

Private Sub Form_Resize()
HScroll1.Top = Height - HScroll1.Height - 400
VScroll1.Left = Width - VScroll1.Width - 120

HScroll1.Visible = (Width <= (Picture1.Width + 120))
VScroll1.Visible = (Height <= (Picture1.Height + 400))

HScroll1.Width = IIf(VScroll1.Visible, VScroll1.Left, Width - 120)
VScroll1.Height = IIf(HScroll1.Visible, HScroll1.Top, Height - 400)

HScroll1.Max = (Picture1.Width - Width) / 300
VScroll1.Max = (Picture1.Height - Height) / 300
End Sub

Private Sub HScroll1_Change()
Picture1.Left = -HScroll1.Value * 300
End Sub

Private Sub HScroll1_Scroll()
Picture1.Left = -HScroll1.Value * 300
End Sub

Private Sub VScroll1_Change()
Picture1.Top = -VScroll1.Value * 300
End Sub

Private Sub VScroll1_Scroll()
Picture1.Top = -VScroll1.Value * 300
End Sub

'-----------

This is just a code snippet - take it and improve on it. You might need to change some of the numbers to make sure the bars appear at the right time and in the right place.

Chaz
 
Hail,

Thanx for the code, I'll play with it but just to start me off, what do you base the numbers on? (300,400 and 120?)

Phailak
 
I have a magical technique which I use to generate those numbers, but I will share it with you.

I run the code, and when things appear in the wrong place, I add values to things to shift them up/down left/right.

I haven't put them in as constants because I wanted them to stand out. Once you've got the values correct (ie. the scrollbars are in the right place, etc) you can package them in constants.

Actually, this begs the question - how to you get the dimensions of the usuable bit of a form?

Chaz
 
Hail,

Cool, I'll give it a try, my form is pretty loaded up though, I don't know if I'll manage to fit everything on it. We'll see I guess...

Phailak
 
Hi Chaz,

You're quite right about the limitations of what you can put onto an MDI parent form - but we're not doing this.

The issue here is that Phailak already has a form, with all the controls etc that he wants on it. So all we need to do is make it an MDI child. Nothing else has to change at all (well, apart from changing the border setting as noted). i.e. all we are doing is hosting the original form.

One additional advantage of this 'cheat' is that if the original form has a menu bar then the MDI parent inherits this, and so the menu doesn't scroll...
 
Phailak, just click the 'let strongm know this post was useful' link...
 
Mike

Apologies for doubting your solution - you are quite right, a much more elegant solution. I can only put it down to lack of sleep.

Chaz
 
Hail,

Well guys, I didn't have a chance to try it yet, but if it's that simple I'm glad.

Thanx again.

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top