ZForge.Controls.ExplorerBar.TaskItem.CalcGdiPreferredHeight C# (CSharp) Méthode

CalcGdiPreferredHeight() protected méthode

Calculates the preferred height of the TaskItem using GDI
protected CalcGdiPreferredHeight ( Graphics g ) : int
g System.Drawing.Graphics The Graphics used to measure the TaskItem
Résultat int
        protected int CalcGdiPreferredHeight(Graphics g)
        {
            IntPtr hdc = g.GetHdc();

            int height = 0;

            if (hdc != IntPtr.Zero)
            {
                IntPtr hFont = this.Font.ToHfont();
                IntPtr oldFont = NativeMethods.SelectObject(hdc, hFont);

                RECT rect = new RECT();

                int width = this.Width - this.Padding.Right;

                if (this.Image != null)
                {
                    width -= 16 + this.Padding.Left;
                }

                rect.right = width;

                NativeMethods.DrawText(hdc, this.Text, this.Text.Length, ref rect, DrawTextFlags.DT_CALCRECT | this.DrawTextFlags);

                height = rect.bottom - rect.top;

                NativeMethods.SelectObject(hdc, oldFont);
                NativeMethods.DeleteObject(hFont);
            }
            else
            {
                height = this.CalcGdiPlusPreferredHeight(g);
            }

            g.ReleaseHdc(hdc);

            return height;
        }