public override int RenderTextEx(IntPtr htheme, IntPtr hdc, int partid, int stateid, string psztext, int cchtext, NativeMethods.DT dwtextflags, IntPtr prect, ref NativeMethods.DTTOPTS poptions) { switch ((Parts)partid) { case Parts.LVP_GROUPHEADER: { NativeMethods.GetThemeColor(htheme, partid, stateid, poptions.iColorPropId, out var crefText); var color = Color.FromArgb(crefText.R, crefText.G, crefText.B); var adaptedColor = color.AdaptTextColor(); // do not render, just modify text color poptions.iColorPropId = 0; poptions.crText = ColorTranslator.ToWin32(adaptedColor); // proceed to default implementation with modified poptions parameter return(Unhandled); } } return(Unhandled); }
public override int RenderTextEx(IntPtr htheme, IntPtr hdc, int partid, int stateid, string psztext, int cchtext, NativeMethods.DT dwtextflags, IntPtr prect, ref NativeMethods.DTTOPTS poptions) { Color textColor; switch ((Parts)partid) { case Parts.CP_READONLY: switch ((State.Readonly)stateid) { case State.Readonly.CBRO_NORMAL: case State.Readonly.CBRO_HOT: case State.Readonly.CBRO_PRESSED: textColor = SystemColors.ControlText; break; case State.Readonly.CBRO_DISABLED: textColor = SystemColors.ControlDark; break; default: return(Unhandled); } // do not render, just modify text color poptions.dwFlags |= NativeMethods.DTT.TextColor; poptions.iColorPropId = 0; poptions.crText = ColorTranslator.ToWin32(textColor); return(Unhandled); default: return(Unhandled); } }
public virtual int RenderTextEx(IntPtr htheme, IntPtr hdc, int partid, int stateid, string psztext, int cchtext, NativeMethods.DT dwtextflags, IntPtr prect, ref NativeMethods.DTTOPTS poptions) { return(Unhandled); }
public override int RenderTextEx(IntPtr htheme, IntPtr hdc, int partid, int stateid, string psztext, int cchtext, NativeMethods.DT dwtextflags, IntPtr prect, ref NativeMethods.DTTOPTS poptions) { switch ((Parts)partid) { case Parts.TVP_TREEITEM: { if (poptions.dwFlags.HasFlag(NativeMethods.DTT.TextColor)) { return(Unhandled); } Color foreColor; switch ((State.Item)stateid) { case State.Item.TREIS_DISABLED: foreColor = SystemColors.GrayText; break; case State.Item.TREIS_SELECTED: case State.Item.TREIS_HOTSELECTED: case State.Item.TREIS_SELECTEDNOTFOCUS: foreColor = SystemColors.WindowText; break; case State.Item.TREIS_NORMAL: case State.Item.TREIS_HOT: foreColor = SystemColors.WindowText; break; default: return(Unhandled); } // do not render, just modify text color poptions.dwFlags |= NativeMethods.DTT.TextColor; poptions.iColorPropId = 0; poptions.crText = ColorTranslator.ToWin32(foreColor); break; } } return(Unhandled); }
/// <summary> /// Measures the specified string when drawn with the specified <see cref="Font"/> and formatted with the specified <see cref="StringFormat"/>. /// </summary> /// <param name="g">Graphics instance.</param> /// <param name="text">String to measure.</param> /// <param name="font"><see cref="Font"/> defines the text format of the string.</param> /// <param name="layoutArea">SizeF structure that specifies the maximum layout area for the text.</param> /// <param name="stringFormat"><see cref="StringFormat"/> that represents formatting information, such as line spacing, for the string.</param> /// <returns>This method returns a <see cref="SizeF"/> structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter.</returns> public static SizeF MeasureString(this Graphics g, string text, Font font, SizeF layoutArea, StringFormat stringFormat) { IntPtr hdc = g.GetHdc(); RECT r = new RECT(); r.right = Convert.ToInt32(layoutArea.Width); r.bottom = Convert.ToInt32(layoutArea.Height); NativeMethods.DT dt = NativeMethods.DT.CALCRECT | NativeMethods.DT.NOCLIP; if (stringFormat != null) { switch (stringFormat.Alignment) { case StringAlignment.Near: dt |= NativeMethods.DT.LEFT; break; case StringAlignment.Center: dt |= NativeMethods.DT.CENTER; break; case StringAlignment.Far: dt |= NativeMethods.DT.RIGHT; break; } } IntPtr hfont = font.ToHfont(); NativeMethods.GdiSelectObject(hdc, hfont); int result = NativeMethods.GdiDrawText(hdc, text, -1, ref r, dt); g.ReleaseHdc(hdc); layoutArea.Width = r.right; layoutArea.Height = r.bottom; return(layoutArea); }
public override int RenderTextEx(IntPtr htheme, IntPtr hdc, int partid, int stateid, string psztext, int cchtext, NativeMethods.DT dwtextflags, IntPtr prect, ref NativeMethods.DTTOPTS poptions) { // do not render, just modify text color var textColor = GetTextColor((States)stateid); poptions.crText = ColorTranslator.ToWin32(textColor); poptions.dwFlags |= NativeMethods.DTT.TextColor; // proceed to default implementation with modified poptions parameter return(Unhandled); }