Freigeben über


Annoying thing happening with AutoScroll...

This AutoScroll feature
on controls that are ScrollableControls is
pretty neat, but there is a slight problem. Here's the scenario...

Project Setup:

  1. Add a Panel control to a Windows Form. Set
    it to AutoScroll.
  2. Within this Panel add a PictureBox. Make this set to AutoSize. Load a large image on the Form's Load
    event.
  3. Add a Button to the Windows Form. The code
    for the Button's Click event should be pictureBox1.Select()

Test Scenario:

  1. After the application has loaded, scroll to the lower right hand corner of
    the PictureBox on the Panel.
  2. Now click the Button.
  3. Notice that the Location of the PictureBox has changed.

This is quite annoying!! I would have figured that the Location should not change. I tried to figure out a
way to prevent this from happening, but after an extensive search I kept getting
the same result. In an internal method call, the RectLocation is being set to
(0,0). I would have figured that the Location
should not change after a Select(). Here's the
relevant portion of my stack trace along with the line that sets the position
back to (0,0) highlighted:

TestApp.exe!TestApp.TestApp.pictureBox1_LocationChanged(System.Object
sender = {System.Windows.Forms.PictureBox}, System.EventArgs e =
{System.EventArgs}) Line
668 C#
system.windows.forms.dll!System.Windows.Forms.Control::OnLocationChanged(System.EventArgs
e = {System.EventArgs}) + 0x73
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::UpdateBounds(__int32
x = 0, __int32 y = 0, __int32 width = 1752, __int32 height = 1168, __int32
clientWidth = 1752, __int32 clientHeight = 1168) + 0xb1
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::UpdateBounds()
+ 0xb8
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::WmMove(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x20
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x6ac
bytes 
system.windows.forms.dll!ControlNativeWindow::OnMessage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19
bytes 
system.windows.forms.dll!ControlNativeWindow::WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda
bytes 
system.windows.forms.dll!System.Windows.Forms.NativeWindow::DebuggableCallback(__int32
hWnd = 2032966, __int32 msg = 3, __int32 wparam = 0, __int32 lparam = 0) +
0x39 bytes 
system.windows.forms.dll!System.Windows.Forms.ScrollableControl::SetDisplayRectLocation(__int32
x = 0, __int32 y = 0) + 0x254
bytes
 
system.windows.forms.dll!System.Windows.Forms.ScrollableControl::ScrollControlIntoView(System.Windows.Forms.Control
activeControl = {System.Windows.Forms.PictureBox}) + 0x366
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::ScrollActiveControlIntoView()
+ 0x3e
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::ActivateControlInternal(System.Windows.Forms.Control
control = {System.Windows.Forms.PictureBox}, bool originator = true) + 0x99
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::ActivateControlInternal(System.Windows.Forms.Control
control = {System.Windows.Forms.PictureBox}) + 0x19
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::WmSetFocus(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x93
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x7bb
bytes 
system.windows.forms.dll!ControlNativeWindow::OnMessage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19
bytes 
system.windows.forms.dll!ControlNativeWindow::WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda
bytes 
system.windows.forms.dll!System.Windows.Forms.NativeWindow::DebuggableCallback(__int32
hWnd = 2032966, __int32 msg = 7, __int32 wparam = 918718, __int32 lparam = 0)
+ 0x39
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::FocusActiveControlInternal()
+ 0x6e
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::SetActiveControlInternal(System.Windows.Forms.Control
value = {System.Windows.Forms.PictureBox}) + 0x94
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::SetActiveControl(System.Windows.Forms.Control
ctl = {System.Windows.Forms.PictureBox}) + 0x2f
bytes 
system.windows.forms.dll!System.Windows.Forms.ContainerControl::set_ActiveControl(System.Windows.Forms.Control
value = {System.Windows.Forms.PictureBox}) + 0x16
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::Select(bool
directed = false, bool forward = false) + 0x32
bytes 
system.windows.forms.dll!System.Windows.Forms.Control::Select()
+ 0x15 bytes 
TestApp.exe!TestApp.TestApp.button4_Click(System.Object
sender = {Text="button4"}, System.EventArgs e = {System.EventArgs}) Line
664 C#

Maybe in future versions this can be a flag... ResetRect = true or
false.