c# - Custom TabControl display issues -
i've been writing custom drawn tab control few days , part pretty , amazing job ... except when use on windows 10 computer (at run-time).
i've gone basic few lines of code trace error , can't life of me figure out.
below code being used, in nutshell i'm designing horizontal aligned tab control.
using system.drawing; using system.windows.forms; namespace windowsformsapplication1.ui { class tabcontroltest : tabcontrol { public tabcontroltest() { alignment = tabalignment.left; sizemode = tabsizemode.fixed; } } } 
i've added custom tab control form, added couple of group boxes reference purposes , changed background colour of form grey can see tab control.
now, at design time 2 group boxes (1 in tab control, 1 on form) align perfectly.
but @ run-time see different result.

as can see tab part of control larger @ design time , resulting change means contexts of tab have moved.
if on windows 7 computer displayed appears @ design time, should!
i've added imagesize makes no difference.
itemsize = new system.drawing.size(30, 150); i've reinstalled vs on (win10) development machine. i'm @ loss explain why , how resolve this.
any/all immensely appreciated.
looking @ tab width in comparison images, believe issue caused automatic windows control scaling. found dpiaware option automatically set when it's run within visual studio , reverts default windows scaling windows implements when outside visual studio.
to prevent auto-scaling when run outside visual studio altogether need notify os you're application dpiaware calling win32 p/invoke setprocessdpiaware() method within main() before application.run() called, example below demonstrates. let controls use native resolution designing coordinates from.
static class program { [system.runtime.interopservices.dllimport("user32.dll")] private static extern bool setprocessdpiaware(); static void main(string[] args) { if (environment.osversion.version.major >= 6) setprocessdpiaware(); application.run(new uimonitor()); } } alternatively, if want keep scaling, may able set groupbox location based off width of tab control instead of specific location. (or using combination of control measurements instead of exact picel placement.)
Comments
Post a Comment