Smooth scrolling image or picturebox

P

Paul Loveless

Hi all. I have a user control that contains a picturebox within a panel with
the panel set to autoscroll the picturebox. One thing that I have noticed
with the default functionality is when you click and drag the scroll box
(thumb track) the picturebox does not scroll until you release it. Is there
a way to scroll the picturebox while you move the scrollbox (like when you
scroll a web page)? Or do you have to use the scroll bar controls instead of
autoscroll and manually code this functionality?

Any ideas?

Paul
 
B

Bob Powell [MVP]

Try this... (after my signature)

This works fine for me. It may affect your application if you have the "Show
contents of window while dragging" setting enabled in the display
properties.

--
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
 
P

Paul L

Hmm...not quite what I had in mind Bob. While the picture does scroll
properly, my earlier point still stands. What I mean is, when you click and
drag a scroll bar's thumbtrack, I want the picture itself to scroll while
you are dragging the thumbtrack. Scrolling any web page in IE will
illustrate this. In your example, when you click and drag the thumbtrack,
the picture does not scroll until "after" you release the mouse button.

However, I like how you use a matrix to perform a picture translation.
Thanks for the feedback though. If you understand what I mean and have any
other ideas, I'm all ears.

Take care,
Paul


Bob Powell said:
Try this... (after my signature)

This works fine for me. It may affect your application if you have the "Show
contents of window while dragging" setting enabled in the display
properties.

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


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

[code deleted]

Paul Loveless said:
Hi all. I have a user control that contains a picturebox within a panel with
the panel set to autoscroll the picturebox. One thing that I have noticed
with the default functionality is when you click and drag the scroll box
(thumb track) the picturebox does not scroll until you release it. Is there
a way to scroll the picturebox while you move the scrollbox (like when you
scroll a web page)? Or do you have to use the scroll bar controls
instead
of
autoscroll and manually code this functionality?

Any ideas?

Paul
 
B

Bob Powell [MVP]

It *does* scroll on thumbtrack on my system. Quite smoothly actually.

Have you set the display options for show window contents while dragging?
This may affect that functionality...

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






Paul L said:
Hmm...not quite what I had in mind Bob. While the picture does scroll
properly, my earlier point still stands. What I mean is, when you click and
drag a scroll bar's thumbtrack, I want the picture itself to scroll while
you are dragging the thumbtrack. Scrolling any web page in IE will
illustrate this. In your example, when you click and drag the thumbtrack,
the picture does not scroll until "after" you release the mouse button.

However, I like how you use a matrix to perform a picture translation.
Thanks for the feedback though. If you understand what I mean and have any
other ideas, I'm all ears.

Take care,
Paul


Bob Powell said:
Try this... (after my signature)

This works fine for me. It may affect your application if you have the "Show
contents of window while dragging" setting enabled in the display
properties.

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


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

[code deleted]

Paul Loveless said:
Hi all. I have a user control that contains a picturebox within a
panel
with
the panel set to autoscroll the picturebox. One thing that I have noticed
with the default functionality is when you click and drag the scroll box
(thumb track) the picturebox does not scroll until you release it. Is there
a way to scroll the picturebox while you move the scrollbox (like when you
scroll a web page)? Or do you have to use the scroll bar controls
instead
of
autoscroll and manually code this functionality?

Any ideas?

Paul
 
P

Paul L

Your right, it does smooth scroll when the display option for showing window
contents is enabled.
However, through my own investigation, I have developed a solution that
doesn't rely on this display setting (which I prefer). If you are
interested, I can send you the code once I've cleaned it up.

Paul

Bob Powell said:
It *does* scroll on thumbtrack on my system. Quite smoothly actually.

Have you set the display options for show window contents while dragging?
This may affect that functionality...

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






Paul L said:
Hmm...not quite what I had in mind Bob. While the picture does scroll
properly, my earlier point still stands. What I mean is, when you click and
drag a scroll bar's thumbtrack, I want the picture itself to scroll while
you are dragging the thumbtrack. Scrolling any web page in IE will
illustrate this. In your example, when you click and drag the thumbtrack,
the picture does not scroll until "after" you release the mouse button.

However, I like how you use a matrix to perform a picture translation.
Thanks for the feedback though. If you understand what I mean and have any
other ideas, I'm all ears.

Take care,
Paul


Bob Powell said:
Try this... (after my signature)

This works fine for me. It may affect your application if you have the "Show
contents of window while dragging" setting enabled in the display
properties.

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


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

[code deleted]

Hi all. I have a user control that contains a picturebox within a panel
with
the panel set to autoscroll the picturebox. One thing that I have noticed
with the default functionality is when you click and drag the scroll box
(thumb track) the picturebox does not scroll until you release it. Is
there
a way to scroll the picturebox while you move the scrollbox (like
when
you
scroll a web page)? Or do you have to use the scroll bar controls instead
of
autoscroll and manually code this functionality?

Any ideas?

Paul
 
B

Bob Powell [MVP]

Why not post it here so that others can benefit?

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






Paul L said:
Your right, it does smooth scroll when the display option for showing window
contents is enabled.
However, through my own investigation, I have developed a solution that
doesn't rely on this display setting (which I prefer). If you are
interested, I can send you the code once I've cleaned it up.

Paul

Bob Powell said:
It *does* scroll on thumbtrack on my system. Quite smoothly actually.

Have you set the display options for show window contents while dragging?
This may affect that functionality...

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






Paul L said:
Hmm...not quite what I had in mind Bob. While the picture does scroll
properly, my earlier point still stands. What I mean is, when you
click
and
drag a scroll bar's thumbtrack, I want the picture itself to scroll while
you are dragging the thumbtrack. Scrolling any web page in IE will
illustrate this. In your example, when you click and drag the thumbtrack,
the picture does not scroll until "after" you release the mouse button.

However, I like how you use a matrix to perform a picture translation.
Thanks for the feedback though. If you understand what I mean and have any
other ideas, I'm all ears.

Take care,
Paul


Try this... (after my signature)

This works fine for me. It may affect your application if you have the
"Show
contents of window while dragging" setting enabled in the display
properties.

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


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

[code deleted]

Hi all. I have a user control that contains a picturebox within a panel
with
the panel set to autoscroll the picturebox. One thing that I have
noticed
with the default functionality is when you click and drag the
scroll
box
(thumb track) the picturebox does not scroll until you release it. Is
there
a way to scroll the picturebox while you move the scrollbox (like when
you
scroll a web page)? Or do you have to use the scroll bar controls
instead
of
autoscroll and manually code this functionality?

Any ideas?

Paul
 
P

Paul L

True. I may not get a chance to post it for a couple of days though.

Paul

Bob Powell said:
Why not post it here so that others can benefit?

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






Paul L said:
Your right, it does smooth scroll when the display option for showing window
contents is enabled.
However, through my own investigation, I have developed a solution that
doesn't rely on this display setting (which I prefer). If you are
interested, I can send you the code once I've cleaned it up.

Paul

Bob Powell said:
It *does* scroll on thumbtrack on my system. Quite smoothly actually.

Have you set the display options for show window contents while dragging?
This may affect that functionality...

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






Hmm...not quite what I had in mind Bob. While the picture does scroll
properly, my earlier point still stands. What I mean is, when you click
and
drag a scroll bar's thumbtrack, I want the picture itself to scroll while
you are dragging the thumbtrack. Scrolling any web page in IE will
illustrate this. In your example, when you click and drag the thumbtrack,
the picture does not scroll until "after" you release the mouse button.

However, I like how you use a matrix to perform a picture translation.
Thanks for the feedback though. If you understand what I mean and
have
any
other ideas, I'm all ears.

Take care,
Paul


Try this... (after my signature)

This works fine for me. It may affect your application if you have the
"Show
contents of window while dragging" setting enabled in the display
properties.

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


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

[code deleted]

Hi all. I have a user control that contains a picturebox within a
panel
with
the panel set to autoscroll the picturebox. One thing that I have
noticed
with the default functionality is when you click and drag the scroll
box
(thumb track) the picturebox does not scroll until you release
it.
Is
there
a way to scroll the picturebox while you move the scrollbox
(like
when
you
scroll a web page)? Or do you have to use the scroll bar controls
instead
of
autoscroll and manually code this functionality?

Any ideas?

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top