Scrollbars for Picturebox Controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Kurtis Koeber

    Scrollbars for Picturebox Controls

    Dear All,
    This may sound like an elementary question but how do you implement
    scrollbars for the Picturebox control. Do I have to create my own code to do
    this or is there some property that I can set? Thank you very much for your
    time and consideration in this matter!
    Christopher Koeber


  • Bob Powell [MVP]

    #2
    Re: Scrollbars for Picturebox Controls

    Put your picturebox inside a panel and set the bounds of the picturebox to
    be the same size as the image. Set the Panel.AutoScrol l property to true and
    the panel will provide the scrollbars for you.

    The code after my signature demonstrates this.

    --
    Bob Powell [MVP]
    Visual C#, System.Drawing

    Answer those GDI+ questions with the GDI+ FAQ


    The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
    Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
    Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


    -------------------------------------------------------------------------
    Public Class Form1
    Inherits System.Windows. Forms.Form

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeCompo nent()

    'Add any initialization after the InitializeCompo nent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Disp ose()
    End If
    End If
    MyBase.Dispose( disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.Componen tModel.IContain er

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows. Forms.Panel
    Friend WithEvents PictureBox1 As System.Windows. Forms.PictureBo x
    <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    InitializeCompo nent()
    Me.Panel1 = New System.Windows. Forms.Panel
    Me.PictureBox1 = New System.Windows. Forms.PictureBo x
    Me.Panel1.Suspe ndLayout()
    Me.SuspendLayou t()
    '
    'Panel1
    '
    Me.Panel1.AutoS croll = True
    Me.Panel1.Contr ols.Add(Me.Pict ureBox1)
    Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
    Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
    Me.Panel1.Name = "Panel1"
    Me.Panel1.Size = New System.Drawing. Size(292, 266)
    Me.Panel1.TabIn dex = 0
    '
    'PictureBox1
    '
    Me.PictureBox1. Location = New System.Drawing. Point(32, 48)
    Me.PictureBox1. Name = "PictureBox 1"
    Me.PictureBox1. TabIndex = 0
    Me.PictureBox1. TabStop = False
    '
    'Form1
    '
    Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
    Me.ClientSize = New System.Drawing. Size(292, 266)
    Me.Controls.Add (Me.Panel1)
    Me.Name = "Form1"
    Me.Text = "Form1"
    Me.Panel1.Resum eLayout(False)
    Me.ResumeLayout (False)

    End Sub

    #End Region

    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    Me.PictureBox1. Image = Image.FromFile( "c:\foo.jpg ") 'you'll need to
    change this obviously...
    Me.PictureBox1. Location = New Point(0, 0)
    Me.PictureBox1. Size = Me.PictureBox1. Image.Size
    End Sub
    End Class

    -------------------------------------------------------------------------



    "Christophe r Kurtis Koeber" <c_koeber@myrea lbox.com> wrote in message
    news:%23c2u$Mpq EHA.556@tk2msft ngp13.phx.gbl.. .[color=blue]
    > Dear All,
    > This may sound like an elementary question but how do you implement
    > scrollbars for the Picturebox control. Do I have to create my own code to[/color]
    do[color=blue]
    > this or is there some property that I can set? Thank you very much for[/color]
    your[color=blue]
    > time and consideration in this matter!
    > Christopher Koeber
    >
    >[/color]


    Comment

    • Dr Screwup

      #3
      Re: Scrollbars for Picturebox Controls

      Why not use the panel control itself?



      "Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
      news:%23txAoksq EHA.1456@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Put your picturebox inside a panel and set the bounds of the picturebox to
      > be the same size as the image. Set the Panel.AutoScrol l property to true
      > and
      > the panel will provide the scrollbars for you.
      >
      > The code after my signature demonstrates this.
      >
      > --
      > Bob Powell [MVP]
      > Visual C#, System.Drawing
      >
      > Answer those GDI+ questions with the GDI+ FAQ
      > http://www.bobpowell.net/gdiplus_faq.htm
      >
      > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
      > Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
      > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
      >
      >
      > -------------------------------------------------------------------------
      > Public Class Form1
      > Inherits System.Windows. Forms.Form
      >
      > #Region " Windows Form Designer generated code "
      >
      > Public Sub New()
      > MyBase.New()
      >
      > 'This call is required by the Windows Form Designer.
      > InitializeCompo nent()
      >
      > 'Add any initialization after the InitializeCompo nent() call
      >
      > End Sub
      >
      > 'Form overrides dispose to clean up the component list.
      > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      > If disposing Then
      > If Not (components Is Nothing) Then
      > components.Disp ose()
      > End If
      > End If
      > MyBase.Dispose( disposing)
      > End Sub
      >
      > 'Required by the Windows Form Designer
      > Private components As System.Componen tModel.IContain er
      >
      > 'NOTE: The following procedure is required by the Windows Form Designer
      > 'It can be modified using the Windows Form Designer.
      > 'Do not modify it using the code editor.
      > Friend WithEvents Panel1 As System.Windows. Forms.Panel
      > Friend WithEvents PictureBox1 As System.Windows. Forms.PictureBo x
      > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
      > InitializeCompo nent()
      > Me.Panel1 = New System.Windows. Forms.Panel
      > Me.PictureBox1 = New System.Windows. Forms.PictureBo x
      > Me.Panel1.Suspe ndLayout()
      > Me.SuspendLayou t()
      > '
      > 'Panel1
      > '
      > Me.Panel1.AutoS croll = True
      > Me.Panel1.Contr ols.Add(Me.Pict ureBox1)
      > Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
      > Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
      > Me.Panel1.Name = "Panel1"
      > Me.Panel1.Size = New System.Drawing. Size(292, 266)
      > Me.Panel1.TabIn dex = 0
      > '
      > 'PictureBox1
      > '
      > Me.PictureBox1. Location = New System.Drawing. Point(32, 48)
      > Me.PictureBox1. Name = "PictureBox 1"
      > Me.PictureBox1. TabIndex = 0
      > Me.PictureBox1. TabStop = False
      > '
      > 'Form1
      > '
      > Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
      > Me.ClientSize = New System.Drawing. Size(292, 266)
      > Me.Controls.Add (Me.Panel1)
      > Me.Name = "Form1"
      > Me.Text = "Form1"
      > Me.Panel1.Resum eLayout(False)
      > Me.ResumeLayout (False)
      >
      > End Sub
      >
      > #End Region
      >
      > Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      > Me.PictureBox1. Image = Image.FromFile( "c:\foo.jpg ") 'you'll need to
      > change this obviously...
      > Me.PictureBox1. Location = New Point(0, 0)
      > Me.PictureBox1. Size = Me.PictureBox1. Image.Size
      > End Sub
      > End Class
      >
      > -------------------------------------------------------------------------
      >
      >
      >
      > "Christophe r Kurtis Koeber" <c_koeber@myrea lbox.com> wrote in message
      > news:%23c2u$Mpq EHA.556@tk2msft ngp13.phx.gbl.. .[color=green]
      >> Dear All,
      >> This may sound like an elementary question but how do you implement
      >> scrollbars for the Picturebox control. Do I have to create my own code to[/color]
      > do[color=green]
      >> this or is there some property that I can set? Thank you very much for[/color]
      > your[color=green]
      >> time and consideration in this matter!
      >> Christopher Koeber
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Bob Powell [MVP]

        #4
        Re: Scrollbars for Picturebox Controls

        Setting up that solution was much simpler. Using just the panel you have to
        adjust the drawing position according to the scroll positions.

        Just for fun I included the code again.

        (code after my signature)

        --
        Bob Powell [MVP]
        Visual C#, System.Drawing

        Answer those GDI+ questions with the GDI+ FAQ


        The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
        Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
        Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


        Imports System.Drawing. Drawing2D

        Public Class Form1

        Inherits System.Windows. Forms.Form

        Dim image As image

        #Region " Windows Form Designer generated code "

        Public Sub New()

        MyBase.New()

        'This call is required by the Windows Form Designer.

        InitializeCompo nent()

        'Add any initialization after the InitializeCompo nent() call

        End Sub

        'Form overrides dispose to clean up the component list.

        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then

        If Not (components Is Nothing) Then

        components.Disp ose()

        End If

        End If

        MyBase.Dispose( disposing)

        End Sub

        'Required by the Windows Form Designer

        Private components As System.Componen tModel.IContain er

        'NOTE: The following procedure is required by the Windows Form Designer

        'It can be modified using the Windows Form Designer.

        'Do not modify it using the code editor.

        Friend WithEvents Panel1 As System.Windows. Forms.Panel

        <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

        Me.Panel1 = New System.Windows. Forms.Panel

        Me.SuspendLayou t()

        '

        'Panel1

        '

        Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill

        Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)

        Me.Panel1.Name = "Panel1"

        Me.Panel1.Size = New System.Drawing. Size(292, 266)

        Me.Panel1.TabIn dex = 0

        '

        'Form1

        '

        Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

        Me.ClientSize = New System.Drawing. Size(292, 266)

        Me.Controls.Add (Me.Panel1)

        Me.Name = "Form1"

        Me.Text = "Form1"

        Me.ResumeLayout (False)

        End Sub

        #End Region

        Private Sub Panel1_Paint(By Val sender As Object, ByVal e As
        System.Windows. Forms.PaintEven tArgs) Handles Panel1.Paint

        e.Graphics.Tran sform = New Matrix(1, 0, 0, 1,
        Me.Panel1.AutoS crollPosition.X , Me.Panel1.AutoS crollPosition.Y )

        e.Graphics.Draw ImageUnscaled(i mage, 0, 0)

        End Sub

        Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
        Handles MyBase.Load

        image = image.FromFile( "c:\foo.jpg ")

        Me.Panel1.AutoS crollMinSize = image.Size

        Me.Panel1.AutoS croll = True

        End Sub

        End Class




        "Dr Screwup" <nospam@no_than ks.com> wrote in message
        news:10m5agfp1n 2o16d@corp.supe rnews.com...[color=blue]
        > Why not use the panel control itself?
        >
        >
        >
        > "Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
        > news:%23txAoksq EHA.1456@TK2MSF TNGP10.phx.gbl. ..[color=green]
        > > Put your picturebox inside a panel and set the bounds of the picturebox[/color][/color]
        to[color=blue][color=green]
        > > be the same size as the image. Set the Panel.AutoScrol l property to true
        > > and
        > > the panel will provide the scrollbars for you.
        > >
        > > The code after my signature demonstrates this.
        > >
        > > --
        > > Bob Powell [MVP]
        > > Visual C#, System.Drawing
        > >
        > > Answer those GDI+ questions with the GDI+ FAQ
        > > http://www.bobpowell.net/gdiplus_faq.htm
        > >
        > > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
        > > Windows Forms Tips and Tricks RSS:[/color][/color]
        http://www.bobpowell.net/tipstricks.xml[color=blue][color=green]
        > > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
        > >
        > >[/color]
        >
        > -------------------------------------------------------------------------[color=green]
        > > Public Class Form1
        > > Inherits System.Windows. Forms.Form
        > >
        > > #Region " Windows Form Designer generated code "
        > >
        > > Public Sub New()
        > > MyBase.New()
        > >
        > > 'This call is required by the Windows Form Designer.
        > > InitializeCompo nent()
        > >
        > > 'Add any initialization after the InitializeCompo nent() call
        > >
        > > End Sub
        > >
        > > 'Form overrides dispose to clean up the component list.
        > > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        > > If disposing Then
        > > If Not (components Is Nothing) Then
        > > components.Disp ose()
        > > End If
        > > End If
        > > MyBase.Dispose( disposing)
        > > End Sub
        > >
        > > 'Required by the Windows Form Designer
        > > Private components As System.Componen tModel.IContain er
        > >
        > > 'NOTE: The following procedure is required by the Windows Form[/color][/color]
        Designer[color=blue][color=green]
        > > 'It can be modified using the Windows Form Designer.
        > > 'Do not modify it using the code editor.
        > > Friend WithEvents Panel1 As System.Windows. Forms.Panel
        > > Friend WithEvents PictureBox1 As System.Windows. Forms.PictureBo x
        > > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
        > > InitializeCompo nent()
        > > Me.Panel1 = New System.Windows. Forms.Panel
        > > Me.PictureBox1 = New System.Windows. Forms.PictureBo x
        > > Me.Panel1.Suspe ndLayout()
        > > Me.SuspendLayou t()
        > > '
        > > 'Panel1
        > > '
        > > Me.Panel1.AutoS croll = True
        > > Me.Panel1.Contr ols.Add(Me.Pict ureBox1)
        > > Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
        > > Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
        > > Me.Panel1.Name = "Panel1"
        > > Me.Panel1.Size = New System.Drawing. Size(292, 266)
        > > Me.Panel1.TabIn dex = 0
        > > '
        > > 'PictureBox1
        > > '
        > > Me.PictureBox1. Location = New System.Drawing. Point(32, 48)
        > > Me.PictureBox1. Name = "PictureBox 1"
        > > Me.PictureBox1. TabIndex = 0
        > > Me.PictureBox1. TabStop = False
        > > '
        > > 'Form1
        > > '
        > > Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
        > > Me.ClientSize = New System.Drawing. Size(292, 266)
        > > Me.Controls.Add (Me.Panel1)
        > > Me.Name = "Form1"
        > > Me.Text = "Form1"
        > > Me.Panel1.Resum eLayout(False)
        > > Me.ResumeLayout (False)
        > >
        > > End Sub
        > >
        > > #End Region
        > >
        > > Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
        > > System.EventArg s) Handles MyBase.Load
        > > Me.PictureBox1. Image = Image.FromFile( "c:\foo.jpg ") 'you'll need[/color][/color]
        to[color=blue][color=green]
        > > change this obviously...
        > > Me.PictureBox1. Location = New Point(0, 0)
        > > Me.PictureBox1. Size = Me.PictureBox1. Image.Size
        > > End Sub
        > > End Class
        > >[/color]
        >
        > -------------------------------------------------------------------------[color=green]
        > >
        > >
        > >
        > > "Christophe r Kurtis Koeber" <c_koeber@myrea lbox.com> wrote in message
        > > news:%23c2u$Mpq EHA.556@tk2msft ngp13.phx.gbl.. .[color=darkred]
        > >> Dear All,
        > >> This may sound like an elementary question but how do you implement
        > >> scrollbars for the Picturebox control. Do I have to create my own code[/color][/color][/color]
        to[color=blue][color=green]
        > > do[color=darkred]
        > >> this or is there some property that I can set? Thank you very much for[/color]
        > > your[color=darkred]
        > >> time and consideration in this matter!
        > >> Christopher Koeber
        > >>
        > >>[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Christopher Kurtis Koeber

          #5
          Re: Scrollbars for Picturebox Controls

          Thanks, Bob

          Your website is pretty cool as well.

          Christopher
          "Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
          news:%23txAoksq EHA.1456@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Put your picturebox inside a panel and set the bounds of the picturebox to
          > be the same size as the image. Set the Panel.AutoScrol l property to true
          > and
          > the panel will provide the scrollbars for you.
          >
          > The code after my signature demonstrates this.
          >
          > --
          > Bob Powell [MVP]
          > Visual C#, System.Drawing
          >
          > Answer those GDI+ questions with the GDI+ FAQ
          > http://www.bobpowell.net/gdiplus_faq.htm
          >
          > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
          > Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
          > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
          >
          >
          > -------------------------------------------------------------------------
          > Public Class Form1
          > Inherits System.Windows. Forms.Form
          >
          > #Region " Windows Form Designer generated code "
          >
          > Public Sub New()
          > MyBase.New()
          >
          > 'This call is required by the Windows Form Designer.
          > InitializeCompo nent()
          >
          > 'Add any initialization after the InitializeCompo nent() call
          >
          > End Sub
          >
          > 'Form overrides dispose to clean up the component list.
          > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
          > If disposing Then
          > If Not (components Is Nothing) Then
          > components.Disp ose()
          > End If
          > End If
          > MyBase.Dispose( disposing)
          > End Sub
          >
          > 'Required by the Windows Form Designer
          > Private components As System.Componen tModel.IContain er
          >
          > 'NOTE: The following procedure is required by the Windows Form Designer
          > 'It can be modified using the Windows Form Designer.
          > 'Do not modify it using the code editor.
          > Friend WithEvents Panel1 As System.Windows. Forms.Panel
          > Friend WithEvents PictureBox1 As System.Windows. Forms.PictureBo x
          > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
          > InitializeCompo nent()
          > Me.Panel1 = New System.Windows. Forms.Panel
          > Me.PictureBox1 = New System.Windows. Forms.PictureBo x
          > Me.Panel1.Suspe ndLayout()
          > Me.SuspendLayou t()
          > '
          > 'Panel1
          > '
          > Me.Panel1.AutoS croll = True
          > Me.Panel1.Contr ols.Add(Me.Pict ureBox1)
          > Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
          > Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
          > Me.Panel1.Name = "Panel1"
          > Me.Panel1.Size = New System.Drawing. Size(292, 266)
          > Me.Panel1.TabIn dex = 0
          > '
          > 'PictureBox1
          > '
          > Me.PictureBox1. Location = New System.Drawing. Point(32, 48)
          > Me.PictureBox1. Name = "PictureBox 1"
          > Me.PictureBox1. TabIndex = 0
          > Me.PictureBox1. TabStop = False
          > '
          > 'Form1
          > '
          > Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
          > Me.ClientSize = New System.Drawing. Size(292, 266)
          > Me.Controls.Add (Me.Panel1)
          > Me.Name = "Form1"
          > Me.Text = "Form1"
          > Me.Panel1.Resum eLayout(False)
          > Me.ResumeLayout (False)
          >
          > End Sub
          >
          > #End Region
          >
          > Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
          > System.EventArg s) Handles MyBase.Load
          > Me.PictureBox1. Image = Image.FromFile( "c:\foo.jpg ") 'you'll need to
          > change this obviously...
          > Me.PictureBox1. Location = New Point(0, 0)
          > Me.PictureBox1. Size = Me.PictureBox1. Image.Size
          > End Sub
          > End Class
          >
          > -------------------------------------------------------------------------
          >
          >
          >
          > "Christophe r Kurtis Koeber" <c_koeber@myrea lbox.com> wrote in message
          > news:%23c2u$Mpq EHA.556@tk2msft ngp13.phx.gbl.. .[color=green]
          >> Dear All,
          >> This may sound like an elementary question but how do you implement
          >> scrollbars for the Picturebox control. Do I have to create my own code to[/color]
          > do[color=green]
          >> this or is there some property that I can set? Thank you very much for[/color]
          > your[color=green]
          >> time and consideration in this matter!
          >> Christopher Koeber
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • samir parekh

            #6
            RE: Scrollbars for Picturebox Controls

            dear ckk;
            to do the requested task u only have to search the MSDN help on your PC .
            Find the Scrollbar class there in and find the sample code given down there
            with regards
            samir parekh (student)
            sam41180@yahoo. com

            "Christophe r Kurtis Koeber" wrote:
            [color=blue]
            > Dear All,
            > This may sound like an elementary question but how do you implement
            > scrollbars for the Picturebox control. Do I have to create my own code to do
            > this or is there some property that I can set? Thank you very much for your
            > time and consideration in this matter!
            > Christopher Koeber
            >
            >
            >[/color]

            Comment

            Working...