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