개발일기/C#

폰트 크기에서 폰트 높이로 단위 변환

쌀덕이 2016. 2. 19. 13:13


        [DllImport("user32.dll")]

        public static extern IntPtr GetDC(IntPtr ptr);

        [DllImport("user32.dll")]

        public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);

        [DllImport("kernel32.dll")]

        static extern int MulDiv(int nNumber, int nNumerator, int nDenominator);

        [DllImport("gdi32.dll")]

        static extern int GetDeviceCaps(IntPtr hdc, int nIndex);


        private int GetFontHeight(int pt)

        {

            IntPtr hdc = GetDC(this.Handle);

            int height = -MulDiv(pt, GetDeviceCaps(hdc, 90/*LOGPIXELSY*/), 72);

            ReleaseDC(this.Handle, hdc);

            return height;

        }


출저 : http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=803896&ref=803896

'개발일기 > C#' 카테고리의 다른 글

영역 색상 반전  (0) 2016.02.23
Win32 API를 쓸때 유용한 페이지  (0) 2016.02.23
Control 기본 이벤트 지정.  (0) 2016.01.12
[C#] Excel에서 RowsCount, ColumnsCount 구하기  (0) 2014.07.08
[C#] 비동기 프로그래스바.  (0) 2014.05.30