[2005] Panel roll up/down ideas
Hi All,
I have created a few corner-rounded gradient panels that replicate the XP 'MyComputer' (left hand menu items) theme.
I can currently click on the panel title (a Label) and the panel retracts up to the bottom of the Label. No problem here except I would like it to progressively (scroll) shrink up (and down if re-clicked) as the panels in the XP theame does.
I guess I could use a Timer, and reduce the .Height property but I was curious if there is a better idea someone has come up with ;)
Cheers 'n' Beers,
Re: [2005] Panel roll up/down ideas
Just a guess but maybe try a loop and decrease the height every loop.
Re: [2005] Panel roll up/down ideas
Hi Troy,
Yep, thats another option. But I would pause during that loop so it takes about 0.5 sec to roll up etc.
Re: [2005] Panel roll up/down ideas
Ok, this seems to work. I would appreciate feedback/criticism etc.... ;)
vb Code:
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
' Note: The second Parameter could (should) be captured at Form_Load in a varable for example
Roll_Panel(Panel1, 100, Label1.Height, 1)
End Sub
Private Sub Roll_Panel(ByRef pnl As Panel, ByVal intOriginalPanelHeight As Integer, ByVal intLabelHeight As Integer, ByVal intDelay As Integer)
If pnl.Height <> intLabelHeight Then
Do Until pnl.Height <= intLabelHeight
pnl.Height -= 1
Threading.Thread.Sleep(intDelay)
pnl.Refresh()
Loop
Else
Do Until pnl.Height >= intOriginalPanelHeight
pnl.Height += 1
Threading.Thread.Sleep(intDelay)
pnl.Refresh()
Loop
End If
End Sub
Re: [2005] Panel roll up/down ideas
The main problem I see is that you are telling your UI thread to sleep. This may not be an issue if the delay is low enough, though.
Instead of using <= and >= just use =, since your increment (or decrement) is only one pixel.
Another thought is since you are sleeping for 1 millisecond and the panel is only 100 pixels high, this would mean it would take 100 milliseconds to complete. If it takes longer than this then your code is slowing down. It is not bad that your code slows the process, but on a faster computer the same process might take less time.
Those are just thoughts.
Re: [2005] Panel roll up/down ideas
I don’t see why you don’t want to use Timer component. The problem with the current code is that you use Thread.Sleep in the same thread so your app is being frozen during that time. But Timer is a separate thread so it does a better performance. Bottom of the line they both do the same.
Re: [2005] Panel roll up/down ideas
Quote:
Originally Posted by Bruce Fox
Ok, this seems to work. I would appreciate feedback/criticism etc.... ;)
vb Code:
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
' Note: The second Parameter could (should) be captured at Form_Load in a varable for example
Roll_Panel(Panel1, 100, Label1.Height, 1)
End Sub
Private Sub Roll_Panel(ByRef pnl As Panel, ByVal intOriginalPanelHeight As Integer, ByVal intLabelHeight As Integer, ByVal intDelay As Integer)
If pnl.Height <> intLabelHeight Then
Do Until pnl.Height <= intLabelHeight
pnl.Height -= 1
Threading.Thread.Sleep(intDelay)
pnl.Refresh()
Loop
Else
Do Until pnl.Height >= intOriginalPanelHeight
pnl.Height += 1
Threading.Thread.Sleep(intDelay)
pnl.Refresh()
Loop
End If
End Sub
If you want to use this method, you'd need to modify it to run in a thread, so the application doesnt look "frozen" during the sleeping.
Re: [2005] Panel roll up/down ideas
Thanks for the replies guys.
The time it takes is small, and the UI freeze is negligible in this case - However, there is room for improvement.
VBDT, I may try a Timer as a different method too - will be good to compare.
At least using a Timer will also allow use on a different machine with different specs.
I will remove the <> as I was experimenting with values. They can go as it's one pixel as mentioned.
Thanks again all for your input.
Re: [2005] Panel roll up/down ideas
Sup Bruce! Long time no see.
I have done this already and ran into an issue with using a timer. You accidentally double click or click again before the "animation scroll" is completed it will queue the click and look stupid lol.
Have you tried searching the forums for my threads on my XP Nav Panel control?
Re: [2005] Panel roll up/down ideas
Hey Rob,
I emailed you a about four weeks ago - not sure if it got thru I used my work email.
I haven't looked for that Nav Panel, but will now tho.
I remember you did something like this a few years back, and I did find some classes that helped.
I wasthinking of a timer, and a flag that would prevent any additional operations. Never the less, I will look for your Nav Panel.
Hope all is well your way ;)
Re: [2005] Panel roll up/down ideas
Thanks, things are ok and hope they are good with you as well. Didnt get the email.
I just remembered that I had a performance issue too because of resizing the panel. Not just one panel but when I had multiple panels. Say you collapsed the top one, well when you resize it you have to move the other ones up like it works in XP. I had too many steps in the timer resizing it by 4-8 pizels at a time. Best scenerio is to resize it by 1/2-1/3 steps so its allot less intense.
Using a boolean flag to make a click will work to prevent wueueing of clicks I think.
Re: [2005] Panel roll up/down ideas
In your case you built a user control (from recent memory).
I will just have 3 collapsible panels, that are gradient, and rounded (that part done); just working on the collapsing side of the house. Having said that the code I posted above does the trick. Out of all this I came across XPCC (XP Common Controls) that jmcilhinney referenced - just trying to decipher how to implement the classes..... ;)
Edit: No need to decipher etc once you download the right bloody thing... :rolleyes: ;)
Any one else tried XPCC?
Have a great weekend all.
Re: [2005] Panel roll up/down ideas
Nope, but I heard something about some minor issues with it.
Have you looked at vbaccelerator's site where they have a good similar XP nav control?
I started out doing what your doing with a grouping of controls and then I found I was going to need it on other forms so I figured it would be worht creating the UC. But little did I know how deep I would get into it :lol:
Re: [2005] Panel roll up/down ideas
I could imagine.
I have been playing with the 'XpTaskBox' from the XPCC items - nice (but I have already done most of it - but for a simple adding of a reference may be worth it). That said it seems to be a great one stop shop!
One thing that I realized I could improve in the code snippet I posted was to sleep and refresh based on Mod - every 2 or 3rd iteration; that keeps the speed up etc. This came about from collapsing the panel up to the one above that was collapsed.
I will now continue a look into the 'XP nav control'. - cheers ;)
Re: [2005] Panel roll up/down ideas
Hmmm, seems the only thing available now from vbaccelerator (circa 2004) is the '.NET ExplorerBar Control'.
Not to worry, I think I'm good - it's an app for me in any case (famous last words right ;) ).
Re: [2005] Panel roll up/down ideas
Yes, that was what it was called. Yes, its VB 6 but its a very very close duplication of the original windows control.