我想做一个winform滚动条,要求只在窗体中间的位置滚动,不超出窗体。希望大家帮帮忙。我自己写了一个。但是它是不是在窗体中间滚动。代码如下;
  private void timer2_Tick(object sender, EventArgs e)
        {
            lblScoll.Left = lblScoll.Left - 5;
            if (lblScoll.Left <= -lblScoll.Width )
            {
                lblScoll.Left = this.Width;
            }
        }

解决方案 »

  1.   

    参考:  
    private   void   UserPictureBox_Paint(object   sender,   System.Windows.Forms.PaintEventArgs   e)   
      {   
            Graphics   g   =   e.Graphics;   
            g.FillRectangle(Brushes.White,this.ClientRectangle);   
            if   (TheImage   !=   null)   
              {     
                    //   Draw   the   Image   Offset   by   the   scroll   positions   inside   the   Client   Rectangle   
                  g.DrawImageUnscaled(TheImage,   -OffsetX,   -OffsetY,   TheImage.Width,   TheImage.Height);   
        
                //     Draw   a   little   gray   rectangle   in   the   portion   of   the   control   where   the   two   scrollbars   touch   
                    g.FillRectangle(Brushes.Gray,   ClientRectangle.Width   -   vScrollBar1.Width,     
                    ClientRectangle.Height   -   hScrollBar1.Height,   vScrollBar1.Width,   hScrollBar1.Height);   
              }   
        
      }