Windows.Forms.Panel 32767 Size Limit

Windows.Forms.Panel 32767 size limit

This is an architectural limitation in Windows. Various messages that indicate positions in a window, like WM_MOUSEMOVE, report the position in a 32-bit integer with 16-bits for the X and 16-bits for the Y-position. You therefore cannot create a window that's larger than short.MaxValue. This isn't exactly a real problem, nobody has a monitor that's wider than 32,767 pixels and won't for a long time to come.

You'll have to do this differently. Like using Graphics.TranslateTransform() in a Paint method.

Controls in panel are hidden until I resize the window

@Yas,

This was a rather intriguing problem--didn't quite grasp it until loading/running your code. I happen to agree with Jimi--that you're probably running up against an internal limitation, however bizarre that limitation appears to be. As you pointed out, tweaking the height/width of the form shouldn't overcome a limitation. So whatever's going on internally, it's a bit odd and unexpected.

But I have a solution for you: It's admittedly a kludge but sometimes that's our only option. If your project specs require a form like the one you presented--a form that ends up with a height value well over 100,000, then this solution should fit the bill.

Add the following code to the end of your Form1 initialization code, shown in your original post (see below). What I've done is programmatically "tweaked" the height of the form ever so slightly--repeatedly--until all of the panels have been fully rendered. I think this is going to be your best bet.

For the record, I had spent quite a bit of time on this. I had tried various combinations of Refresh() on various controls, DoEvents(), etc., to no avail. I even tried not using docking and autosizing, in favor of setting top and heights manually (that didn't work either). Thus, I think the code below is really the only way to fix this, aside from a fix from Microsoft.

** For the code below to work, add this line immediately after your code's InitializeComponent(); line:

this.Show();

Then add this code after your code's closing brace:

     // fix the panContents panel
long currentMaximum = 0;
while (true)
{
var preserveHeight = this.Height;
// tweak the height
this.Height += 1;
// set it back the height
this.Height = preserveHeight;

// test to see if the scroll bar max remains at its previous value
// if it does, we're done
if (currentMaximum == panContents.VerticalScroll.Maximum)
break;

// otherwise, preserve the current maximum scroll bar position
currentMaximum = panContents.VerticalScroll.Maximum;

// now scroll to the bottom of the panel
panContents.VerticalScroll.Value = panContents.VerticalScroll.Maximum;
// necessary step to ensure scroll bar value is set
panContents.PerformLayout();
}

// scroll to the top
panContents.VerticalScroll.Value = 0;
// necessary step to ensure scroll bar value is set
panContents.PerformLayout();

Adding dynamic controls to form with auto scroll

This limit (32767) is due to GDI+. I believe different behaviours may be observed according to the Windows version.

The maximum number of characters a TextBox can display

From my tests I find that a Textbox can't display lines that would exceed 32k pixels given the Font of the TextBox.

Using this little testbed

public Form1()
{
InitializeComponent();

textBox1.Font = new System.Drawing.Font("Consolas", 32f);
G = textBox1.CreateGraphics();
for (int i = 0; i < 100; i++) textBox1.Text += i.ToString("0123456789");
}

Graphics G;

private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++) textBox1.Text += i.ToString("x");
Console.WriteLine( textBox1.Text.Length.ToString("#0 ")
+ G.MeasureString(textBox1.Text, textBox1.Font).Width);
}

You can see that the display vanishes once the width would exceed 32k. For the chosen big Fontsize this happens with only about 1350 characters. This should explain our different results from the comments, imo.

The Text still holds the full length of the data.

Update: Acoording to the answers in this post this limit is not so much about TextBoxes and their Lines but about Windows Controls in general:

Hans Passant writes:

This is an architectural limitation in Windows. Various messages that
indicate positions in a window, like WM_MOUSEMOVE, report the position
in a 32-bit integer with 16-bits for the X and 16-bits for the
Y-position. You therefore cannot create a window that's larger than
short.MaxValue.

So when calculating its display, the TextBox hits that limit and silently/gracfully(??) doesn't display anything at all.



Related Topics



Leave a reply



Submit