ScrollBar クラスとは? わかりやすく解説

ScrollBar クラス

スクロール バー コントロール基本機能実装ます。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public MustInherit Class
 ScrollBar
    Inherits Control
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public abstract class ScrollBar : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class ScrollBar abstract : public
 Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public abstract class ScrollBar extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public abstract class ScrollBar extends
 Control
解説解説
使用例使用例

PictureBox コントロールスクロール バーと垂直スクロール バー追加しコントロールDoubleClick イベント発生したときにピクチャ ボックスImage読み込むコード例次に示しますピクチャ ボックスダブルクリックすると、いつでも新しイメージ読み込むことができますイメージサイズコントロールより大きい場合は、スクロール バー表示されます。そのスクロール バースクロールして、コントロール内に収まらないイメージ表示させることができます。この例では、VScrollBarHScrollBar が端にドッキングされた PictureBoxForm 上に作成されていることを前提にしています。この例は、System.Drawing 名前空間への参照追加されていることも前提にしています。VScrollBarHScrollBar両方に対して HandleScroll メソッドScroll イベント ハンドラデリゲートとして設定されていることを確認してください。この例を拡張するための追加コードについては、LargeChangeSmallChangeMaximumMinimumValue の各メンバ参照してくださいスクロール バープロパティを、その親コントロールプロパティ基づいて設定することもできます。たとえば、Maximum の値を、PictureBox割り当てられImageHeight または Width の値に合わせて設定するメソッドを、この例に追加することもできますまた、LargeChange の値を PictureBox の高さまたは幅に設定します。なお、スクロール バーの高さまたは幅はこの値から差し引きます。この設定により、イメージ範囲越えてスクロールすることができなくなりLargeChange 値は、イメージ表示領域ピクチャ ボックス表示され領域と同じ距離だけ移動します

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms

Namespace Scrollbar
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Private WithEvents openFileDialog1
 As System.Windows.Forms.OpenFileDialog
        Private WithEvents pictureBox1 As
 System.Windows.Forms.PictureBox
        Private WithEvents vScrollBar1 As
 System.Windows.Forms.VScrollBar
        Private WithEvents hScrollBar1 As
 System.Windows.Forms.HScrollBar

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub InitializeComponent()
            Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
            Me.pictureBox1 = New System.Windows.Forms.PictureBox()
            Me.vScrollBar1 = New System.Windows.Forms.VScrollBar()
            Me.hScrollBar1 = New System.Windows.Forms.HScrollBar()
            Me.pictureBox1.SuspendLayout()
            Me.SuspendLayout()
            Me.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.pictureBox1.Controls.AddRange(New
 System.Windows.Forms.Control() _
            {Me.vScrollBar1, Me.hScrollBar1})
            Me.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.pictureBox1.Size = New System.Drawing.Size(440,
 349)
            Me.vScrollBar1.Dock = System.Windows.Forms.DockStyle.Right
            Me.vScrollBar1.Location = New System.Drawing.Point(422,
 0)
            Me.vScrollBar1.Size = New System.Drawing.Size(16,
 331)
            Me.vScrollBar1.Visible = False
            Me.hScrollBar1.Dock = System.Windows.Forms.DockStyle.Bottom
            Me.hScrollBar1.Location = New System.Drawing.Point(0,
 331)
            Me.hScrollBar1.Size = New System.Drawing.Size(438,
 16)
            Me.hScrollBar1.Visible = False
            Me.ClientSize = New System.Drawing.Size(440,
 349)
            Me.Controls.AddRange(New System.Windows.Forms.Control()
 _
                {Me.pictureBox1})
            Me.Text = "Form1"
            Me.pictureBox1.ResumeLayout(False)
            Me.ResumeLayout(False)
        End Sub

        <STAThread()> Shared Sub Main()
            Application.Run(New Form1())
        End Sub

        Private Sub pictureBox1_DoubleClick(ByVal
 sender As [Object], _
            ByVal e As EventArgs) _
          Handles pictureBox1.DoubleClick

            ' Open the dialog box so the user can select a new image.
            If openFileDialog1.ShowDialog() <> DialogResult.Cancel
 Then

                ' Display the image in the PictureBox.
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName)
                Me.DisplayScrollBars()
                Me.SetScrollBarValues()
            End If
        End Sub

        Private Sub Form1_Resize(ByVal
 sender As Object, _
            ByVal e As System.EventArgs) Handles
 MyBase.Resize

            ' If the PictureBox has an image, see if it needs
            ' scrollbars and refresh the image. 
            If Not (pictureBox1.Image Is
 Nothing) Then
                Me.DisplayScrollBars()
                Me.SetScrollBarValues()
                Me.Refresh()
            End If
        End Sub

        Public Sub DisplayScrollBars()

            ' If the image is wider than the PictureBox, show the HScrollBar.
            If pictureBox1.Width > pictureBox1.Image.Width
 - _
              Me.vScrollBar1.Width Then
                hScrollBar1.Visible = False
            Else
                hScrollBar1.Visible = True
            End If

            ' If the image is taller than the PictureBox, show the VScrollBar.
            If pictureBox1.Height > pictureBox1.Image.Height
 - _
              Me.hScrollBar1.Height Then
                vScrollBar1.Visible = False
            Else
                vScrollBar1.Visible = True
            End If
        End Sub

        Private Sub HandleScroll(ByVal
 sender As [Object], _
            ByVal se As ScrollEventArgs) _
          Handles vScrollBar1.Scroll, hScrollBar1.Scroll

            ' Create a graphics object and draw a portion 
            ' of the image in the PictureBox. 
            Dim g As Graphics = pictureBox1.CreateGraphics()

            g.DrawImage(pictureBox1.Image, _
                New Rectangle(0, 0, pictureBox1.Right - vScrollBar1.Width,
 _
                pictureBox1.Bottom - hScrollBar1.Height), _
                New Rectangle(hScrollBar1.Value, vScrollBar1.Value,
 _
                pictureBox1.Right - vScrollBar1.Width, _
                pictureBox1.Bottom - hScrollBar1.Height), GraphicsUnit.Pixel)
            pictureBox1.Update()
        End Sub

        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 = CType(Me.hScrollBar1.Maximum
 / 10, Integer)
            Me.hScrollBar1.SmallChange = CType(Me.hScrollBar1.Maximum
 / 20, Integer)

            ' 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 = CType(Me.vScrollBar1.Maximum
 / 10, Integer)
            Me.vScrollBar1.SmallChange = CType(Me.vScrollBar1.Maximum
 / 20, Integer)

            ' Adjust the Maximum value to make the raw Maximum 
            ' value attainable by user interaction.
            Me.vScrollBar1.Maximum += Me.vScrollBar1.LargeChange
        End Sub
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;


namespace Scrollbar
{
    public class Form1 :  Form
   {
      private  OpenFileDialog openFileDialog1;
      private  PictureBox pictureBox1;
      private  VScrollBar vScrollBar1;
      private  HScrollBar hScrollBar1;
    
      public Form1()
      {
         InitializeComponent();
      }
    
      private void InitializeComponent()
      {
         this.openFileDialog1 = new OpenFileDialog();
         this.pictureBox1 = new PictureBox();
         this.vScrollBar1 = new VScrollBar();
         this.hScrollBar1 = new HScrollBar();
         this.pictureBox1.SuspendLayout();
         this.SuspendLayout();
        
         this.pictureBox1.BorderStyle = BorderStyle.FixedSingle;
         this.pictureBox1.Controls.AddRange(
             new Control[] { this.vScrollBar1,
 this.hScrollBar1});
         this.pictureBox1.Dock = DockStyle.Fill;
         this.pictureBox1.Size = new System.Drawing.Size(440,
 349);
         this.pictureBox1.DoubleClick += new
 EventHandler(this.pictureBox1_DoubleClick);

         this.vScrollBar1.Dock = DockStyle.Right;
         this.vScrollBar1.Location = new System.Drawing.Point(422,
 0);
         this.vScrollBar1.Size = new System.Drawing.Size(16,
 331);
         this.vScrollBar1.Visible = false;
         this.vScrollBar1.Scroll += 
             new ScrollEventHandler(this.HandleScroll);
         
         this.hScrollBar1.Dock = DockStyle.Bottom;
         this.hScrollBar1.Location = new System.Drawing.Point(0,
 331);
         this.hScrollBar1.Size = new System.Drawing.Size(438,
 16);
         this.hScrollBar1.Visible = false;
         this.hScrollBar1.Scroll += 
             new ScrollEventHandler(this.HandleScroll);
         
         this.ClientSize = new System.Drawing.Size(440,
 349);
         this.Controls.AddRange(new Control[]
 {this.pictureBox1});
         this.Text = "Form1";
         this.Resize += new System.EventHandler(this.Form1_Resize);
         this.pictureBox1.ResumeLayout(false);
         this.ResumeLayout(false);

      }

      [STAThread]
      static void Main() 
      {
         Application.Run(new Form1());
      }

private void pictureBox1_DoubleClick (Object
 sender, EventArgs e)
{
   // Open the dialog box so the user can select a new image.
   if(openFileDialog1.ShowDialog() != DialogResult.Cancel)
   {
      // Display the image in the PictureBox.
      pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
      this.DisplayScrollBars();
      this.SetScrollBarValues();
   }
}
 
private void Form1_Resize (Object sender, EventArgs
 e)
{
   // If the PictureBox has an image, see if it needs 
   // scrollbars and refresh the image. 
   if(pictureBox1.Image != null)
   {
      this.DisplayScrollBars();
      this.SetScrollBarValues();
      this.Refresh();
   }
}
 
public void DisplayScrollBars()
{
   // If the image is wider than the PictureBox, show the HScrollBar.
   if (pictureBox1.Width > pictureBox1.Image.Width - this.vScrollBar1.Width)
   {
      hScrollBar1.Visible = false;
   }
   else
   {
      hScrollBar1.Visible = true;
   }
 
   // If the image is taller than the PictureBox, show the VScrollBar.
   if (pictureBox1.Height > 
       pictureBox1.Image.Height - this.hScrollBar1.Height)
   {
      vScrollBar1.Visible = false;
   }
   else
   {
      vScrollBar1.Visible = true;
   }
}
 
private void HandleScroll(Object sender, ScrollEventArgs
 se)
{
   /* Create a graphics object and draw a portion 
      of the image in the PictureBox. */
   Graphics g = pictureBox1.CreateGraphics();
   
   g.DrawImage(pictureBox1.Image, 
     new Rectangle(0, 0, pictureBox1.Right - vScrollBar1.Width,
 
     pictureBox1.Bottom - hScrollBar1.Height), 
     new Rectangle(hScrollBar1.Value, vScrollBar1.Value, 
     pictureBox1.Right - vScrollBar1.Width,
     pictureBox1.Bottom - hScrollBar1.Height), 
     GraphicsUnit.Pixel);

     pictureBox1.Update();
}

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;
   }

  }
}
#using <system.dll>
#using <system.data.dll>
#using <system.drawing.dll>
#using <system.windows.forms.dll>
#using <system.xml.dll>

using namespace System;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;

#define null 0L
public ref class Form1: public
 Form
{
protected:
   DataGrid^ dataGrid1;
   DataSet^ dataSet1;
   OpenFileDialog^ openFileDialog1;
   PictureBox^ pictureBox1;
   ScrollBar^ hScrollBar1;
   ScrollBar^ vScrollBar1;

private:

  
   void pictureBox1_DoubleClick( Object^ sender, EventArgs^ e
 )
   {
      // Open the dialog box so the user can select a new image.
      if ( openFileDialog1->ShowDialog() != ::DialogResult::Cancel
 )
      {
         // Display the image in the PictureBox.
         pictureBox1->Image = System::Drawing::Image::FromFile( openFileDialog1->FileName
 );
         this->DisplayScrollBars();
         this->SetScrollBarValues();
      }
   }

   void Form1_Resize( Object^ sender, EventArgs^ e )
   {
      /* If the PictureBox has an image, see if it needs
             scrollbars and refresh the image. */
      if ( pictureBox1->Image != nullptr )
      {
         this->SetScrollBarValues();
         this->DisplayScrollBars();
         this->Refresh();
      }
   }

   void DisplayScrollBars()
   {
      // If the image is wider than the PictureBox, show the HScrollBar.
      if ( pictureBox1->Width > pictureBox1->Image->Width
 - this->vScrollBar1->Width )
      {
         hScrollBar1->Visible = false;
      }
      else
      {
         hScrollBar1->Visible = true;
      }

      // If the image is taller than the PictureBox, show the VScrollBar.
      if ( pictureBox1->Height > pictureBox1->Image->Height
 - this->hScrollBar1->Height )
      {
         vScrollBar1->Visible = false;
      }
      else
      {
         vScrollBar1->Visible = true;
      }
   }

   void HandleScroll( Object^ sender, ScrollEventArgs^ se )
   {
      /* Create a graphics object and draw a portion
             of the image in the PictureBox. */
      Graphics^ g = pictureBox1->CreateGraphics();
      g->DrawImage( pictureBox1->Image, Rectangle(0,0,pictureBox1->Right
 - vScrollBar1->Width,pictureBox1->Bottom - hScrollBar1->Height), Rectangle(hScrollBar1->Value,vScrollBar1->Value,pictureBox1->Right
 - vScrollBar1->Width,pictureBox1->Bottom - hScrollBar1->Height), GraphicsUnit::Pixel );
   }

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;
   }
};
package Scrollbar;

import System.*;
import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;

public class Form1 extends Form
{
    private OpenFileDialog openFileDialog1;
    private PictureBox pictureBox1;
    private VScrollBar vScrollBar1;
    private HScrollBar hScrollBar1;
  
    public Form1()
    {
        InitializeComponent();
    } 

    private void InitializeComponent()
    {
        this.openFileDialog1 = new OpenFileDialog();
        this.pictureBox1 = new PictureBox();
        this.vScrollBar1 = new VScrollBar();
        this.hScrollBar1 = new HScrollBar();
        this.pictureBox1.SuspendLayout();
        this.SuspendLayout();
        this.pictureBox1.set_BorderStyle(
            BorderStyle.FixedSingle);
        this.pictureBox1.get_Controls().AddRange(
            new Control[] { 
            this.vScrollBar1, this.hScrollBar1
 });
        this.pictureBox1.set_Dock(DockStyle.Fill);
        this.pictureBox1.set_Size(new System.Drawing.Size(440,
 349));
        this.pictureBox1.set_TabIndex(0);
        this.pictureBox1.set_TabStop(false);
        this.pictureBox1.add_DoubleClick(
            new System.EventHandler(this.pictureBox1_DoubleClick));
        this.vScrollBar1.set_Dock(DockStyle.Right);
        this.vScrollBar1.set_Location(new System.Drawing.Point(422,
 0));
        this.vScrollBar1.set_Size(new System.Drawing.Size(16,
 331));
        this.vScrollBar1.set_Visible(false);
        this.vScrollBar1.add_Scroll(
            new ScrollEventHandler(this.HandleScroll));
        this.hScrollBar1.set_Dock(DockStyle.Bottom);
        this.hScrollBar1.set_Location(new System.Drawing.Point(0,
 331));
        this.hScrollBar1.set_Size(new System.Drawing.Size(438,
 16));
        this.hScrollBar1.set_Visible(false);
        this.hScrollBar1.add_Scroll(
            new ScrollEventHandler(this.HandleScroll));
        this.set_ClientSize(new System.Drawing.Size(440,
 349));
        this.get_Controls().AddRange(
            new Control[] { this.pictureBox1
 });
        this.set_Text("Form1");
        this.add_Resize(new System.EventHandler(this.Form1_Resize));
        this.pictureBox1.ResumeLayout(false);
        this.ResumeLayout(false);
    }
    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        Application.Run(new Form1());
    } 

    private void pictureBox1_DoubleClick(Object
 sender, EventArgs e)
    {
        // Open the dialog box so the user can select a new image.
        if (openFileDialog1.ShowDialog() != get_DialogResult().Cancel)
 {
    
            // Display the image in the PictureBox.
            pictureBox1.set_Image(Image.FromFile(
                openFileDialog1.get_FileName()));
            this.DisplayScrollBars();
            this.SetScrollBarValues();
        }
    } 

    protected void Form1_Resize(Object sender,
 EventArgs e)
    {
        /* If the PictureBox has an image, see if it needs 
           scrollbars and refresh the image. 
         */
        if (pictureBox1.get_Image() != null)
 {
            this.DisplayScrollBars();
            this.SetScrollBarValues();
            this.Refresh();
        }
    } 

    public void DisplayScrollBars()
    {
        // If the image is wider than the PictureBox, show the HScrollBar.
        if (pictureBox1.get_Width() > pictureBox1.get_Image().get_Width()
 
            - this.vScrollBar1.get_Width()) {
                hScrollBar1.set_Visible(false);
        }
        else {
            hScrollBar1.set_Visible(true);
        }

        // If the image is taller than the PictureBox, show the VScrollBar.
        if (pictureBox1.get_Height() > pictureBox1.get_Image().get_Height()
 
            - this.hScrollBar1.get_Height()) {
                vScrollBar1.set_Visible(false);
        }
        else {
            vScrollBar1.set_Visible(true);
        }
    } 

    private void HandleScroll(Object sender, ScrollEventArgs
 se)
    {
        /* Create a graphics object and draw a portion 
           of the image in the PictureBox. 
         */
        Graphics g = pictureBox1.CreateGraphics();

        g.DrawImage(pictureBox1.get_Image(), 
            new Rectangle(0, 0, 
            pictureBox1.get_Right() - vScrollBar1.get_Width(), 
            pictureBox1.get_Bottom() - hScrollBar1.get_Height()), 
            new Rectangle(hScrollBar1.get_Value(), 
            vScrollBar1.get_Value(), pictureBox1.get_Right() 
            - vScrollBar1.get_Width(), pictureBox1.get_Bottom() 
            - hScrollBar1.get_Height()), GraphicsUnit.Pixel);
        pictureBox1.Update();
    }

    public void SetScrollBarValues()
    {
        // Set the Maximum, Minimum, LargeChange and SmallChange properties.
        this.vScrollBar1.set_Minimum(0);
        this.hScrollBar1.set_Minimum(0);

        // If the offset does not make the Maximum less than zero, 
        // set its value. 
        if (this.pictureBox1.get_Image().get_Size().get_Width()
 
            - pictureBox1.get_ClientSize().get_Width() > 0) {
                this.hScrollBar1.set_Maximum(
                    this.pictureBox1.get_Image().get_Size().get_Width()
 
                    - pictureBox1.get_ClientSize().get_Width());
        }

        /* If the VScrollBar is visible, adjust the Maximum of the 
           HSCrollBar to account for the width of the VScrollBar.
 
         */
        if (this.vScrollBar1.get_Visible())
 {
            this.hScrollBar1.set_Maximum(this.hScrollBar1.get_Maximum()
 
                + this.vScrollBar1.get_Width());
        }

        this.hScrollBar1.set_LargeChange(this.hScrollBar1.get_Maximum()
 / 10);
        this.hScrollBar1.set_SmallChange(this.hScrollBar1.get_Maximum()
 / 20);

        // Adjust the Maximum value to make the raw Maximum value attainable
 
        // by user interaction.
        this.hScrollBar1.set_Maximum(this.hScrollBar1.get_Maximum()
 
            + this.hScrollBar1.get_LargeChange());

        // If the offset does not make the Maximum less than zero, 
        // set its value.    
        if (this.pictureBox1.get_Image().get_Size().get_Height()
 
            - pictureBox1.get_ClientSize().get_Height() > 0) {
                this.vScrollBar1.set_Maximum(
                    this.pictureBox1.get_Image().get_Size().get_Height()
 
                    - pictureBox1.get_ClientSize().get_Height());
        }

        /* If the HScrollBar is visible, adjust the Maximum of the 
           VSCrollBar to account for the width of the HScrollBar.
         */
        if (this.hScrollBar1.get_Visible())
 {
            this.vScrollBar1.set_Maximum(this.vScrollBar1.get_Maximum()
 
                + this.hScrollBar1.get_Height());
        }

        this.vScrollBar1.set_LargeChange(this.vScrollBar1.get_Maximum()
 / 10);
        this.vScrollBar1.set_SmallChange(this.vScrollBar1.get_Maximum()
 / 20);

        // Adjust the Maximum value to make the raw Maximum value attainable
 
        // by user interaction.
        this.vScrollBar1.set_Maximum(this.vScrollBar1.get_Maximum()
 
            + this.vScrollBar1.get_LargeChange());
    } //SetScrollBarValues
   
} 
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.ScrollBar
           System.Windows.Forms.HScrollBar
           System.Windows.Forms.VScrollBar
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ScrollBar クラス」の関連用語

ScrollBar クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ScrollBar クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS