WinForms TreeView Display positioning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbturner
    New Member
    • Feb 2016
    • 2

    #1

    WinForms TreeView Display positioning

    I have a TreeView (System.Windows .Forms.TreeView ) control on a custom control (similar to the Output window in visual studio 2013). that control is placed at the bottom of a main form (like the visual studio ide). when i populate this TreeView control with data, it fills correctly, but, if the containing control is close to the bottom, the displayed "popup" is cut off. if i expand the lower control to have more room, the control displays with all the data. the display is "docked" to where it was designed. i tried putting a scrollbar on the display (which worked), but this is not the desired/requested behavior.

    what i would like to do is to either have the display "go up", if necessary, like the "Show output from:" display on the Output window in Visual Studio 2013, or, simply have the display be FreeFloating.

    note: this is an existing Winforms application and this is an enhancement request.

    any suggestions would be greatly appreciated.

    thanks in advance.

    pete.
  • pbturner
    New Member
    • Feb 2016
    • 2

    #2
    RESOLVED:
    - create 3 new variables ... originalParent, originalLocatio n, and firstTime.
    - in the Resize method (which is called from a mouseOver event), where the size of the display is set, if this is the first time, save off the above and set the parent to the TopLevelControl
    - determine the new location on the form ... originalParent. FindForm().Poin tToClient(origi nalParent.Point ToScreen(origin alLocation).
    - see if the displayed output would go beyond the end of the top form ... TopLevelControl .DisplayRectang le.Height - (locationOnForm .Y + oTreeView.Displ ayRectangle.Hei ght)
    - if the difference is less than 0, adjust the new location.Y by the difference.
    - set the display output Location to the new location

    presto ...

    - also, added a method so that when the main form is resized, or the containing control is repositioned, the location is set using the info above - just not adjusting for the display output height.
    - add a call to the reset in the mouseLeave event

    Comment

    Working...