Handling DPI changes in windows form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pakmarshal
    New Member
    • Aug 2009
    • 17

    Handling DPI changes in windows form

    Hi,

    I am developing a windows based application in VB 2005, the main form of the application is of fixed border style (i.e. user cannot resize the form), but in certain cases I am resizing my form through code. Intially the form has a fixed height i.e. 350 for normal height and 400 for extended height. But in this case the problem could not be solved effectively as the user can have different DPI setting e.g. 120, 144, 192 etc. The logic I implemented is to divide my form (vertically) into 3 parts

    1. Menu
    2. Toolstrip
    3. A panel containing the all controls on the form.

    I have arranged the controls in such a manner that no pixel lies between 2 controls. while deciding for the height of the form I use the formula i.e. TitleBarHeight+ MenuHeight + ToolStripHeight + MainPanelHeight + Border. The logic seems ok with 96 DPI but in case of 120 DPI it always returns 3 pixels lesser than the height of the form, similarly in case of 144 and 192 DPI it returns 5 pixels lesser. On the basis of this pixel calculation on the first launch of the application, form shrinks a little which appears to be odd. (ONLY ONCE per execution).

    Can anyone help me whats going wrong? Or what could be a better approach?

    Thanks & Regards,
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Loop through all the controls on the form.
    Get the Bound.Bottom of the control.
    Record the lowest control.
    Resize to encompass the lowest control.

    Comment

    Working...