Windows.Forms.Panel 32767 Size Limit

I have an application that uses Windows.Forms.Panel to display a list of images. When the height of the panel exceeds 32767 pixels, the rest of the content is simply cropped.

Example:

 Windows.Forms.Panel myPanel; ArrayList pictureList; foreach(pic in pictureList) { myPanel.Controls.Add(pic) // adds all the objects without complaints } 

In this example, all elements are added to the panel without error, but after the panel reaches the size 32767, the image is no longer displayed.

My question is: is it possible to break this limit and display more content on the panel?

I know that this approach is by no means impossible, but now there is no time to redo the entire application.

+6
source share
4 answers

This is an architectural limitation in Windows. Various messages that indicate positions in the window, such as WM_MOUSEMOVE, report a position in a 32-bit integer with 16-bit for X and 16-bit for Y-position. Therefore, you cannot create a window that is larger than short.MaxValue. This is not a real problem, no one has a monitor that exceeds 32,767 pixels and will not last a long time.

You will have to do it differently. Like the use of Graphics.TranslateTransform () in the Paint method.

+11
source

LPARAM is a Windows data type used to pass message parameters to a Windows procedure. This is a 32-bit pointer that transmits a message as two parts: I am in high order (the first 16 bits of 32 bits) and the youngest (second 16 bits of 32 bits).

  Where High order is used to pass the height of the control and Low order is used to pass the width of the control 

So, if the height or width of the control exceeds 32762, it shows an error because

32767 is the highest number that can be represented in a signed 16-bit integer value.

+1
source

Solution without a drawing method

I had this exact problem. I did not want to rewrite functionality that was already encoded into my child controls. This routine manages child controls using the scroll bar and stores hidden and unclosed hidden objects.

 Public Class ManuallyScrollingPanel Inherits Panel Public WithEvents sbar As New System.Windows.Forms.VScrollBar Sub New() MyBase.New() Controls.Add(sbar) sbar.Visible = True Me.AutoScroll = False End Sub Sub SetScrollParams() If PanelPositions.Any Then Dim NewMax = CInt((From item In PanelPositions.Values Select item.Bottom).Max + 500) - Height If sbar.Maximum <> NewMax Then sbar.Maximum = NewMax End If End If End Sub Public Sub RegisterChildSize(pnl As Panel, DesiredBounds As Drawing.Rectangle) PanelPositions(pnl) = DesiredBounds SetScrollParams() End Sub Dim PanelPositions As New Dictionary(Of Panel, Drawing.Rectangle) Private Sub ManuallyScrollingPanel_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged sbar.Top = 0 sbar.Left = Width - sbar.Width sbar.Height = Me.Height SetScrollParams() sbar.LargeChange = CInt(Height * 0.9) sbar.SmallChange = CInt(Height * 0.2) End Sub Private Sub sb_Scroll(sender As Object, e As ScrollEventArgs) Handles sbar.Scroll ScrollTo(e.NewValue) End Sub Private Sub sb_ValueChanged(sender As Object, e As EventArgs) Handles sbar.ValueChanged ScrollTo(sbar.Value) End Sub Sub ScrollTo(pos As Integer) Me.AutoScroll = False For Each kvp In PanelPositions Dim VirtBounds = New Drawing.Rectangle(CInt(kvp.Value.Left), CInt(kvp.Value.Top - pos), CInt(kvp.Value.Width), CInt(kvp.Value.Height)) If VirtBounds.Bottom < 0 Or VirtBounds.Top > Height Then ' it not visible - hide it and position offscreen kvp.Key.Visible = False kvp.Key.Top = VirtBounds.Top Else ' Visible, position it kvp.Key.Top = VirtBounds.Top kvp.Key.Visible = True End If Next End Sub End Class 

Then for each child control (mine dynamically added, sounds like the OP does the same) make this call:

 CType(Parent, ManuallyScrollingPanel).RegisterChildSize(Me, PanelObject.Bounds) 

Note. I pass the child constraints separately when I create the controls from the DTO in order to allow the same display of the + application as a web application and a Windows application. Same thing with restricting it to a panel. Refactoring if necessary.

+1
source

Why don't you add the scroll bar to the bar

just set AutoScrollbar = true

and just set the RightToLeft property to true.

-1
source

Source: https://habr.com/ru/post/901108/


All Articles