I can't see the difference

  • Thread starter Thread starter ReaanB
  • Start date Start date
R

ReaanB

For some reason, the following line won't work as expected:

int r = ClientRectangle.Right - (VerticalScroll.Visible ?
SystemInformation.VerticalScrollBarWidth : 0);

I placed it in the Click event handler of a new button on an empty
form in a new project. Intellisense evaluates the expression
correctly, but when I inspect the variable after the line is executed,
its value is 0.

The following works as expected:

int r1 = ClientRectangle.Right;
int r2 = (VerticalScroll.Visible ?
SystemInformation.VerticalScrollBarWidth : 0);
int r = r1 - r2;
 
ReaanB said:
For some reason, the following line won't work as expected:

int r = ClientRectangle.Right - (VerticalScroll.Visible ?
SystemInformation.VerticalScrollBarWidth : 0);

Works fine for me. My best guess is that the above code is NOT actually
the code you're having trouble with. My next best guess, if the above
code is literally copy-and-paste from your program, that the code is not
in the context you describe.

In any case, if you post a concise-but-complete code example that
reliably reproduces the problem, I'm sure I or someone else will be able
to point out what's wrong.

Pete
 
Works fine for me.  My best guess is that the above code is NOT actually
the code you're having trouble with.  My next best guess, if the above
code is literally copy-and-paste from your program, that the code is not
in the context you describe.

In any case, if you post a concise-but-complete code example that
reliably reproduces the problem, I'm sure I or someone else will be able
to point out what's wrong.

Pete

Thanks for the reply and testing, Pete. Unfortunately, the code is as
described.

I did further tests, and it seems that in 64-bit, the assignment to
the variable gets deferred until the next step. Executing other code
(but not in the Immediate window) causes the correct value to show.
There's also something funny with breakpoints - if the assignment is
followed by MessageBox.Show(r.ToString()); then I can't set a
breakpoint on the call to the messagebox. If I add any other code in
between, the breakpoint works.

Anyway, I can simply ignore the problem for now by choosing 32-bit.
 
ReaanB said:
I did further tests, and it seems that in 64-bit, the assignment to
the variable gets deferred until the next step. Executing other code
(but not in the Immediate window) causes the correct value to show.
There's also something funny with breakpoints - if the assignment is
followed by MessageBox.Show(r.ToString()); then I can't set a
breakpoint on the call to the messagebox. If I add any other code in
between, the breakpoint works.

The above is all completely consistent and expected if you are trying to
debug a Release build of your program. You could in fact even see the
same kind of behavior, though perhaps with slightly different specifics,
with a 32-bit build.

If you are seeing that behavior while debugging a Debug build of your
program, then either you've got an out-of-date PDB file, or somehow your
Visual Studio has gotten corrupted and the debugger's not working correctly.

Pete
 
Back
Top