[.net] Working with HScrollBar / VScrollBar

Started by
3 comments, last by Machaira 18 years ago
Hello developers. I'm trying to figure out how to connect ScrollBar. I'm painting something on the Form. This something is much bigger than a Form, thus I need a scrolling. I'm doing something like this(according to MSDN):

hScrollBar1 = new HScrollBar();
hScrollBar1.Minimum = 0;
hScrollBar1.Maximum = 1000;
hScrollBar1.Dock = DockStyle.Top;
   
// Add the scroll bar to the form.
Controls.Add(hScrollBar1); 


I cannot scroll the Form. I see my scrollbar, I can move it, but it has no influence on my form. Maybe Form is not scrollable, and I have to paint on some scrollable object ? Thanks in advance
Advertisement
The problem is that you haven't added event handlers for the scrollbars. They don't automatically do anything by themselves.

An alternative - drop a Panel on the form and set it's AutoScroll property to True. Add your controls to the Panel instead of the form.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Quote:Original post by Machaira
The problem is that you haven't added event handlers for the scrollbars. They don't automatically do anything by themselves.

An alternative - drop a Panel on the form and set it's AutoScroll property to True. Add your controls to the Panel instead of the form.


I still have nothing. I added few buttons and HScrollBar to panel. I also did autoscroll to panel. When I'm moving panel's scroll, buttons on panel are not moving :-( What to do

this is what I did:

1. Put panel with autoscroll = true
2. Add few buttons to panel
3.

vScrollBar1 = new VScrollBar();
vScrollBar1.Minimum = 0;
vScrollBar1.Maximum = 1000;
vScrollBar1.Dock = Dockstyle.Right;

//Add the scroll bar to the panel.
this.panel1.Controls.Add(vScrollBar1);


You don't need to say anything about scroll bars in your code. When the content of your panel exceeds the size of your panel, the scroll bars will just magically appear and you will be able to scroll. Hope that helps.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Guess I should have been more specific - by "controls" I meant buttons, textboxes, etc, not the scroll bars. [grin]

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

This topic is closed to new replies.

Advertisement