Windows control size limit

6 posts, 1 answers
  1. Michael
    Michael avatar
    33 posts
    Member since:
    Mar 2009

    Posted 25 Mar 2009 Link to this post

    Hello -

    It is my understanding that Windows has a hard limit of 32767 pixels with respect to the size of a control.  WPF gets around this by not using Windows controls, but the Telerik WinForms controls are all based on System.Windows.Control.  Please correct me if I'm wrong, but I believe this means that none of the Telerik WinForms controls can exceed this maximum size.  Thus, even though Telerik has a very elaborate architecture that immitates WPF on WinForms, if I use that archecture to deeply nest a significant number of controls, grids, etc inside layers of panels, I will eventually hit that hard limit in Windows, correct?  Is there a way around this limit using Telerik WinForms?  I realize that I can get around it by using WPF, but that has a whole different set of problems that I'm trying to avoid.  It would be ideal if we could use Telerik WinForms controls to do the job.  I also realize that the nested tables in Telerik's RadGridView gets around this problem by nesting scrollbars, but the nature of my information won't lend itself to nested scrollbars.

    What I desire is a single smooth scrolling pane with a deep hierarchy of nested panels and controls like WPF, but the volume of information that I intend to put into that pane will easily exceed the maximum control height of 32767 (imagine a long Word Document with one scrollbar composed of nested panels/controls/grids/etc).  Is there a recommended solution on Telerik WinForms?

    Thanks,
    Michael Hewitt
    Precision Software Design, LLC
  2. Mike
    Admin
    Mike avatar
    640 posts

    Posted 26 Mar 2009 Link to this post

    Hi Michael,

     I am glad to answer this intriguing question. In general, as far as we know, WinForms controls do not have size limits (as long as Int32 is used to specify their size).

    To test this, I prepared a sample project which resembles the scenario you described. It displays a “document”, represented by a panel that has a height setting greater than Int32.MaxValue. It scrolls smoothly though 400 RadControls - panels, labels, buttons and grids. I have used the latest WinForms release to build the sample (2009.1.9.316), but it should work just as well with the previous versions of our tools, if you change the references and rebuild the project.

    However, some methods of GDI+ regarding drawing gradients, bitmaps, etc, are only able to handle rectangles, which are not greater than 32767px  (Int16.MaxValue) in any direction. Thus, some controls (like RadButton), which use such methods will fail when they are painted and their size is greater that the mentioned limit. Nevertheless, even in this extreme case, you can simply switch the GradientStyle of the corresponding control to Solid and it will work as expected.

    There may be other limitations that we are not aware of, so you would need to further test this case. Furthermore, if your case involves displaying large number of [nested] winforms controls I would suggest considering  a more virtualized approach where only the visible controls are created and managed by your document view. Otherwise you will see a large performance impact.

    Let me know if I can help further with this.

    Sincerely yours,
    Mike
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    33 posts
    Member since:
    Mar 2009

    Posted 26 Mar 2009 Link to this post

    Mike-
     
    Thank you for theprompt and thorough response.  You just made a sale for Telerik.  I came intothe office this morning planning to go with WPF, but your response changed mymind.  The VS solution you provided is solid gold.  It is exactly what I wasstumbling around trying to build myself and failing miserably.  I hope you won'tmind some follow-up questions:
     
    1. How do I insert an inner RadGridView as a child of a CellElement within an enclosing RadGridView?  Also, how do I cause the outer RadGridView to automatically size the corresponding row to the height of the inner RadGridView?  If this is not possible, is there a single element that can be used in an element hierarchy in place of the RadGridView?  I tried using the GridTableElement, but it complained that its parent was not a RadGridView.  My goal is to have an element with all the functionality of RadGridView, but which can freely participate in the element hierarchy, both as an arbitrary element child and as an arbitrary element parent.  The documentation states, "Typically TPF based controls are simple wrappers around RadItem descendant classes, and the RadItem descendant classes define logic and user interface".  Thus, I'm hoping to discover the RadItem descendent that defines all the logic and user interface for RadGridView.
    2. Depending on the answers to #1 & #2 above, this question may not be relevant.  My goal is to have an element with all the RadGridView functionality that plays well in the element layout hierarchy -- i.e. that automatically sizes itself and also that sizes its cells based on their child elements.  Thus, my question is as follows:  How do I cause RadGridView to take up as much space as it needs to display all rows?  Currently, I am manually setting RadGridView.Bounds, but I'd like to just have it auto size.  Note that I don't want the RadGridView to have a scrollbar -- as in your example code, I will enclose the grid view within a control will smooth scrolling parent (I realize that I lose the grid view virtualization by doing this, but I'm OK with that).  Setting AutoSize to true didn't do the trick.  If this is not possible, is there an easy way for me to determine this "desired size" (the space necessary to exactly display all rows without a scrollbar) so that I can manually set the Bounds to the proper value?
    3. I'm having trouble with the scroll position getting reset.  The repro is as follows:  1) Run the example you created above, 2) Move the scrollbar thumb to the bottom, 3) Alt+Tab to another application, 4) Alt+Tab back.  Result:  Scroll position is reset to the top.  I realize this is standard Winforms behavior, but I'm hoping that you might know how to prevent it from happening.
    4. How do I perform hit testing?  For example, how does the form determine the element above which the mouse is currently positioned?
    5. A full class hierarchy would be really nice.  For example, I'm curious to see all the classes that inherit from RadComponentElement.  Does such documentation exist?
    6. Setting ThemeResolutionService.ApplicationThemeName to "ControlDefault" in my form constructor as per the documentation (http://www.telerik.com/help/winforms/themes_using_a_default_theme_for_the_entire_application.html) did not cause all controls on the form to have the specified theme.  I tried this both with a RadForm and a standard Windows Form.  Note that I tried calling "new Telerik.WinControls.Themes.ControlDefaultTheme()" from the constructor first to simulate the theme having been dropped on the form in the designer.
     
    Thanks again!
    - Michael
     
    PS --  Previously, I encountered a situation where I could not make the standard Winforms DataGrid taller than 32767, no matter what I tried.  When I looking on Google, I was led to believe that this height restriction is a low-level Windows limitation.  However, since I received your response, I can no longer reproduce the limitation.  In case you are interested, here are some of the links that previously lead me to believe there was a limitation of 32767x32767 pixels on Windows control sizes:
  5. Mike
    Admin
    Mike avatar
    640 posts

    Posted 31 Mar 2009 Link to this post

    Hello Michael,

    I am glad that you decided to give our tools a try. We will try to help with whatever we can with your scenario.

    I apologize for the delay in my answer but I had to test a few possible solutions to the problems you are facing.

    1. Nesting grids.
    Generally speaking, RadGridView supports hierarchy that resembles the case of nesting grids. There are some examples with hierarchy in our Demo app, which you may want to look at.
    On the other hand nesting RadGridViews (or any controls) as child grids is possible and relatively easy to implement, but it will greatly affect performance. In the attached project I have demonstrated the way to do nested grids.

    The problem of nesting controls in a data-bound  control can also be solved by using the MS DataRepeater control. If you are not familiar with it, I have prepared another sample, which you can find in the attached project. Basically DataRepeater clones all controls initially added to its ItemTemplate in the designer and you just need to add a few more lines of code to make RadControls work with it. As you will see from the attached project, the scrolling in this case is smoother, because DataRepeater has all items in the same size and does not rely on heavy calculations. Let me know if you need assistance with this one.

    Moving to the next question, currently RadGridView can be used only as a control. There is no standalone RadItem that represents RadGridView functionality.

    As to browsing code and inheritors of RadItem, you can use .Net Reflector. It can navigate and find all classes that inherit from RadItem. Some of the 3dr party code navigation and refactoring tools, like Resharper also support this functionality. Unfortunately our documentation does not contain information on this which can help you.
     
    2. Calculating the grid's total height is not a simple task. It depends on many conditions, like whether the automatic-row sizing is turned on, virtual mode is on, and so on. RadGridVeiw was not designed to handle this case and there is no convenient API to this. I will consult with other devs to see if we can come up with a reasonable solution for this.

    3. In a Panel control (an any scollable control), you can scroll automatically the selected control into view. Thus if you walk through the child controls with the Tab key, the Panel will scroll to the top of the next control. I am not 100% sure about this, but I think if you have the correct control focused, the scroll position will not be affected after alt+tab. Please let me know if this does not solve the problem.

    4 HitTesting. The answer of this question depends on the specific case. RadGridView for example, has  convenient events for mouse-enter/leave for most of its significant UI elements, like cells, row, etc. If you need more general hit testing for any elements within a RadControl instance you can use this method:

    radControlInstance.ElementTree.GetElementAtPoint(Point)

    If your case involves monitoring the currently hovered RadElement within RadControl, you can handle the following event:
    radControlInstance.Behavior.HoveredElementChanged

    Also each RadElement has HitTest(Point) method that can be used to hit-test a specific element instance.

    5 Documentation
    We have both online and  MSDN-style documentation (installed together with the controls).  Unfortunately our documentation currently does not include inheritance diagrams. But as I already mentioned - Reflector together with some other free plug-ins can give a good idea on RadControls class hierarchy.

    Let me know how it goes and if I can help with any other questions.

    Regards,
    Mike
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  6. Michael
    Michael avatar
    33 posts
    Member since:
    Mar 2009

    Posted 01 Apr 2009 Link to this post

    Mike -

    I really appreciate your thorough response, and I am moving forward with our implementation atop Telerik Winforms controls.  I've decided not to nest a RadGridView inside another RadGridView cell because it doesn't really meet our requirements anyway.  However, I will still be nesting RadGridViews under elements, so knowing I can do that with RadHostItem & also knowing how to determine the RadGridView's "preferred size" will be critical to our success.  I appreciate your willingness to talk to the devs to come up with an answer on how to calculate the grid's total height, and I look forward to your response on this issue.

    Reflector did the trick for walking the class hierarchy (that tool was actually written by a friend of mine at Microsoft).  The mouse enter/leave events seem to work much better than in WPF, and so far are proving sufficient for our needs.

    The biggest problem I'm having right now is trying to get scrollbars to appear when I place a large StackLayoutPanel element on a form via a custom RadControl.  I started a separate thread on this issue (Placing a RadElement on a form).

    - Michael
  7. Answer
    Mike
    Admin
    Mike avatar
    640 posts

    Posted 02 Apr 2009 Link to this post

    Hi Michael,

    I have prepared you a sample with a large grid inside a panel, that I think works very closely to your requirements. The height and width of the grid are calculated dynamically and are updated based on various events, including, row add\delete, resize, grouping, expanding collapsing of grouped and hierarchy rows,  column show/hide resize, etc.

    The only drawback of the approach is that this way the application will have greater memory footprint. This is because setting a large size of RdGridView forces it to create UI elements for all visible rows and columns, which are generally much more expensive object in terms of memory, that the logical object RadGridView uses to keep track of data.

    Also some features of RadGridView would not behave as expected in this scenario:
    •   pinned rows and columns (including the header row, filtering row)
    •   some grid themes, that render gradient background - this will not work acording to what we've discussed previously.

    p.s.
    (The sample attached is the same as in the thread: Placing a RadElement on a form)

    Best wishes,
    Mike
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top
UI for WinForms is Visual Studio 2017 Ready