views:

962

answers:

2

I need to allow a long label to be scrolled through on it's own. I do not want a text-box of any sort. I would like to be able to format the text inside. It definitely needs to scroll own its own, not with the window. I have added a scrollbar successfully, but I have no idea how to begin to use it's event/s.

thanks

i tried using a panel? I will again, perhaps I made an error. :: yeah I tried that again, it simply cuts off my label.

+2  A: 

Place the label inside a Panel and set AutoScroll to true.

Phoexo
A: 

Add a label (here label1) and a scrollbar (here hScrollBar1) and deal with the event in this fashion (assuming hScrollBar1.Maximum = 100 and hScrollBar1.Minimum = 0):

 private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
        const int labellength = 10;
        String thetext = "Ozzie ozzie ozzie! OI OI OI! And then some...";
        int offset = (int)((double)e.NewValue / 100 * (thetext.Length - labellength));
        label1.Text = thetext.Substring(offset, labellength);
    }

Naturally you would have to specify the 'amount' of text to appear in the label by changing labellength. If you find that you can not scroll to the very end, lower hScrollBar1.LargeChange to 1.

Aert
You can't declare a const inside a method.
Phoexo
Declaring a const in a method is perfectly valid. Therefore the example above compiles and runs just fine.
Aert