location property

  • Thread starter Thread starter SwatSoftwareDev
  • Start date Start date
S

SwatSoftwareDev

Hi,
Is there any way to have location property's X or Y greater than 32767.
Thanks in advance,

Regards,
Swat
 
I belive that the 16-bit position limit is a function of the Windows OS
itself. You should see the same results with a C++/MFC program as well
as .NET.

You probably know that the Location property of Control is a Point
structure. The X and Y properties of Point are int's (Int32), of which
MSDN says:

"The Int32 value type represents signed integers with values ranging
from negative 2,147,483,648 through positive 2,147,483,647"

So, if you are using a Point structure outside of a Control, you should
be able to set it to any values within the range of Int32. You can
even set the values of a Control's location to something larger than
32767, but it gets fixed to 32767 after window layout and validation
occurs.

// If you run this code in a console app, you will get 1000000000 as
the outputs:
Control ctrl = new Control("Test", 1000000000, 1000000000, 100, 100);
Point pt = new Point(1000000000, 1000000000);
Console.WriteLine(pt.X.ToString());
Console.WriteLine(ctrl.Location.X.ToString());

// However, if you create a Windows Forms app with a PictureBox on the
form, and run this code in the forms constructor:
pictureBox1.Location = new Point(1000000000, 1000000000);
Console.WriteLine(pictureBox1.Location.ToString());
// This is output: {X=32767,Y=32767}

Unfortunately, I haven't found documentation of the 16-bit limit on
positions and sizes in Windows. Maybe someone else on the group may
have a link.

What are you trying to do?

-- Tim Scott
http://geekswithblogs.net/tscott
 
Aha, found it:
From Ian Griffiths:
There are a few places in Windows Forms where your values get truncated
to 16 bits. The ToolTip timeouts are another case. It's usually because
of an underlying limitation in Windows itself.

When a window is resized, it will be sent a WM_SIZE notification. The
size is encoded in a single 32-bit number (the LPARAM of the message) in
which the width and height are packed. This means that the width and
height cannot exceed 16 bits with this message. So even though many of
the windowing APIs allow you to pass 32-bit dimensions, it rather looks
like the WM_SIZE message imposes this smaller limit."

From
http://discuss.develop.com/archives/wa.exe?A2=ind0404c&L=dotnet-winforms&T=0&F=&S=&P=3130

-- Tim Scott
http://geekswithblogs.net/tscott
 
Swat,

The location of the control is indeed limited to 16-bit values. This is
unfortuante because since scroll bars support 32-bit position and this is I
guess what you want to use it for.

Tim, I wouldn't necessary say that the 16-bit information that comes with
windows messages is proof for API limitation. There is other examples where
WM_* provide 16-bit information, but the real 32-bit values can be obtained
using API methods.
Even the example with WM_SIZE is incorrect becuase MSDN state "Although the
width and height of a window are 32-bit values, the lParam parameter
contains only the low-order 16 bits of each."

Swat, if you want to implement scrolling I wouldn't say that form's with so
many controls that you need to set a position beyond the max 16-bit value
will be any good. That form of yours will have a huge usability issue.
 
Back
Top