当panel的AutoScroll属性为false时,没有滚动条,图形很对称当panel的AutoScroll属性为true时,有滚动条,图形变了,线条乱七八糟,不对齐
请问,是什么原因?如何解决?

解决方案 »

  1.   

    panel1.HorizontalScroll.Visible = false;//横的
      panel1.VerticalScroll.Visible = false;//竖的 
      

  2.   

    把你的Panel控制到刚好容下所有控件,设置滚动条每步滚动的像素点。调整到合适大小。如果你的Panel宽度固定的话,可以用%试试 
      

  3.   

    代码是这样的,麻烦帮忙看一下 ,把Panel的AutoScroll属性设置为turepublic partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                Label label;
                int a = -10;
                for (int i = 0; i < 1000; i++)
                {
                    label = new Label(); 
                    label.Height = 72; 
                    label.Width = 10;
                    label.Top = 0;
                    label.Name = "label" + i.ToString();
                    a += 10;
                    label.Left = a;
                    panel1.HorizontalScroll.Visible = false;
                    label.Click += buttonN_Click;
                    label.BackColor = Color.Transparent;
                    this.panel1.Controls.Add(label);   
                }            
            }
           // 画直线
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                int a = -10;
                Graphics graphics = e.Graphics;
                Pen pen1 = new Pen(Color.Gray, 1);
                Point point1 = new Point();
                Point point2 = new Point();
                for (int i = 0; i < 1000; i++)
                {
                    a += 10;
                    point1.X = a;
                    point1.Y = 0;
                    point2.X = a;
                    point2.Y = 3000;
                    graphics.DrawLine(pen1, point1, point2);
                }
                graphics.DrawLine(pen1, 0, 0, 2000, 0);
                graphics.DrawLine(pen1, 0, 72, 2000, 72);
             }               
        }
      

  4.   

    等待答案,我试了一下,把Form窗口最小化,然后恢复,图形又正常了...啥原因
      

  5.   

    请问,造成这种情况,是不是下面的线条重绘了,而上面的label没有重绘
      

  6.   


    // 画直线
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                for (int i = 0; i < this.panel1.Controls.Count; i++)
                {
                    Label lb = this.panel1.Controls[i] as Label;
                    if (lb == null)
                        continue;
                    e.Graphics.DrawLine(new Pen(Brushes.Black), lb.Location.X, lb.Location.Y,
                        lb.Location.X, 3000);
                }
                e.Graphics.DrawLine(new Pen(Brushes.Black), 0, 0, 2000, 0);
                e.Graphics.DrawLine(new Pen(Brushes.Black), 0, 72, 2000, 72);
            }