-
November 24th, 2008, 11:26 AM
#1
Scroll Bars for a User Control
I created a user control with scroll bars by inheriting from Panel
Code:
Public Class MyUseControl
Inherits Panel
...
This works. However, the control doesn't update while dragging the bar up and down. How do I get it do that? Also, is their a better way to add scrollbars to a user control then this method?
Also, how do I get it to move up and down with the scroll wheel on the mouse?
Thanks,
-
November 24th, 2008, 12:00 PM
#2
Re: Scroll Bars for a User Control
You might be better off inheriting the basic control... System.Windows.Forms.UserControl and setting the AutoScroll property to true.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
November 24th, 2008, 03:24 PM
#3
Re: Scroll Bars for a User Control
Oh, I used the wrong word. I meant custom control not user control. Every article I read to research this talked about user controls not custom controls so that got stuck in my mind.
I went with a custom control because I have plans to put it in a dll and resuse it.
The custom control doesn't have an autoscroll property. So I had to find another way to have scroll bars.
I decided to try it as a user control. I had previously gotten scrolling with the mouse wheel to work but now it won't when I do it as a user control. To get it to work before I had to handle the mouse click event and call Focus(). Now this doesn't work because I can't get the user control to accept focus.
I think I'll stick with the custom control approach since I plan to reuse it and all the content is created at runtime.
In any case, none of this did anything to get the content to update while dragging the scrollbar. Any suggetions on how to do that.
Thanks,
-
November 24th, 2008, 04:58 PM
#4
Re: Scroll Bars for a User Control
Hang on...how was it not a user control if you inherit from Panel? Unless the panel class is derived from another source, it should at some point inherit the UserControl base class.
As for how to get it updated, it depends on what's on it...
The biggest question is this: are you painting your data, or using controls? If you're painting, the scroll should also trigger the Paint event (if a new region is exposed).
If you're working with controls with the autoscroll property on your control set to true, then they should position automatically.
Out of interest, what is it you're actually programming?
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
November 25th, 2008, 01:02 AM
#5
Re: Scroll Bars for a User Control
Why not use the ScrollableControl class ¿
I've got component ( DLL ) which displays Thumbnails, and based on ScrollaleControl, scrolling becomes easy.
have a look here :
http://msdn.microsoft.com/en-us/libr...lecontrol.aspx
-
November 25th, 2008, 09:28 AM
#6
Re: Scroll Bars for a User Control
I'm not really sure what the real difference is between the two. Maybe just how Visual Studio works with them. However, as a custom control. Things seems to work better.
As for what I'm actually programming, it's basically a GridView but the controls for editing data will be determined by the data type. For example, a check box for boolean. There'll be options to provide a list for columns so you can have a drop down for certain fields. Plus more as I think of it. I've done several apps already that would benefit from have a nice control like this. However, I'm starting out with a control hard coded for the specific application I'm working on. I'll add in the reflection in the next version.
Currently, the controls I'm using are labels and numeric up/downs. I'm not currently doing any any actually drawing in OnPaint().
Back to scrolling, all the content is positioned correctly. When I scroll they all move to the correct position. The only problem is while I'm dragging the scroll bar the content doesn't move. I would like to get that to work since visually it would look a lot nicer.
Thanks,
-
November 25th, 2008, 09:34 AM
#7
Re: Scroll Bars for a User Control
Technically, I am using ScrollableControl since Panel inherits from it. I would say inheriting from Panel is an easier way to get scrolling since it does everything for you. If I inherited from ScrollableControl I'd have to calculate the size of the content area everytime I change the content, calculate min/max, calculate large/small scroll values, etc. If I can somehow get smooth scrolling while dragging the scroll bar by doing this I will. Can you tell me if the control you created updates while dragging the scroll bar?
Thanks
-
November 26th, 2008, 07:58 AM
#8
Re: Scroll Bars for a User Control
You are correct in saying that the Panel inherits from ScrollableControl, no issues there
I'm attaching a slightly modified version of something similar I found on the net, have a look at it - there are no issues ( that I could find ) with the scrolling.
You may need to set the reference to the DLL though.
I hope it helps, even if it is just a little
Last edited by HanneSThEGreaT; June 14th, 2010 at 05:39 AM.
-
December 1st, 2008, 01:00 PM
#9
Re: Scroll Bars for a User Control
Thanks, however, this sample app also doesn't have the smooth scrolling I'm looking for. However, I've figured out is causing the issue. I just need to figure out how to deal with it. Basically, I remote into a dev server to do all my programming. This way I can work from anywhere. It seems somehow remote desktop causes smooth scrolling to not work in both my app and in that sample app. When I run these programs outside of remote desktop they work fine.
I know it's possible to get smooth scrolling from withen remote desktop since visual studio has it, explorer has it, well pretty much every program I've testing works in remote desktop. Do you have any suggestions on how to get scrolling to work how I want it to.
Thanks,
-
December 1st, 2008, 03:08 PM
#10
Re: Scroll Bars for a User Control
Might it be to do with the way VB generates it's paint events? I think that you'll find that every other program you've listed will have been written in a (slightly) lower-level language...
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|