472,328 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Scrolling in a panel

To keep my example simple, let's say I have a windows application form with
a panel in it. For this example, I want to draw a single line in the panel,
which is larger than the size of the panel. Is there a way to get the
scrollbars to show up?

Also....If I were to put a control (like a button) into the panel, the
scrollbars are there...but my line doesn't redraw properly.

How should I be doing this? Thanks.

PS. here's code snip of what I'm trying to do....

Private components As System.ComponentModel.IContainer

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.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Me.Panel1.AutoScroll = True

Me.Panel1.BackColor = System.Drawing.Color.White

Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

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

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(472, 344)

Me.Panel1.TabIndex = 0

'

'Preview

'

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

Me.ClientSize = New System.Drawing.Size(592, 413)

Me.Controls.Add(Me.Panel1)

Me.Name = "Preview"

Me.Text = "Preview"

Me.ResumeLayout(False)

End Sub

Private Sub DrawIt(ByVal g As Graphics)

g.DrawLine(New Pen(Color.Black), 2, 2, 500, 400)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

DrawIt(e.Graphics)

End Sub
Nov 21 '05 #1
5 22077
You should use AutoScrollMinSize and AutoScrollMargin to let the control
know that your area has a certain size, whether it has other controls in it
or not.
To redraw the line, you should capture the OnAutoScroll event (I don't
remember the exact name, but it's something like that) and call
[MyControl].Invalidate() or even [MyForm].Invalidate(true)...
With this, .Net calls the Paint event for your MyControl or your MyForm
(invalidating all children controls).
I'm not sure it's not called automatically if you set the drawing styles of
your control... Try your code with the AutoScrollMinSize and Margin set, and
do the scrolling to see if your line gets redrawn...
Hope this helps...
VBen.

"Rob T" <RT*********@DONTwalchemSPAM.com> escribió en el mensaje
news:Od**************@TK2MSFTNGP15.phx.gbl...
To keep my example simple, let's say I have a windows application form with a panel in it. For this example, I want to draw a single line in the panel, which is larger than the size of the panel. Is there a way to get the
scrollbars to show up?

Also....If I were to put a control (like a button) into the panel, the
scrollbars are there...but my line doesn't redraw properly.

How should I be doing this? Thanks.

PS. here's code snip of what I'm trying to do....

Private components As System.ComponentModel.IContainer

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.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Me.Panel1.AutoScroll = True

Me.Panel1.BackColor = System.Drawing.Color.White

Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

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

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(472, 344)

Me.Panel1.TabIndex = 0

'

'Preview

'

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

Me.ClientSize = New System.Drawing.Size(592, 413)

Me.Controls.Add(Me.Panel1)

Me.Name = "Preview"

Me.Text = "Preview"

Me.ResumeLayout(False)

End Sub

Private Sub DrawIt(ByVal g As Graphics)

g.DrawLine(New Pen(Color.Black), 2, 2, 500, 400)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

DrawIt(e.Graphics)

End Sub

Nov 21 '05 #2
See the article in Windows Forms Tips and Tricks that explains autoscroll

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:Od**************@TK2MSFTNGP15.phx.gbl...
To keep my example simple, let's say I have a windows application form
with a panel in it. For this example, I want to draw a single line in the
panel, which is larger than the size of the panel. Is there a way to get
the scrollbars to show up?

Also....If I were to put a control (like a button) into the panel, the
scrollbars are there...but my line doesn't redraw properly.

How should I be doing this? Thanks.

PS. here's code snip of what I'm trying to do....

Private components As System.ComponentModel.IContainer

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.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Me.Panel1.AutoScroll = True

Me.Panel1.BackColor = System.Drawing.Color.White

Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

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

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(472, 344)

Me.Panel1.TabIndex = 0

'

'Preview

'

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

Me.ClientSize = New System.Drawing.Size(592, 413)

Me.Controls.Add(Me.Panel1)

Me.Name = "Preview"

Me.Text = "Preview"

Me.ResumeLayout(False)

End Sub

Private Sub DrawIt(ByVal g As Graphics)

g.DrawLine(New Pen(Color.Black), 2, 2, 500, 400)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

DrawIt(e.Graphics)

End Sub

Nov 21 '05 #3
Thanks for the tip on using the matrix...works great!

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
See the article in Windows Forms Tips and Tricks that explains autoscroll

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Rob T" <RT*********@DONTwalchemSPAM.com> wrote in message
news:Od**************@TK2MSFTNGP15.phx.gbl...
To keep my example simple, let's say I have a windows application form
with a panel in it. For this example, I want to draw a single line in the
panel, which is larger than the size of the panel. Is there a way to get
the scrollbars to show up?

Also....If I were to put a control (like a button) into the panel, the
scrollbars are there...but my line doesn't redraw properly.

How should I be doing this? Thanks.

PS. here's code snip of what I'm trying to do....

Private components As System.ComponentModel.IContainer

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.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Me.Panel1.AutoScroll = True

Me.Panel1.BackColor = System.Drawing.Color.White

Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

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

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(472, 344)

Me.Panel1.TabIndex = 0

'

'Preview

'

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

Me.ClientSize = New System.Drawing.Size(592, 413)

Me.Controls.Add(Me.Panel1)

Me.Name = "Preview"

Me.Text = "Preview"

Me.ResumeLayout(False)

End Sub

Private Sub DrawIt(ByVal g As Graphics)

g.DrawLine(New Pen(Color.Black), 2, 2, 500, 400)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

DrawIt(e.Graphics)

End Sub


Nov 21 '05 #4
Thanks. That worked great. I couln't find any events that were like
OnAutoScroll...but when I scrolled, it refreshed on it's own anyway.
Perhaps it triggers the paint event automatically...
"VBen" <bm******@compucaremexico.com> wrote in message
news:Ow**************@TK2MSFTNGP15.phx.gbl...
You should use AutoScrollMinSize and AutoScrollMargin to let the control
know that your area has a certain size, whether it has other controls in
it
or not.
To redraw the line, you should capture the OnAutoScroll event (I don't
remember the exact name, but it's something like that) and call
[MyControl].Invalidate() or even [MyForm].Invalidate(true)...
With this, .Net calls the Paint event for your MyControl or your MyForm
(invalidating all children controls).
I'm not sure it's not called automatically if you set the drawing styles
of
your control... Try your code with the AutoScrollMinSize and Margin set,
and
do the scrolling to see if your line gets redrawn...
Hope this helps...
VBen.

"Rob T" <RT*********@DONTwalchemSPAM.com> escribió en el mensaje
news:Od**************@TK2MSFTNGP15.phx.gbl...
To keep my example simple, let's say I have a windows application form

with
a panel in it. For this example, I want to draw a single line in the

panel,
which is larger than the size of the panel. Is there a way to get the
scrollbars to show up?

Also....If I were to put a control (like a button) into the panel, the
scrollbars are there...but my line doesn't redraw properly.

How should I be doing this? Thanks.

PS. here's code snip of what I'm trying to do....

Private components As System.ComponentModel.IContainer

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.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Me.Panel1.AutoScroll = True

Me.Panel1.BackColor = System.Drawing.Color.White

Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

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

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(472, 344)

Me.Panel1.TabIndex = 0

'

'Preview

'

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

Me.ClientSize = New System.Drawing.Size(592, 413)

Me.Controls.Add(Me.Panel1)

Me.Name = "Preview"

Me.Text = "Preview"

Me.ResumeLayout(False)

End Sub

Private Sub DrawIt(ByVal g As Graphics)

g.DrawLine(New Pen(Color.Black), 2, 2, 500, 400)

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

DrawIt(e.Graphics)

End Sub


Nov 21 '05 #5
You may also be interested in this post:
http://blogs.msdn.com/rickbrew/archi...24/165493.aspx
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amrit | last post by:
Hi Can anyone help me? I would really appreciate I am trying to scroll Groupboxes inside the panel when i hold panel's scroll bar and drag up and...
4
by: Nathan | last post by:
I need a panel with only a vertical or only a horizontal scroll bar. Is there a way to do that? Nathan
0
by: Al | last post by:
Hi, I am using large PictureBox inside a Panel, user can write on the PictureBox (it is actually InkPicture) but the problem that I have is...
5
by: Sam | last post by:
Hi, I would like to reproduce the same control as in Visual Studio for the propery editor or the message feedback window. That is, a scrolling...
1
by: John | last post by:
Can I use the Atlas controls to create a scrolling panel in a webform? Basically I want a master page that defines 90% of the screen height to be...
0
by: Elroyskimms | last post by:
I have a fixed witdth panel control with horizontal scrollbars. In it, I load a table and in each table cell is an instance of a user control that...
2
by: shahoo | last post by:
Hi, I am trying to add some controls (say buttons) to a panel. At some stage the controls are too much to be show on the panel, so I set the...
0
by: mike | last post by:
Hi guys, I have a windows form and on load event I dynamically created a panel and dynamically create/add pictureboxes to panel and added a panel...
4
by: mateusz.zajakala | last post by:
Hi, I have panel (with autoscroll property) on which I'm dynamicaly adding of controls. When I want to scroll my panel using scrollbars it...
2
by: luker | last post by:
Hi Experts, I'm trying to create a panel-derived class with Autoscroll = true that scrolls horizontally when using <Shift>+Mousewheel. Sounds like...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.