why this app hangs?

  • Thread starter Thread starter DM
  • Start date Start date
D

DM

Hello.

Could some explain what's wrong with this app - it hangs when I hit one
of arrows of VScrollBar.

using System;
using System.Data;
using System.Windows.Forms;

namespace VScrollBar
{
class Class1 : System.Windows.Forms.Form
{
System.Windows.Forms.VScrollBar scrollBar;

Class1()
{
scrollBar = new System.Windows.Forms.VScrollBar();
scrollBar.Maximum = -100;
scrollBar.Minimum = 100;
scrollBar.SmallChange = 1;
scrollBar.LargeChange = 2;
scrollBar.Value = 0;
scrollBar.ValueChanged += new EventHandler(scrollBar_ValueChanged);

scrollBar.Location = new System.Drawing.Point(100,100);
scrollBar.Size = new System.Drawing.Size(20,40);
Controls.Add(scrollBar);
}

void scrollBar_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show("" + scrollBar.Value);
}
static void Main(string[] args)
{
Application.Run( new Class1() );
}

}
}


Thanks for any help.
 
It's just a guess, but usually you want the maximum value to be > the
minimum value.

Paul T.
 
Hello.

Sorry, it was my mistake. However is you swap maximum
and minimum value result is even more interesting
:-(
 
ScrollBar.ValueChanged is filred on mouse *down*. Then scrollbar autorepeats
increment until it receives mouseup. By calling MessageBox you create a
modal window that steals input from the scrollbar. This leads to all kind of
problems. The rule of thumb is not to create, destroy or activate any
windows inside ScrollBar.ValueChanged.
 
Back
Top