none
c# GDI + Panel AutoScroll Cracked Phenomenon RRS feed

  • Question


  •            being used

             

        base.ResizeRedraw = true;
                base.SetStyle(ControlStyles.DoubleBuffer, true);
                base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                base.SetStyle(ControlStyles.ResizeRedraw, true);    

        using (Pen objPen2 = new Pen(Color.Red, (10 * 2) - 2))
                    {
                         g.DrawLine(objPen2, new Point(0, 1), new Point(this.Width, 1));
                    }

                Broken phenomenon scroll using Draw lines to break.

                Answer Thank you.

    Monday, October 15, 2012 7:29 AM

Answers

  • Hi,

    you need to include the autoscrollposition of the panel into your calculation of the points describing the line:

        public partial class Form1 : Form
        {
            private System.Windows.Forms.Panel panel1;
            public Form1()
            {
                InitializeComponent();
    
                this.panel1 = new System.Windows.Forms.Panel();
    
                this.panel1.AutoScroll = true;
                this.panel1.Location = new System.Drawing.Point(58, 45);
                this.panel1.Name = "panel1";
                this.panel1.Size = new System.Drawing.Size(200, 100);
                this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
    
                this.ClientSize = new System.Drawing.Size(284, 262);
                this.Controls.Add(this.panel1);
    
                this.panel1.AutoScrollMinSize = new Size(this.panel1.Size.Width, 400);
            }
    
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                using (Pen objPen2 = new Pen(Color.Red, (10 * 2) - 2))
                {
                    e.Graphics.DrawLine(objPen2, new Point(0 + panel1.AutoScrollPosition.X, 1 + panel1.AutoScrollPosition.Y), 
                        new Point(this.Width + panel1.AutoScrollPosition.X, 1 + panel1.AutoScrollPosition.Y));
                } 
            }
        }

    Regards,

      Thorsten

    Monday, October 15, 2012 9:08 AM