How to stop controls scroll with form?

AaronYang

New Member
Joined
Nov 1, 2006
Messages
43
Hi,All,
I have a form with height 50 centimeters, and there is a listbox in the left of the form, it is used for pick value. The problem is: when scroll the form, the listbox will disappear with the form page together, how can I keep the listbox always show in the screen?

I try to use below code to capture the scrollbal postion then re-set the listbox TOP properties, but it always show as Zero. Can anybody help me on that? Thanks!


Code:
Option Compare Database
Option Explicit

 
  Public Const SB_HORZ       As Long = 0
  Public Const SB_VERT      As Long = 1
  Public Const SB_CTL       As Long = 2
  Public Type SCROLLINFO
          cbSize   As Long
          fMask   As Long
          nMin   As Long
          nMax   As Long
          nPage   As Long
          nPos   As Long
          nTrackPos   As Long
  End Type
  Public Const SIF_RANGE       As Long = &H1
  Public Const SIF_PAGE       As Long = &H2
  Public Const SIF_POS       As Long = &H4
  Public Const SIF_TRACKPOS       As Long = &H10
  Public Const SIF_DISABLENOSCROLL       As Long = &H8
  Public Const SIF_ALL       As Long = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
  Public Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long

Private Sub Command16_Click()
Dim AA

  Dim SI  As SCROLLINFO
  With SI
  .cbSize = Len(SI)
  .fMask = SIF_ALL
  End With
  AA = GetScrollInfo(Me.hWnd, SB_VERT, SI)
  MsgBox AA
  MsgBox SI.nPos  & "  ==" &  SI.nTrackPos
 
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Aaron,
If you put your list box in the header of the form, then as you scroll down the form, the list box will stay put. Of course, you want to keep it on the left side of the form, but I have found some battles are not worth the fight, and for me, I would put this battle in that category. I would also suggest you change the list box to a combo box, that way you would not be losing that much of the height of your form to the list box.
HTH
 
Upvote 0
Kind of similar to Vic's suggestion you can use a form/subform setup where you listbox is on the main form and the other controls are on the subform. This should give you the ability to have your listbox fixed on the left and the other controls scrollable.

hth,
Giacomo
 
Upvote 0
OK, so I forgot the subform. Thanks Giacomo! Great idea!

Plus, I like the shoe.
:)
 
Upvote 0
OK, so I forgot the subform. Thanks Giacomo! Great idea!

Plus, I like the shoe.
:)

Thanks. I didn't think of it until after I read your post... so you can say I was inspired. The subform that is, not the shoe.
 
Upvote 0
This listbox is used for drag/move value to textbox, when mousedown, a label will show and position follow up the cursor move, label caption is get from the listbox; when mouseup, the textbox which under the cursor will be changed as same as the listbox. So if I use subform,this label will display behind the subform and couldn't pass value to subform textbox.

I can not replace the listbox with combobox, either, because the itemdata is too much,it will be very trouble for end user to select.

Anyway, thanks to both for your advice.
 
Upvote 0
I think I can move all the controls into Page control to reduce the form height, it no need to scroll. ^_^
 
Upvote 0
I think I can move all the controls into Page control to reduce the form height, it no need to scroll. ^_^

Ah that's a good idea too... BTW, I'm curious about your signature can you translate it for me?
 
Upvote 0
Ah that's a good idea too... BTW, I'm curious about your signature can you translate it for me?

Hi,Giacomo,
Here is the translated text for you.

I am tired
You always pretend to be you don't care
How could a relationship be so exhausted and falling apart...
 
Upvote 0

Forum statistics

Threads
1,215,170
Messages
6,123,422
Members
449,099
Latest member
COOT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top