Autoscroll panel bug?

I

Igor

Hi all!

Here is the thing:
I have a panel with autoscroll set to true, and have controls that are outside the viewing area (thus the autoscroll:).
Now, I know that the autoscroll panel scrolls the focused control into view which is ok, but it also happens on paint event - when anything changes on the form, the control is focused into view.

In my example, I have two buttons on the panel. button1 is visible and button2 is on the bottom - you have to scroll to it.
To demonstrate this, try to scroll to button2 using the scrollbar on the panel WHILE the label is counting.
You can't, right?
Now, click button1 to stop the counter.
Now you can, right?

You have to keep the focus on button1 for the test to work.

What's up with that?
Is there a workaround?

PLEASE HELP!!!

Module Module1
Dim l As New System.Windows.Forms.Label
Dim tmr As New System.Windows.Forms.Timer

<STAThread()> Sub main()
Dim f As New System.Windows.Forms.Form
Dim p As New System.Windows.Forms.Panel
p.AutoScroll = True
p.Dock = Windows.Forms.DockStyle.Fill
p.Parent = f

Dim b As New System.Windows.Forms.Button

b.Text = "button1"
b.Location = New System.Drawing.Point(0, 0)
b.Parent = p
AddHandler b.Click, AddressOf click

b = New System.Windows.Forms.Button
b.Text = "button2"
b.Location = New System.Drawing.Point(0, f.Height * 2)
b.Parent = p

l.Text = "test"
l.Dock = Windows.Forms.DockStyle.Top
l.Parent = f

AddHandler tmr.Tick, AddressOf tick
tmr.Enabled = True


System.Windows.Forms.Application.Run(f)
End Sub

Sub click(ByVal sender As Object, ByVal e As EventArgs)
tmr.enabled = Not tmr.enabled
End Sub
Sub tick(ByVal sender As Object, ByVal e As EventArgs)
l.Text = Now.Ticks.ToString
End Sub
End Module
 
S

Stoitcho Goutsev \(100\)

Igor,

The problem is that If the AutoSize property is not set to True the label
revert its size to the original value. The because it is docked the whole
layout engine kick in and this moves the scrollers. Why? I don't know it
might be a bug...

I have two solutions for you:
1. Set label's AutoSize property to True
2. If for some reason you can't do (1) put the label on a panel, docke the
label Fill and dock the panel Top. This will take care of the problem
because the label will cause its container (the second panel) to re-layout
and this won't affect the panel with the scorll bars.
 
I

Igor

Stoitcho said:
Igor,

The problem is that If the AutoSize property is not set to True the label
revert its size to the original value. The because it is docked the whole
layout engine kick in and this moves the scrollers. Why? I don't know it
might be a bug...

I have two solutions for you:
1. Set label's AutoSize property to True
2. If for some reason you can't do (1) put the label on a panel, docke the
label Fill and dock the panel Top. This will take care of the problem
because the label will cause its container (the second panel) to re-layout
and this won't affect the panel with the scorll bars.
Thanks, but the label in the example is not the problem - I thought it
might be the layout issue. The real problem that I have is in a complex
form - a scrollable panel is inside another panel (also docked) and I'm
blinking the icon on the statusstriplabel (2005) on a statustrip. If I
put the statutstrip inside a panel and do as you suggested I'll be in a
world of hurt. especially because it is implemented in a superclass form
from which I derive all my forms...

I've created my own "scrollablepanel" which doesn't have this "feature",
but I'd like to minimize custom controls usage as they slow down already
quite poor performace of the UI.

But, thanx for the suggestion :)
Drop some other ideas if you've got'em :)
 

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