ScrollBar.Maximum Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit la limite supérieure des valeurs de la plage de défilement.
public:
property int Maximum { int get(); void set(int value); };
public int Maximum { get; set; }
member this.Maximum : int with get, set
Public Property Maximum As Integer
Valeur de propriété
Valeur numérique. La valeur par défaut est 100.
Exemples
L’exemple suivant part du principe que vous avez créé un Form, ajouté un PictureBox à celui-ci Formet ajouté un horizontal HScrollBar et un vertical VScrollBar à l’objet PictureBox. Cet exemple de code fait partie d’un exemple plus large fourni pour la vue d’ensemble de la ScrollBar classe.
Dans cet exemple, la Maximum propriété est définie sur la taille de la Image plus la taille de la barre de défilement si elle est visible plus un facteur d’ajustement de la taille de la LargeChange propriété.
Vous devez ajouter des références aux espaces de noms et System.Windows.Forms aux System.Drawing espaces de noms pour exécuter cet exemple.
Note
Pour obtenir des instructions sur l’exécution de cet exemple dans Visual Studio, consultez Guide pratique pour compiler et exécuter un exemple complet de code Windows Forms à l’aide de Visual Studio.
public void SetScrollBarValues()
{
//Set the following scrollbar properties:
//Minimum: Set to 0
//SmallChange and LargeChange: Per UI guidelines, these must be set
// relative to the size of the view that the user sees, not to
// the total size including the unseen part. In this example,
// these must be set relative to the picture box, not to the image.
//Maximum: Calculate in steps:
//Step 1: The maximum to scroll is the size of the unseen part.
//Step 2: Add the size of visible scrollbars if necessary.
//Step 3: Add an adjustment factor of ScrollBar.LargeChange.
//Configure the horizontal scrollbar
//---------------------------------------------
if (this.hScrollBar1.Visible)
{
this.hScrollBar1.Minimum = 0;
this.hScrollBar1.SmallChange = this.pictureBox1.Width / 20;
this.hScrollBar1.LargeChange = this.pictureBox1.Width / 10;
this.hScrollBar1.Maximum = this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width; //step 1
if (this.vScrollBar1.Visible) //step 2
{
this.hScrollBar1.Maximum += this.vScrollBar1.Width;
}
this.hScrollBar1.Maximum += this.hScrollBar1.LargeChange; //step 3
}
//Configure the vertical scrollbar
//---------------------------------------------
if (this.vScrollBar1.Visible)
{
this.vScrollBar1.Minimum = 0;
this.vScrollBar1.SmallChange = this.pictureBox1.Height / 20;
this.vScrollBar1.LargeChange = this.pictureBox1.Height / 10;
this.vScrollBar1.Maximum = this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height; //step 1
if (this.hScrollBar1.Visible) //step 2
{
this.vScrollBar1.Maximum += this.hScrollBar1.Height;
}
this.vScrollBar1.Maximum += this.vScrollBar1.LargeChange; //step 3
}
}
Public Sub SetScrollBarValues()
'Set the following scrollbar properties:
'Minimum: Set to 0
'SmallChange and LargeChange: Per UI guidelines, these must be set
' relative to the size of the view that the user sees, not to
' the total size including the unseen part. In this example,
' these must be set relative to the picture box, not to the image.
'Maximum: Calculate in steps:
'Step 1: The maximum to scroll is the size of the unseen part.
'Step 2: Add the size of visible scrollbars if necessary.
'Step 3: Add an adjustment factor of ScrollBar.LargeChange.
'Configure the horizontal scrollbar
'---------------------------------------------
If (Me.hScrollBar1.Visible) Then
Me.hScrollBar1.Minimum = 0
Me.hScrollBar1.SmallChange = CInt(Me.pictureBox1.Width / 20)
Me.hScrollBar1.LargeChange = CInt(Me.pictureBox1.Width / 10)
Me.hScrollBar1.Maximum = Me.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width 'step 1
If (Me.vScrollBar1.Visible) Then 'step 2
Me.hScrollBar1.Maximum += Me.vScrollBar1.Width
End If
Me.hScrollBar1.Maximum += Me.hScrollBar1.LargeChange 'step 3
End If
'Configure the vertical scrollbar
'---------------------------------------------
If (Me.vScrollBar1.Visible) Then
Me.vScrollBar1.Minimum = 0
Me.vScrollBar1.SmallChange = CInt(Me.pictureBox1.Height / 20)
Me.vScrollBar1.LargeChange = CInt(Me.pictureBox1.Height / 10)
Me.vScrollBar1.Maximum = Me.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height 'step 1
If (Me.hScrollBar1.Visible) Then 'step 2
Me.vScrollBar1.Maximum += Me.hScrollBar1.Height
End If
Me.vScrollBar1.Maximum += Me.vScrollBar1.LargeChange 'step 3
End If
End Sub
Remarques
Vous pouvez envisager d’ajuster la Maximum propriété de manière dynamique pour qu’elle corresponde à la taille du parent de la barre de défilement en proportion à la taille de pixels ou au nombre de lignes ou de lignes affichées.
La valeur maximale ne peut être atteinte que par programmation. La valeur d’une barre de défilement ne peut pas atteindre sa valeur maximale par le biais de l’interaction utilisateur au moment de l’exécution. La valeur maximale qui peut être atteinte par le biais de l’interaction utilisateur est égale à 1 plus la Maximum valeur de propriété moins la valeur de LargeChange propriété. Si nécessaire, vous pouvez définir la Maximum propriété sur la taille de l’objet -1 pour tenir compte du terme 1.