By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,699 Members | 1,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,699 IT Pros & Developers. It's quick & easy.

Scrollbars for Picturebox Controls

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Put your picturebox inside a panel and set the bounds of the picturebox to
be the same size as the image. Set the Panel.AutoScroll 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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Controls.Add(Me.PictureBox1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(292, 266)
Me.Panel1.TabIndex = 0
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(32, 48)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = 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.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) 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

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

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #2

P: n/a
Why not use the panel control itself?

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Put your picturebox inside a panel and set the bounds of the picturebox to
be the same size as the image. Set the Panel.AutoScroll 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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Controls.Add(Me.PictureBox1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(292, 266)
Me.Panel1.TabIndex = 0
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(32, 48)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = 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.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) 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

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

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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


Nov 21 '05 #3

P: n/a
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
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
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.

InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

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

Me.SuspendLayout()

'

'Panel1

'

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

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

Me.Panel1.Name = "Panel1"

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

Me.Panel1.TabIndex = 0

'

'Form1

'

Me.AutoScaleBaseSize = 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(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

e.Graphics.Transform = New Matrix(1, 0, 0, 1,
Me.Panel1.AutoScrollPosition.X, Me.Panel1.AutoScrollPosition.Y)

e.Graphics.DrawImageUnscaled(image, 0, 0)

End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

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

Me.Panel1.AutoScrollMinSize = image.Size

Me.Panel1.AutoScroll = True

End Sub

End Class


"Dr Screwup" <nospam@no_thanks.com> wrote in message
news:10*************@corp.supernews.com...
Why not use the panel control itself?

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Put your picturebox inside a panel and set the bounds of the picturebox to be the same size as the image. Set the Panel.AutoScroll 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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Controls.Add(Me.PictureBox1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(292, 266)
Me.Panel1.TabIndex = 0
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(32, 48)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = 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.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) 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


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

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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



Nov 21 '05 #4

P: n/a
Thanks, Bob

Your website is pretty cool as well.

Christopher
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Put your picturebox inside a panel and set the bounds of the picturebox to
be the same size as the image. Set the Panel.AutoScroll 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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Controls.Add(Me.PictureBox1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(292, 266)
Me.Panel1.TabIndex = 0
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(32, 48)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = 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.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) 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

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

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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


Nov 21 '05 #5

P: n/a
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)
sa******@yahoo.com

"Christopher Kurtis Koeber" wrote:
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

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.