Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ScrollBar.Maximum Property

Gets or sets the upper limit of values of the scrollable range.

[Visual Basic]
Public Property Maximum As Integer
[C#]
public int Maximum {get; set;}
[C++]
public: __property int get_Maximum();
public: __property void set_Maximum(int);
[JScript]
public function get Maximum() : int;
public function set Maximum(int);

Property Value

A numeric value. The default value is 100.

Remarks

You might consider adjusting the Maximum property dynamically to match the size of the scroll bar's parent in proportion to pixel size or to the number of rows or lines displayed.

Note   The value of a scroll bar cannot reach its maximum value through user interaction at run time. The maximum value that can be reached is equal to the Maximum property value minus the LargeChange property value plus one. The maximum value can only be reached programmatically.

Example

[Visual Basic, C#, C++] The following example uses the derived classes VScrollBar and HScrollBar, and sets some of their common properties. Their Maximum properties are set equal to the height or width of the Image assigned to their parent, a PictureBox. The LargeChange property is set equal to the size of the picture box (with the height or width of the scroll bars subtracted). The SmallChange property is set equal to the LargeChange property value divided by five. Lastly, the Value property values for both of the scroll bars are set to 0. The result is vertical and horizontal scroll bars displayed on a picture box that displays the upper-left corner of the Image. The scroll bars will not scroll past the end of the image, and when a LargeChange scroll happens, the image will only move the same distance as the area displayed in the picture box. It takes five SmallChange scrolls to move the same distance as one LargeChange scroll. This code assumes a PictureBox, HScrollBar, VScrollBar, and Image have all been created on a Form. It also assumes that a reference to the System.Drawing namespace has been added. For additional code that can extend this example, see the ScrollBar class overview.

[Visual Basic] 
Public Sub SetScrollBarValues()
   ' Set the Maximum, Minimum, LargeChange and SmallChange properties.
   Me.vScrollBar1.Minimum = 0
   Me.hScrollBar1.Minimum = 0
   
   ' If the offset does not make the Maximum less than zero, set its value.
   If Me.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width > 0 Then
      Me.hScrollBar1.Maximum = Me.pictureBox1.Image.Size.Width - _
        pictureBox1.ClientSize.Width
   End If
   ' If the VScrollBar is visible, adjust the Maximum of the 
   ' HSCrollBar to account for the width of the VScrollBar.
   If Me.vScrollBar1.Visible Then
      Me.hScrollBar1.Maximum += Me.vScrollBar1.Width
   End If
   Me.hScrollBar1.LargeChange = Me.hScrollBar1.Maximum / 10
   Me.hScrollBar1.SmallChange = Me.hScrollBar1.Maximum / 20
   ' Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   Me.hScrollBar1.Maximum += Me.hScrollBar1.LargeChange
         
   ' If the offset does not make the Maximum less than zero, set its value.
   If Me.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height > 0 Then
      Me.vScrollBar1.Maximum = Me.pictureBox1.Image.Size.Height - _
        pictureBox1.ClientSize.Height
   End If
   ' If the HScrollBar is visible, adjust the Maximum of the 
   ' VSCrollBar to account for the width of the HScrollBar.
   If Me.hScrollBar1.Visible Then
      Me.vScrollBar1.Maximum += Me.hScrollBar1.Height
   End If
   Me.vScrollBar1.LargeChange = Me.vScrollBar1.Maximum / 10
   Me.vScrollBar1.SmallChange = Me.vScrollBar1.Maximum / 20
   ' Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   Me.vScrollBar1.Maximum += Me.vScrollBar1.LargeChange
End Sub

[C#] 
public void SetScrollBarValues() 
{
   // Set the Maximum, Minimum, LargeChange and SmallChange properties.
   this.vScrollBar1.Minimum = 0;
   this.hScrollBar1.Minimum = 0;
   // If the offset does not make the Maximum less than zero, set its value. 
   if( (this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width) > 0)
   {
      this.hScrollBar1.Maximum = this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width;
   }
   /* If the VScrollBar is visible, adjust the Maximum of the 
      HSCrollBar to account for the width of the VScrollBar. */
   if(this.vScrollBar1.Visible)
   {
      this.hScrollBar1.Maximum += this.vScrollBar1.Width;
   }
   this.hScrollBar1.LargeChange = this.hScrollBar1.Maximum / 10;
   this.hScrollBar1.SmallChange = this.hScrollBar1.Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this.hScrollBar1.Maximum += this.hScrollBar1.LargeChange;
     
   // If the offset does not make the Maximum less than zero, set its value.    
   if( (this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height) > 0)
   {
      this.vScrollBar1.Maximum = this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height;
   }
   /* If the HScrollBar is visible, adjust the Maximum of the 
      VSCrollBar to account for the width of the HScrollBar.*/
   if(this.hScrollBar1.Visible)
   {
      this.vScrollBar1.Maximum += this.hScrollBar1.Height;
   }
   this.vScrollBar1.LargeChange = this.vScrollBar1.Maximum / 10;
   this.vScrollBar1.SmallChange = this.vScrollBar1.Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this.vScrollBar1.Maximum += this.vScrollBar1.LargeChange;
}

[C++] 
public:
void SetScrollBarValues() 
{
   // Set the Maximum, Minimum, LargeChange and SmallChange properties.
   this->vScrollBar1->Minimum = 0;
   this->hScrollBar1->Minimum = 0;
   // If the offset does not make the Maximum less than zero, set its value. 
   if( (this->pictureBox1->Image->Size.Width - pictureBox1->ClientSize.Width) > 0)
   {
      this->hScrollBar1->Maximum = this->pictureBox1->Image->Size.Width - pictureBox1->ClientSize.Width;
   }
   /* If the VScrollBar is visible, adjust the Maximum of the 
      HSCrollBar to account for the width of the VScrollBar. */
   if(this->vScrollBar1->Visible)
   {
      this->hScrollBar1->Maximum += this->vScrollBar1->Width;
   }
   this->hScrollBar1->LargeChange = this->hScrollBar1->Maximum / 10;
   this->hScrollBar1->SmallChange = this->hScrollBar1->Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this->hScrollBar1->Maximum += this->hScrollBar1->LargeChange;
     
   // If the offset does not make the Maximum less than zero, set its value.    
   if( (this->pictureBox1->Image->Size.Height - pictureBox1->ClientSize.Height) > 0)
   {
      this->vScrollBar1->Maximum = this->pictureBox1->Image->Size.Height - pictureBox1->ClientSize.Height;
   }
   /* If the HScrollBar is visible, adjust the Maximum of the 
      VSCrollBar to account for the width of the HScrollBar.*/
   if(this->hScrollBar1->Visible)
   {
      this->vScrollBar1->Maximum += this->hScrollBar1->Height;
   }
   this->vScrollBar1->LargeChange = this->vScrollBar1->Maximum / 10;
   this->vScrollBar1->SmallChange = this->vScrollBar1->Maximum / 20;
   // Adjust the Maximum value to make the raw Maximum value attainable by user interaction.
   this->vScrollBar1->Maximum += this->vScrollBar1->LargeChange;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

ScrollBar Class | ScrollBar Members | System.Windows.Forms Namespace | Minimum

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft