Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms: Maximum Size of a Control is 65535 - Workaround?

Tags:

c#

winforms

In WinForms and C#, it seems I cannot create a control wider than 65535. If I set it to 70.000, the value gets reset to 65535. Digging through the source of Control.Size with ILSpy, I couldn't immediately find the code responsible for clamping the size.

So is this a limit of the Win32 API or of Windows Forms? Is there any way around this, e.g. with unmanaged interop?

The reason I need such a large control is that I draw music waveform of very long audio files onto it. (Yes, I could draw the waveform directly, without a containing control; but that would require lots of refactoring). I am not talking about the drawing code here. Clearly it's necessary to draw only the visible part, but the thing is that I'd like to have a control as wide as 200.000 pixels.

like image 805
LTR Avatar asked Dec 16 '22 21:12

LTR


2 Answers

It is a winapi restriction. A pretty hard one, the mouse position is reported with, say, the WM_MOUSEMOVE message with the mouse position packed into the LPARAM argument. With 16 bits for the X- and 16-bits for Y-location.

You'll have to deal with it. It is not a limitation on for example the AutoScrollMinSize property of a panel. Which is what you'd always use in this case anyway, start painting at AutoScrollPosition.

like image 156
Hans Passant Avatar answered Jan 14 '23 18:01

Hans Passant


I do think its a limitation of windows forms, the thing is, for your needs a WPF form would be more suitable as it allows larger loads. Just my opinion.

like image 42
Freeman Avatar answered Jan 14 '23 17:01

Freeman