I wonder something. I have a Form with Vertical ScrollBars.
When running this code below that are inside a buttoncontrol when the scrollbar is at the top of the Form, the Form Scroll downs a bit, perheps 5-10 cm.

This is because I set button1->Enabled = false;
(I don´t know why the Form is scrolling down though when doing this)

Is it possible to not let the Form scroll down when running the code ?

button1->Enabled = false;

// Code Here

button1->Enabled = true;

I'm wondering something too.

Like how are we supposed to guess which OS / Compiler / UI Toolkit you're using from just a few UI buzzwords scattered through the post and 2 lines of code.

> Is it possible to not let the Form scroll down when running the code ?
It's hard to tell what your problem is without seeing all of the code, but to mitigate the effect of the problem you can move the scroll bar position back to 0. It's kludgy, but gives the desired effect. ;)

> how are we supposed to guess which OS / Compiler / UI Toolkit you're using
Jennifer84 isn't new to the forum, and all of her GUI questions that Edward has seen have been about Windows Forms in C++/CLI. Do you expect her to repeat the same information in every post despite her frequent threads concerning the same API?

Thank you. I use VC++ 2008 Express Edition.

I thought this perheps wasn´t so easy to know without see all the code.
The problem is that there is thousands of lines of code inside this button. : )

I tried to put it like this. It works but what happens is that the Form scroll down and
up again very fast, so it kind of ´blinks´.
It is probably not easy to know what it could depend on. I will try to experiment and
see if I can find any solution.

Why I want to Disable the button when pressing it is because if you press the button again and again very fast at the same time, you will have a "vector out of range" Error because
the calculation isn´t finished.
Perheps there could be an other way to disable it or prevent to press the button until it is finished.
button1->Visible = true; perheps isn´t the best either because calculations can take a while sometimes and the user might wonder where the button is :)

button1->Enabled = false;
Form2::VerticalScroll->Value = 0;

button1->Enabled = true;

> Perheps there could be an other way to disable it or prevent to press the button until it is finished.
Edward would probably use a processing flag while the calculation is running. Set the flag to true when the button is clicked--or do nothing if the flag is already set--and unset it when the calculation finishes:

bool _isProcessing;

void buttonCalculate_Click(Object^, EventArgs^)
{
  if (_isProcessing)
    return;

  _isProcessing = true;

  // Run calculation
}

void backgroundWorker_RunWorkerCompleted(Object^, RunWorkerCompletedEventArgs^)
{
  _isProcessing = false;
}

That assumes you're running the calculation in a BackgroundWorker thread.

Yes ofcourse, this is a very good idéa. I will try this approach.

Thank you...

> Perheps there could be an other way to disable it or prevent to press the button until it is finished.
Edward would probably use a processing flag while the calculation is running. Set the flag to true when the button is clicked--or do nothing if the flag is already set--and unset it when the calculation finishes:

bool _isProcessing;

void buttonCalculate_Click(Object^, EventArgs^)
{
  if (_isProcessing)
    return;

  _isProcessing = true;

  // Run calculation
}

void backgroundWorker_RunWorkerCompleted(Object^, RunWorkerCompletedEventArgs^)
{
  _isProcessing = false;
}

That assumes you're running the calculation in a BackgroundWorker thread.

This question has already been answered. Start a new discussion instead.