Challenge - ListView with Custom Scrollbars
Is anybody smart enough to help me get this working ok? I cannot make that the scrollbar reachs the bottom at the same time as the ListView. It's still buggy.... who dare see it?
Printable View
Challenge - ListView with Custom Scrollbars
Is anybody smart enough to help me get this working ok? I cannot make that the scrollbar reachs the bottom at the same time as the ListView. It's still buggy.... who dare see it?
This is what I'm trying to do:
http://www.vbforums.com/attachment.p...postid=1027365
Come on... the more people that participate, the faster we will get it working.
You don't move controls using the height and width properties of a form. You use the ScaleWidth and ScaleHeight properties.
VB Code:
Private Sub Form_Resize() LV.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight With pctSBLV .Left = Me.ScaleWidth - .Width .Height = Me.ScaleHeight .PaintPicture pctOrig, 0, 0, , Me.ScaleHeight, 0, 0 End With End Sub
Here's how you would make it scroll if you were using a standard scroll bar.
VB Code:
' AFTER all the controls are positioned, you set the scroll bar ' properties. With ScrollBar1 if ScaleHeight > LV.Height then .Max = ScaleHeight - LV.Height .Enabled = True Else .Value = 0 .Enabled = False End If End With Sub ScrollBar1_Scroll LV.Top = - ScrollBar1.Value End Sub
Ok, but I', not using a standard scrollbar. And it's a little different with a picturebox.
actually, it's exactly like that for a picture box. Assuming you are using a picture box in a picture box.
Size the first picture (container) to whatever size on the form.
Size the internal picture box to it's full size. Then you set the scrollbar max to be internal picture.height - container picture.height
Or are you talking about the scroll bar being a picture box? It that's the case, you'd be better off writing a class that uses a picturebox object and then giving the class the same properties as a standard scrollbar so that the interface is the same.
Otherwise, you're just making your life harder.
I don't get it... could you post an example?
What are you using the picturebox for... the scroll bar or the listview?
The picturebox is for scrolling the ListView
so the list view is full expanded, correct? Then the picture box is the "window" container for the list view.
So if the listview is the same size or smaller than the picturebox, then you just disable the scroll bar. That part is easy.
When the listview is bigger than the picture box (height) then the scroll bar need to be set so that it can scroll the difference in height of the two
ScrollBar1.Max = ListView1.Height - PictureBox1.ScaleHeight
then when you use the scroll bar, the list view moves up and down in the picture box. But if the scroll bar goes down, the picture goes up. So you use minus the value of the scroll bar.
Sub ScrollBar1_Scroll
ListView1.Top = - ScrollBar1.Value
End Sub
Your code doesn't work like that though. But you get the idea. the maximum your scroll bar should be able to move is the difference in height of the listview and scaleheight of the picture box.
As a rule of thumb, you use the ScaleHeight of the container and the Height of the contained object for this sort of thing.
Ah... I understand you. But I cannot know if the ListView would always be "able" to be sized so that all the items are shown. I believe there's a limit for its height property. If that is so... I cannot do it this way.
I'm using the picturebox to scroll the ListView, not to change its top.
OK, then I'm really lost. How are you using the picture box to scroll a list view?
I'm sending a message to the LV
VB Code:
SendMessage lst.hwnd, LVM_SCROLL, ByVal HorizPixels, ByVal VertPixels
OK, this is beyond my realm now. There are two pieces of information you need to complete this puzzle.
1) Can you send it negative values? How does it know if you're going up or down?
2) How do you know what the maximum scroll value is? If you know that and know where you are, then it's not a difficult problem.
Ok... I almost got it your way. The main problem is that the ListView's height maximum value is 245745. Any odeas?
Not really. My last post pretty much sums up what needs to happen. I have no idea how to do it though. This is one of the many reasons I don't play with making my own controls. It's just too many headaches and keeps me from getting my applications finished.
What you need is an API guru to show you the way.
I'm this close to get it working the way I was saying. I need to sharpen the calculation.
It's a pleasure for me to say that..... I've acheive to scroll both (ListView and TreeView) with my personal scrollbar!!!
:D :D :D :D :cool: :cool: :cool: :cool: :D :D :D :D
All hail McBrain! The Patron Saint of Scroll Bar.Quote:
Originally posted by Mc Brain
It's a pleasure for me to say that..... I've acheive to scroll both (ListView and TreeView) with my personal scrollbar!!!
:D :D :D :D :cool: :cool: :cool: :cool: :D :D :D :D
* CafeenMan looks upon Mad McBrain with terror and awe *
:)
Good job, man!
If you see Winamp shaking.... is because they found out my app. Anyway, it's not a player... it's just an UI to select the music you want Winamp to play.... then, it'd be nice that this app look like Winamp, don't you think?
By the way.... MP3 Browser will be part of the MP3 Organizer (posted on the signature).... but I'll upload it later tonight when I get home.
So are you turning your scroll bar into an ActiveX control?
mmmm... I don't think that would be easy. I'll think about it.
It's code, code and more code right now. I didn't think of writing an ActiveX 'cos it was too buggy before.... Anyway, re-writing all this to create an ActiveX would be another challenge.
Here's the code for the Listview....
hey its very nice :))
but..
i've three little thing:
- please explain me why u just needed that timer? (250msec.. it looks like when an app lagging.. anyway 50msec better) (edit: oops.. only with 50msec, in your code its precise :D)
- move the bar very-very smoothly/slowly.. the listbox isnt scrolls itself
- i can scroll the listbox with the mousewheel, but the scrollbar isnt follows its position :)
anyway, superb code, grats :)
I don't know, I use a timer to detect the shift of the scrollbar and set its interval to a little number. A more little number could be needed. That could be changed easily if it doesn't expects your needs.Quote:
Originally posted by Jim Davis
hey its very nice :))
but..
i've three little thing:
- please explain me why u just needed that timer? (250msec.. it looks like when an app lagging.. anyway 50msec better) (edit: oops.. only with 50msec, in your code its precise :D)
Yes, that's a problem. The code detects the relative movement (not absolute). So if you move pixel by pixel it might not be enough to scroll a whole line up. Even later (when you have scrolled a lot of pixels) if you're still moving pixel by pixel the relative movement won't be enough.Quote:
Originally posted by Jim Davis
- move the bar very-very smoothly/slowly.. the listbox isnt scrolls itself
I'd already notice that... but have not the clueless idea how to detect that scroll and refresh the scrollbar's top.Quote:
Originally posted by Jim Davis
- i can scroll the listbox with the mousewheel, but the scrollbar isnt follows its position :)
anyway, superb code, grats :)
Anyway, you won't notice this if you have too many items. Even if you move a pixel, your ListView will scroll.Quote:
Originally posted by Mc Brain
I don't know, I use a timer to detect the shift of the scrollbar and set its interval to a little number. A more little number could be needed. That could be changed easily if it doesn't expects your needs.
yo brain
ive a little bit modified your code :D
im sorry for that, but ive seen that your horrible complex calculations, and i cant understand them sometimes, so ive made some modifications.. see the bottom of the form if you wish to know what was them.. it looks a little bit easier, and more accurate... check out :)
and... show me if you do something with that.. i'm very curious to see how it will works.. im too lazy to finsh :)
PS: the timer is commented out, because looks like you would not need that..
Jim
well.. ive forgot the code :D
Wow.... you've changed too much for a code that I've written testing it. That's why the "complex" calculations. Besides, I don't see the ListView scrolling.
:) as i said im too lazy to done this code... but.. if you want, i'll dust of my glasses and done this :)
Ok... here you have an improved version.
i've some other idea to how can i figure out this problem, so will you accept if im rewrite your handler engine? :)
i hope so... :)
Go ahead... but I guess this is the easiest way it can be done. The other way would be to resize the cursor according to the number of elements (if there are too few, the first and last "page" won't scroll the listview). Anyway, this resizing of the cursor won't be nice for the app I was writing.
Another way would be as Winamp does. To have a stepped cursor. I mean the cursor doesn't move smoothly but through steps. But I guess that would be harder to code.
the cursor in winamp moves smoothly......
No it doesn't. Add 10-20 items or less, resize the playlist window so that it would need 1 and a little pages and you will see what I mean.
The "stepped" cursor happens when you have too few items. If this happens the listview doesn't move until "some time" (in my app). Winamp, to avoid this does not move the cursor until the list is scrolled, and when this happen the cursor moves a "lot".
just a quick report: everything works fine, the smooth scrollbar is done, but i have a little difficulty with the stepped bar, exacly SHE DONT want to step to the last position, so i never got the last line in the treeview...
i'm work on this recalcitrant bar...
:rolleyes:
Jim
done. :)
well.. now im going to smoke then ill post the stuff :D
*Jim feels the cosmic powah in his hands "III CCAAANN DOOO EEVVRRYYTTHHIINNGG!!!" *
just kidding :)
here's the code, i think its done... mousewheel, keypress, scrollbar... try them out :)
Peace,
Jim.
I think that is really cool.
MouseWheel doesn't work as expected on my system.
if you can use the wheel on a listbox, then it will work, because theres no any other mousewheel mapping...Quote:
Originally posted by Mc Brain
MouseWheel doesn't work as expected on my system.
:)
pls check out how it works, i cant tell to you (my poor english :X )..
Jim.
I don't know if it works.... because I would need to change the code (subclass the ListView) to be able to see it. See this forum and you will understand what's my problem with the wheel.
http://www.vbforums.com/showthread.p...hreadid=175944
Anyway.. I resized the LV a little narrower and see it's working. :D
This was looking / working pretty good anyone ever finish / fix all the glitches?
So it seems.
Could i have an updated example with all the problems fixed?
like did u ever get it scrolling as mint as winamps?:ehh:
thanks :afrog:
This is the last example I have. In the main program, might have a better tune up after this last modification (can't remember).