无法在面板中显示垂直滚动条 [英] Could not show vertical scrollbar in panel

查看:123
本文介绍了无法在面板中显示垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用户控件或窗体中有一个面板可以绘制曲线.绘图宽度和高度的区域大于面板的尺寸.我将AutoScroll = true设置为AutoScrollMinSize = panel1.Size(原始尺寸,即400X400).但是滚动条不会显示.此外,我将面板尺寸设置为更大的尺寸,即800X800.并保持AutoScrollMinSize = 400X400.滚动条仍然不出现.

有什么事吗

谢谢!


谢谢你的建议!

我创建了一个Windows窗体项目,并向该窗体添加了一个面板.然后,我添加了一个panel.Paint事件.在paint事件处理程序中,我画了一个比面板大的圆.

I have a panel in a user control or form to draw curves. The area of drawing width and height is larger the size of the panel. I set the AutoScroll = true, AutoScrollMinSize = panel1.Size (original size, i.e. 400X400). But the scroll bar does not show up. Further, I set the panel size to larger size, i.e. 800X800. And keep the AutoScrollMinSize = 400X400. The scroll bar still does not appear.

What could be wrong?

Thanks!


Thanks for the suggestion!

I created a windows form project and added a panel to the form. Then I added an event of panel.Paint. In the paint event handler, I draw a circle larger than the panel size.

panel.AutoScroll=true;
panel.AutoScrollMinSize = new Size(504,337);


圆的矩形大小为(800,800).没有滚动条显示.此外,我在保持AutoScrollMinSize不变的同时设置了panel.Size = new Size(504, 900).仍然没有滚动条.


The circle''s rectangle size is (800, 800). No scroll bar is displayed. Further, I set the panel.Size = new Size(504, 900) while keeping AutoScrollMinSize unchanged. There is still no scroll bar.

   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
           panel1.AutoScrollMinSize = new System.Drawing.Size(panel1.Size.Width,
                                                              panel1.Size.Height);
//           panel1.Size = new System.Drawing.Size(panel1.Size.Width, 900);
           panel1.Paint += new PaintEventHandler(panel1_Paint);
       }
       void panel1_Paint(object sender, PaintEventArgs e)
       {
           Pen penDraw = new Pen(new SolidBrush(Color.Black));
           Rectangle rectDraw = new Rectangle(0, 0, 800, 800);
           e.Graphics.DrawArc(penDraw, rectDraw, 0.0f, 360.0f);
       }
   }


[/Edit]


[/Edit]

推荐答案

您可能会误解自动滚动.
解释如下: http://www.bobpowell.net/understanding_autoscroll.htm [
然后,AutoScrollMinSize应该大于Panel.Size.例如,如果它是宽度"和高度"的两倍大,则其行为就像您有一个4倍的虚拟"绘画区域,然后可以在固定的滚动位置立即看到该区域.

最后,自动滚动旨在滚动面板上的子级,而不是渲染的图形.当您实现所需的功能时,滚动时会弄乱您的图形,因为滚动不会使您的面板无效.如果处理事件Scroll.Scroll(如您应做的那样),则图形...将不会随着滚动而移动,而是停留在同一位置.要变通,您也可以移动渲染数据,但效果不佳.自己看:

You probably misunderstand Auto-scroll.
Here is the explanation: http://www.bobpowell.net/understanding_autoscroll.htm[^].

First, in case you hope Auto-scroll takes into account the bounding size of your rendered graphics: it won''t. The panel will clip it exactly in the same way as without Auto-scroll; you reasoning "The circle''s rectangle size is (800, 800)".

Then, AutoScrollMinSize should be more than Panel.Size. For example, if it is twice big as in Width and Height, it behaves like you have a 4-fold "virtual" paint area then the area you can see at once, at fixed scroll position.

Finally, Auto-scroll is designed to scroll children on your panel, not your rendered graphics. When you implement what you want, your graphics will be messed up when you scroll, because scroll does not invalidate you panel. If your handle the event Scroll.Scroll (as you should), you graphic... will not be moved with scroll, it be staying in the same place. To work around, you could move your rendering data as well, which in not effective. Look by yourself:

panel1.Width = 100;
//will scroll, but rendering... not as you expected!
panel1.Height = 100;
panel1.AutoScroll = true;
panel1.AutoScrollMinSize = new Size(200, 200);
panel1.Paint += (sender, ev) => {
   ev.Graphics.FillEllipse(Brushes.Red, new Rectangle(10, 10, 20, 40));
};
panel1.Scroll += (sender, ev) => {
//panel1.Invalidate();
};



这不是解决该问题的方式.同样,自动滚动旨在滚动面板上的子面板,因此您需要放置一个比父面板更大的子面板.然后,您应该在较大的子面板上进行图形渲染,但滚动较小的父面板.我做到了,它奏效了.

—SA



This is not how such problem should be solved. Again, Auto-scroll is designed to scroll children on your panel, so you need put a child panel of bigger size than you parent panel. Then you should do you graphic rendering on bigger child panel but scroll a smaller parent panel. I did, it worked.

—SA


自动滚动正在检测Panel.Controls集合中控件的区域.当您仅在面板上绘制时,它不会在其Controls集合中检测到该绘图.您将需要添加某种用户控件以用作画布来进行绘制,该画布将重新调整自身大小以完全包含您的图形,然后该用户控件的区域可以触发面板.
The auto-scroll is detecting the region of the controls in the Panel.Controls collection. When you just draw on the panel it doe not detect that drawing in its Controls collection. You will need to add some kind user control to act as a canvas to draw on that will re-size itself to fully contain your drawing, then the region of that user control can trigger the panel.


这篇关于无法在面板中显示垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆