4

I have a label inside a panel. When the text exceeds, the label text should wrap. For doing that I have set mylabel's AutoSize = false and MaximumSize = 100,0.

Now since the text is being wrapped, vertical scrollbar should appear on panel. But that's not happening, please specify what I am missing here. Is it possible this way or should I explicitly add a vertical scrollbar inside the panel?

DotNet Coder
  • 51
  • 1
  • 1
  • 6

4 Answers4

2

1) You need to put the label inside the panel

2) AutoSize for label should be TRUE

3) AutoSize for panel should be FALSE

4) AutoScroll for panel should be True

that is it!

enter image description here

Nima Soroush
  • 12,242
  • 4
  • 52
  • 53
  • If you don't want a horizontal scroll bar to potentially show. Set the Anchor for the label to Top only. If you leave it as the default 'Top, Left' then the label could potentially scroll left. Just something to be aware of – SandstormNick May 09 '23 at 07:02
0

Did you have the properties Scrollable=true or AutoScroll?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.scrollbars.aspx

Try this:

ScrollBar vScrollBar1 = new VScrollBar();
vScrollBar1.Dock = DockStyle.Right;
vScrollBar1.Scroll += (sender, e) => { panel1.VerticalScroll.Value = vScrollBar1.Value; };
panel1.Controls.Add(vScrollBar1);
Alice
  • 313
  • 2
  • 5
  • 16
  • Thanks Alice, but I require to scroll the panel and not the individual label. – DotNet Coder Apr 17 '13 at 08:14
  • This one then: http://stackoverflow.com/questions/6090558/add-vertical-scroll-bar-to-panel and check too if you have a autoscroll properties in your panel maybe? Check this site too: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.scrollbars.aspx – Alice Apr 17 '13 at 08:16
  • 1
    no, I dont think Adding a vertical scrollbar explicitly is a gud option. – DotNet Coder Apr 18 '13 at 10:39
0

You should be setting AutoSize to true to automatically wrap. For the scrollbars check that you set panel.VerticalScroll.Visible = true;

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
  • panel.VerticalScroll.Visible = true; and AutoSize to true also didnt help – DotNet Coder Apr 17 '13 at 10:04
  • Try `panel.Invalidate();` and see if it gets properly resized to show the scrollbars. Also consider replacing your panel with a `FlowLayoutPanel`. You could try adding it manually as well. See [this answer](http://stackoverflow.com/a/6090611/612717). – Chibueze Opata Apr 17 '13 at 10:21
  • I had tried FlowLayoutPanel also, but it only lets d user add controls in a particular direction(left to right or top to down) only. What to write in panel.Invalidate()? – DotNet Coder Apr 17 '13 at 10:30
  • Sorry, but what does your panel contain exactly? If your panel is panel1, then write `panel1.Invalidate();` – Chibueze Opata Apr 17 '13 at 10:59
  • Chibueze my Panel contains 3 labels.. So when the data exceeds their width, the text of gets wrapped. Now All I want is to add a vertical scrollbar to view the entire contents of other labels.. – DotNet Coder Apr 17 '13 at 12:53
0

It's long time ago about this question. Solution :

  1. Panel1.AutoScroll = True

  2. Label1.AutoSize = True

  3. Label1.MaximumSize = New Size(Panel1.ClientRectangle.Width - 18, 0)

Impotrant thing is to define MaximumSize for Label width. Height leave 0 (zero). Height will grow with label content.

In this case, maximum width of label would be width of panel - 18px for scroller.

nelek
  • 4,074
  • 3
  • 22
  • 35