public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle) { IntPtr primaryHdc = graphics.GetHdc(); // Create a memory DC so we can work offscreen IntPtr memoryHdc = CreateCompatibleDC(primaryHdc); // Create a device-independent bitmap and select it into our DC BITMAPINFO info = new BITMAPINFO(); info.biSize = Marshal.SizeOf(info); info.biWidth = bounds.Width; info.biHeight = -bounds.Height; info.biPlanes = 1; info.biBitCount = 32; info.biCompression = 0; // BI_RGB IntPtr dib = CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0); SelectObject(memoryHdc, dib); // Create and select font IntPtr fontHandle = font.ToHfont(); SelectObject(memoryHdc, fontHandle); // Draw glowing text System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS)); if (textStyle == TextStyle.Glowing) { dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR; } else { dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR; } dttOpts.crText = ColorTranslator.ToWin32(color); dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); // Clean up DeleteObject(fontHandle); DeleteObject(dib); DeleteDC(memoryHdc); graphics.ReleaseHdc(primaryHdc); }
/// <summary> /// Paint the header with a Gradient Background /// </summary> private void OnHeaderPaint(object sender, PaintEventArgs e) { Bitmap buffer = new Bitmap(this.Width, this.Height, e.Graphics); Graphics g = Graphics.FromImage(buffer); //draw the header Rectangle headerR = new Rectangle(0, 0, this.Width, headerHeight); Brush l = new LinearGradientBrush(headerR, IrcColor.colors[_parent.IceChatColors.PanelHeaderBG1], IrcColor.colors[_parent.IceChatColors.PanelHeaderBG2], 300); g.FillRectangle(l, headerR); // http://www.scip.be/index.php?Page=ArticlesNET01&Lang=EN //System.Diagnostics.Debug.WriteLine("p:" + this.Parent.GetType()); //System.Diagnostics.Debug.WriteLine("pp:" + this.Parent.Parent.GetType()); if (this.Parent.Parent.GetType() != typeof(FormFloat)) { if (Application.RenderWithVisualStyles) { if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)) { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal); //which side are we docked on Rectangle rect = Rectangle.Empty; if (((IceDockPanel)this.Parent.Parent.Parent.Parent).Dock == DockStyle.Right) { rect = new Rectangle(0, 0, 22, 22); } else { rect = new Rectangle(this.Width - 22, 0, 22, 22); } renderer.DrawBackground(g, rect); } } } StringFormat sf = new StringFormat { Alignment = StringAlignment.Center }; Font headerFont = new Font("Verdana", 10); Rectangle centered = headerR; centered.Offset(0, (int)(headerR.Height - g.MeasureString(headerCaption, headerFont).Height) / 2); g.DrawString(headerCaption, headerFont, new SolidBrush(IrcColor.colors[_parent.IceChatColors.PanelHeaderForeColor]), centered, sf); e.Graphics.DrawImageUnscaled(buffer, 0, 0); buffer.Dispose(); g.Dispose(); l.Dispose(); headerFont.Dispose(); }
public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle) { IntPtr primaryHdc = graphics.GetHdc(); IntPtr memoryHdc = CreateCompatibleDC(primaryHdc); // Create a device-independent bitmap and select it into our DC BITMAPINFO info = new BITMAPINFO(); info.biSize = Marshal.SizeOf(info); info.biWidth = bounds.Width; info.biHeight = -bounds.Height; info.biPlanes = 1; info.biBitCount = 32; info.biCompression = 0; // BI_RGB IntPtr dib = CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0); SelectObject(memoryHdc, dib); // Create and select font IntPtr fontHandle = font.ToHfont(); SelectObject(memoryHdc, fontHandle); // Draw glowing text System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS)); if (textStyle == TextStyle.Glowing) { dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR; } else { dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR; } dttOpts.crText = ColorTranslator.ToWin32(color); dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses DavuxLib.Win32API.Shared.RECT textBounds = new DavuxLib.Win32API.Shared.RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); // Clean up DeleteObject(fontHandle); DeleteObject(dib); DeleteDC(memoryHdc); graphics.ReleaseHdc(primaryHdc); }
/// <summary> /// Draws composited text onto the glass area of a form. /// </summary> /// <param name="dc">The <see cref="IDeviceContext"/> onto which the composited text should be drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="font">The <see cref="Font"/> to apply to the drawn text.</param> /// <param name="bounds">The <see cref="Rectangle" /> that represents the bounds of the text.</param> /// <param name="padding">The <see cref="Padding"/> around the text; necessary to allow space for the glow effect.</param> /// <param name="foreColor">The <see cref="Color" /> to apply to the drawn text.</param> /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <param name="glowSize">Specifies the size of a glow that will be drawn on the background prior to any text being drawn.</param> /// <remarks> /// <para> /// Do not use this method to draw text on non-glass areas of a form. /// </para> /// </remarks> /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception> /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception> public static void DrawCompositedText(IDeviceContext dc, string text, Font font, Rectangle bounds, Padding padding, Color foreColor, int glowSize, TextFormatFlags textFormat) { if (!IsDwmCompositionEnabled) { throw new NotSupportedException(Properties.Resources.GlassNotSupportedError); } if (dc == null) { throw new ArgumentNullException("dc"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } IntPtr primaryHdc = dc.GetHdc(); try { using (SafeDeviceHandle memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc)) using (SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true)) using (SafeGDIHandle dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc)) { NativeMethods.SelectObject(memoryHdc, fontHandle); // Draw glowing text System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); NativeMethods.DTTOPTS dttOpts = new NativeMethods.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(NativeMethods.DTTOPTS)); dttOpts.dwFlags = NativeMethods.DrawThemeTextFlags.Composited | NativeMethods.DrawThemeTextFlags.GlowSize | NativeMethods.DrawThemeTextFlags.TextColor; dttOpts.crText = ColorTranslator.ToWin32(foreColor); dttOpts.iGlowSize = glowSize; NativeMethods.RECT textBounds = new NativeMethods.RECT(padding.Left, padding.Top, bounds.Width - padding.Right, bounds.Height - padding.Bottom); NativeMethods.DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; NativeMethods.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); } } finally { dc.ReleaseHdc(); } }
void EnsureGlyphRenderers() { if (openRenderer == null || closedRenderer == null) { if (ClassicStyle) { openRenderer = new swf.VisualStyles.VisualStyleRenderer(swf.VisualStyles.VisualStyleElement.TreeView.Glyph.Opened); closedRenderer = new swf.VisualStyles.VisualStyleRenderer(swf.VisualStyles.VisualStyleElement.TreeView.Glyph.Closed); } else { openRenderer = new swf.VisualStyles.VisualStyleRenderer("Explorer::TreeView", 2, 2); closedRenderer = new swf.VisualStyles.VisualStyleRenderer("Explorer::TreeView", 2, 1); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int st = this.Enabled ? (int)status : 4; if (Application.RenderWithVisualStyles) { IntPtr hdc = e.Graphics.GetHdc(); Win32.RECT r = new Win32.RECT { left = 0, top = 0, bottom = 32, right = 32 }; System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.CreateElement("NAVIGATION", 1, 1)); Win32.DrawThemeBackground(renderer.Handle, hdc, 1, st, ref r, IntPtr.Zero); } }
public static void DrawTextOnGlass(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, int rflags) { IntPtr primaryHdc = graphics.GetHdc(); IntPtr memoryHdc = NativeMethods.CreateCompatibleDC(new HandleRef(null, primaryHdc)); NativeMethods.BITMAPINFO info = new NativeMethods.BITMAPINFO(); info.bmiHeader_biSize = Marshal.SizeOf(info); info.bmiHeader_biWidth = bounds.Width; info.bmiHeader_biHeight = -bounds.Height; info.bmiHeader_biPlanes = 1; info.bmiHeader_biBitCount = 32; info.bmiHeader_biCompression = 0; IntPtr ppbBits = IntPtr.Zero; IntPtr dib = NativeMethods.CreateDIBSection(primaryHdc, info, (uint)0, out ppbBits, IntPtr.Zero, (uint)0); NativeMethods.SelectObject(new HandleRef(null, memoryHdc), new HandleRef(null, dib)); IntPtr fontHandle = font.ToHfont(); NativeMethods.SelectObject(new HandleRef(null, memoryHdc), new HandleRef(null, fontHandle)); System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DWMAPI.DTTOPTS dttOpts = new DWMAPI.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(DWMAPI.DTTOPTS)); dttOpts.dwFlags = DWMAPI.DTT_COMPOSITED | rflags | DWMAPI.DTT_TEXTCOLOR; dttOpts.crText = ColorTranslator.ToWin32(color); dttOpts.iGlowSize = 10; NativeMethods.RECT textBounds = new NativeMethods.RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); UXTheme.DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts); const int SRCCOPY = 0x00CC0020; NativeMethods.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); NativeMethods.DeleteObject(new HandleRef(null, fontHandle)); NativeMethods.DeleteObject(new HandleRef(null, dib)); NativeMethods.DeleteDC(new HandleRef(null, memoryHdc)); graphics.ReleaseHdc(primaryHdc); }
/// <summary> /// Provides the size, in pixels, of the specified text. /// </summary> /// <param name="dc">The device context in which to measure the text.</param> /// <param name="text">The text to measure.</param> /// <param name="font">The <see cref="Font"/> to apply to the measured text.</param> /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <returns>The <see cref="Size"/>, in pixels, of <paramref name="text"/> drawn with the specified <paramref name="font"/> and format.</returns> /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception> /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception> public static Size MeasureCompositedText(IDeviceContext dc, string text, Font font, TextFormatFlags textFormat) { if (!IsDwmCompositionEnabled) { throw new NotSupportedException(Properties.Resources.GlassNotSupportedError); } if (dc == null) { throw new ArgumentNullException("dc"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } IntPtr primaryHdc = dc.GetHdc(); try { Rectangle bounds = new Rectangle(0, 0, int.MaxValue, int.MaxValue); using (SafeDeviceHandle memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc)) using (SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true)) using (SafeGDIHandle dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc)) { NativeMethods.SelectObject(memoryHdc, fontHandle); System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); NativeMethods.RECT bounds2 = new NativeMethods.RECT(bounds); NativeMethods.RECT rect; NativeMethods.GetThemeTextExtent(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref bounds2, out rect); return(new Size(rect.Right - rect.Left, rect.Bottom - rect.Top)); } } finally { dc.ReleaseHdc(); } }
public static void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize) { if (IsCompositionEnabled()) { RECT rc = new RECT(); RECT rc2 = new RECT(); rc.left = ctlrct.Left; rc.right = ctlrct.Right; // + 2 * iglowSize; //make it larger to contain the glow effect rc.top = ctlrct.Top; rc.bottom = ctlrct.Bottom; // + 2 * iglowSize; //Just the same rect with rc,but (0,0) at the lefttop rc2.left = 0; rc2.top = 0; rc2.right = rc.right - rc.left; rc2.bottom = rc.bottom - rc.top; IntPtr destdc = WinAPI.GetDC(hwnd); //hwnd must be the handle of form,not control IntPtr Memdc = WinAPI.CreateCompatibleDC(destdc); // Set up a memory DC where we'll draw the text. IntPtr bitmap; IntPtr bitmapOld = IntPtr.Zero; IntPtr logfnotOld; int uFormat = Constants.DT_SINGLELINE | Constants.DT_CENTER | Constants.DT_VCENTER | Constants.DT_NOPREFIX; //text format IntPtr ptPixels = IntPtr.Zero; BITMAPINFO dib = new BITMAPINFO(); dib.bmiHeader.biHeight = -(rc.bottom - rc.top); // negative because DrawThemeTextEx() uses a top-down DIB dib.bmiHeader.biWidth = rc.right - rc.left; dib.bmiHeader.biPlanes = 1; dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); dib.bmiHeader.biBitCount = 32; dib.bmiHeader.biCompression = Constants.BI_RGB; dib.bmiColors.rgbBlue = 255; if (!(WinAPI.SaveDC(Memdc) == 0)) { bitmap = WinAPI.CreateDIBSection(Memdc, ref dib, Constants.DIB_RGB_COLORS, out ptPixels, IntPtr.Zero, 0); // Create a 32-bit bmp for use in offscreen drawing when glass is on if (!(bitmap == IntPtr.Zero)) { bitmapOld = WinAPI.SelectObject(Memdc, bitmap); IntPtr hFont = font.ToHfont(); logfnotOld = WinAPI.SelectObject(Memdc, hFont); try { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS)); dttOpts.dwFlags = Constants.DTT_COMPOSITED | Constants.DTT_GLOWSIZE; dttOpts.iGlowSize = iglowSize; for (int i = (-(dib.bmiHeader.biWidth * dib.bmiHeader.biHeight) - 1); i >= 0; i--) { Marshal.WriteInt32( (IntPtr)((long)ptPixels + Marshal.SizeOf(typeof(int)) * i), GetAeroBackgroundColor().ToArgb() ); } WinAPI.DrawThemeTextEx(renderer.Handle, Memdc, 1, 1, text, -1, uFormat, ref rc2, ref dttOpts); WinAPI.BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, Constants.SRCCOPY); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } //Remember to clean up WinAPI.SelectObject(Memdc, bitmapOld); WinAPI.SelectObject(Memdc, logfnotOld); WinAPI.DeleteObject(bitmap); WinAPI.DeleteObject(hFont); WinAPI.ReleaseDC(Memdc, -1); WinAPI.DeleteDC(Memdc); } } } }
/// <summary> /// Paints ribbon tab group. /// </summary> /// <param name="e">Context information</param> public override void PaintTabGroup(RibbonTabGroupRendererEventArgs e) { Graphics g = e.Graphics; Office2007RibbonTabGroupColorTable colorTable = GetColors(e.RibbonTabItemGroup); if (colorTable == null) return; #if FRAMEWORK20 if (e.ItemPaintArgs.GlassEnabled) { if (e.ItemPaintArgs.CachedPaint) return; PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, true); Rectangle rect = e.Bounds; rect.Height -= 2; IntPtr hdc = g.GetHdc(); Font font = e.GroupFont; string text = e.RibbonTabItemGroup.GroupTitle; ThemeTextFormat tf = GetThemeFormat(); try { IntPtr memdc = WinApi.CreateCompatibleDC(hdc); try { WinApi.BITMAPINFO bmpInfo = new WinApi.BITMAPINFO(); bmpInfo.biWidth = rect.Width; bmpInfo.biHeight = -rect.Height; bmpInfo.biPlanes = 1; bmpInfo.biBitCount = 32; bmpInfo.biSize = Marshal.SizeOf(bmpInfo); IntPtr dib = WinApi.CreateDIBSection(hdc, bmpInfo, 0, 0, IntPtr.Zero, 0); WinApi.SelectObject(memdc, dib); IntPtr fontHandle = font.ToHfont(); WinApi.SelectObject(memdc, fontHandle); Themes.RECT bounds = GetThemeTextBounds(rect); System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); Themes.DTTOPTS dttOpts = new Themes.DTTOPTS(); dttOpts.iGlowSize = 10; dttOpts.crText = new Themes.COLORREF(colorTable.Text); dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR; if (colorTable.Background == null || colorTable.Background.IsEmpty || colorTable.Background.Start.A < 255) dttOpts.dwFlags |= (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE; dttOpts.dwSize = Marshal.SizeOf(dttOpts); // Draw Background using (Graphics gb = Graphics.FromHdc(memdc)) { PaintTabGroupBackground(gb, colorTable, new Rectangle(0, 0, rect.Width, rect.Height + 2), new Rectangle(0, 0, rect.Width, rect.Height + 2), true); } Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts); const int SRCCOPY = 0x00CC0020; WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY); WinApi.DeleteObject(fontHandle); WinApi.DeleteObject(dib); } finally { WinApi.DeleteDC(memdc); } } finally { g.ReleaseHdc(hdc); } return; } #endif PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, false); ElementStyle style = e.RibbonTabItemGroup.Style; //.Copy(); Color styleTextColor = style.TextColor; Color styleTextShadowColor = style.TextShadowColor; Point styleTextShadowOffset = style.TextShadowOffset; style.FreezeEvents = true; style.TextColor = colorTable.Text; style.TextShadowColor = Color.Empty; style.TextShadowOffset = Point.Empty; ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, e.Graphics, GetTextBounds(e)); ElementStyleDisplay.PaintText(info, e.RibbonTabItemGroup.GroupTitle, e.GroupFont, false, e.RibbonTabItemGroup.Style.TextFormat | GetTextFormat()); style.TextColor = styleTextColor; style.TextShadowColor = styleTextShadowColor; style.TextShadowOffset = styleTextShadowOffset; style.FreezeEvents = false; }
private void DrawTextOnGlassInternal(IntPtr destdc, String text, Font font, Rectangle ctlrct, ContentAlignment textAlign, int iglowSize) { if (Glass.IsDesktopCompositionEnabled()) { RECT rc = new RECT(); RECT rc2 = new RECT(); var iglowExpand = (int)(iglowSize * 0.5); //iglowExpand = 0; //make it larger to contain the glow effect rc.left = ctlrct.Left - iglowExpand; rc.right = ctlrct.Right;// + iglowExpand; rc.top = ctlrct.Top - iglowExpand; rc.bottom = ctlrct.Bottom + iglowExpand; //Just the same rect with rc,but (0,0) at the lefttop rc2.left = iglowExpand; rc2.top = iglowExpand; rc2.right = rc.right - rc.left;// - iglowExpand; rc2.bottom = rc.bottom - rc.top - iglowExpand; IntPtr Memdc = CreateCompatibleDC(destdc); // Set up a memory DC where we'll draw the text. IntPtr bitmap; IntPtr bitmapOld = IntPtr.Zero; IntPtr logfnotOld; //int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX; //text format TextFormatFlags uFormat = TextFormatFlags.NoPrefix; //text format //if ((textAlign == ContentAlignment.TopCenter) || // (textAlign == ContentAlignment.MiddleCenter) || // (textAlign == ContentAlignment.BottomCenter)) // uFormat |= TextFormatFlags.HorizontalCenter; //if ((textAlign == ContentAlignment.TopRight) || // (textAlign == ContentAlignment.MiddleRight) || // (textAlign == ContentAlignment.BottomRight)) // uFormat |= TextFormatFlags.Right; //if ((textAlign == ContentAlignment.MiddleLeft) || // (textAlign == ContentAlignment.MiddleCenter) || // (textAlign == ContentAlignment.MiddleRight)) // uFormat |= TextFormatFlags.VerticalCenter; //if ((textAlign == ContentAlignment.BottomLeft) || // (textAlign == ContentAlignment.BottomCenter) || // (textAlign == ContentAlignment.BottomRight)) // uFormat |= TextFormatFlags.Bottom; BITMAPINFO dib = new BITMAPINFO(); dib.bmiHeader.biHeight = -(rc.bottom - rc.top); // negative because DrawThemeTextEx() uses a top-down DIB dib.bmiHeader.biWidth = rc.right - rc.left; dib.bmiHeader.biPlanes = 1; dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); dib.bmiHeader.biBitCount = 32; dib.bmiHeader.biCompression = BI_RGB; if (!(SaveDC(Memdc) == 0)) { bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0); // Create a 32-bit bmp for use in offscreen drawing when glass is on if (!(bitmap == IntPtr.Zero)) { bitmapOld = SelectObject(Memdc, bitmap); IntPtr hFont = font.ToHfont(); logfnotOld = SelectObject(Memdc, hFont); try { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS)); dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE; dttOpts.iGlowSize = iglowSize; DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, (int)uFormat, ref rc2, ref dttOpts); BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY); } catch (Exception e) { Trace.WriteLine(e.Message); } //using (var image = GetImageFromHBitmap(bitmap)) //{ // image.Save(@"d:\temp\sqlupdate.png", System.Drawing.Imaging.ImageFormat.Png); //} //Remember to clean up SelectObject(Memdc, bitmapOld); SelectObject(Memdc, logfnotOld); DeleteObject(bitmap); DeleteObject(hFont); ReleaseDC(Memdc, -1); DeleteDC(Memdc); } } } }
private void OnPaint(object sender, PaintEventArgs e) { try { //make the buffer we draw this all to Bitmap buffer = new Bitmap(this.Width, this.Height, e.Graphics); Graphics g = Graphics.FromImage(buffer); //draw the header g.Clear(IrcColor.colors[FormMain.Instance.IceChatColors.NickListBackColor]); g.InterpolationMode = InterpolationMode.Low; g.SmoothingMode = SmoothingMode.HighSpeed; g.PixelOffsetMode = PixelOffsetMode.None; g.CompositingQuality = CompositingQuality.HighSpeed; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; Font headerFont = new Font("Verdana", 10); Rectangle headerR = new Rectangle(0, 0, this.Width, headerHeight); //get the header colors here Brush l = new LinearGradientBrush(headerR, IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderBG1], IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderBG2], 300); g.FillRectangle(l, headerR); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; Rectangle centered = headerR; centered.Offset(0, (int)(headerR.Height - e.Graphics.MeasureString(headerCaption, headerFont).Height) / 2); g.DrawString(headerCaption, headerFont, new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderForeColor]), centered, sf); if (this.Parent.Parent.GetType() != typeof(FormFloat)) { if (Application.RenderWithVisualStyles) { if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)) { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal); //which side are we docked on Rectangle rect = Rectangle.Empty; if (((IceDockPanel)this.Parent.Parent.Parent.Parent).Dock == DockStyle.Right) rect = new Rectangle(0, 0, 22, 22); else rect = new Rectangle(this.Width - 22, 0, 22, 22); renderer.DrawBackground(g, rect); } } } //draw the nicks Rectangle listR; if (this.panelButtons.Visible) listR = new Rectangle(0, headerHeight, this.Width, this.Height - headerHeight - panelButtons.Height); else listR = new Rectangle(0, headerHeight, this.Width, this.Height - headerHeight); if (currentWindow != null && currentWindow.WindowStyle == IceTabPage.WindowType.Channel) { PopulateNicks(); int currentY = listR.Y; int _lineSize = Convert.ToInt32(this.Font.GetHeight(g)); int randColor = -1; for (int i = topIndex; i < sortedNickNames.Count; i++) { Brush b = null; User u = currentWindow.GetNick(sortedNickNames[i].nick); if (FormMain.Instance.IceChatColors.RandomizeNickColors) { randColor++; if (randColor > (IrcColor.colors.Length-1)) randColor = 0; //make sure its not the same color as the background if (randColor == FormMain.Instance.IceChatColors.NickListBackColor) { randColor++; if (randColor > (IrcColor.colors.Length-1)) randColor = 0; } b = new SolidBrush(IrcColor.colors[randColor]); u.nickColor = randColor; } else { //get the correct nickname color for channel status for (int y = 0; y < u.Level.Length; y++) { if (u.Level[y]) { switch (currentWindow.Connection.ServerSetting.StatusModes[0][y]) { case 'q': b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelOwnerColor]); break; case 'a': b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelAdminColor]); break; case 'o': b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelOpColor]); break; case 'h': b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelHalfOpColor]); break; case 'v': b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelVoiceColor]); break; default: b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelRegularColor]); break; } break; } } if (b == null) b = new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.ChannelRegularColor]); } //check if selected, if so, draw the selector bar if (sortedNickNames[i].selected) { g.FillRectangle(new SolidBrush(SystemColors.Highlight), 0, currentY, this.Width, _lineSize); b = null; b = new SolidBrush(SystemColors.HighlightText); } //draw the nickname g.DrawString(sortedNickNames[i].nick, this.Font, b, 2, currentY); //draw the host if (FormMain.Instance.IceChatOptions.ShowNickHost) { if (currentWindow.Connection.ServerSetting.IAL.ContainsKey(u.NickName)) { string host = sortedNickNames[i].host; if (sortedNickNames[i].host.Length > 0) g.DrawString(sortedNickNames[i].host, this.Font, b, (this.Font.SizeInPoints * 14), currentY); } } currentY += _lineSize; if (currentY >= (listR.Height + listR.Y)) { vScrollBar.Maximum = sortedNickNames.Count - 2; vScrollBar.LargeChange = ((listR.Height - _lineSize) / _lineSize); break; } } if (currentY >= listR.Height || vScrollBar.Value > 0) vScrollBar.Visible = true; else { vScrollBar.Visible = false; } } l.Dispose(); sf.Dispose(); //paint the buffer onto the usercontrol e.Graphics.DrawImageUnscaled(buffer, 0, 0); buffer.Dispose(); g.Dispose(); headerFont.Dispose(); } catch (Exception ee) { FormMain.Instance.WriteErrorFile(currentWindow.Connection, "NickList OnPaint:" + currentWindow.Nicks.Values.Count, ee); } }
/// <summary> /// Draws composited text onto the glass area of a form. /// </summary> /// <param name="dc">The <see cref="IDeviceContext"/> onto which the composited text should be drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="font">The <see cref="Font"/> to apply to the drawn text.</param> /// <param name="bounds">The <see cref="Rectangle" /> that represents the bounds of the text.</param> /// <param name="padding">The <see cref="Padding"/> around the text; necessary to allow space for the glow effect.</param> /// <param name="foreColor">The <see cref="Color" /> to apply to the drawn text.</param> /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <param name="glowSize">Specifies the size of a glow that will be drawn on the background prior to any text being drawn.</param> /// <remarks> /// <para> /// Do not use this method to draw text on non-glass areas of a form. /// </para> /// </remarks> /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception> /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception> public static void DrawCompositedText(IDeviceContext dc, string text, Font font, Rectangle bounds, Padding padding, Color foreColor, int glowSize, TextFormatFlags textFormat) { if( !IsDwmCompositionEnabled ) throw new NotSupportedException(Properties.Resources.GlassNotSupportedError); if( dc == null ) throw new ArgumentNullException("dc"); if( text == null ) throw new ArgumentNullException("text"); if( font == null ) throw new ArgumentNullException("font"); IntPtr primaryHdc = dc.GetHdc(); try { using( SafeDeviceHandle memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc) ) using( SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true) ) using( SafeGDIHandle dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc) ) { NativeMethods.SelectObject(memoryHdc, fontHandle); // Draw glowing text System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); NativeMethods.DTTOPTS dttOpts = new NativeMethods.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(NativeMethods.DTTOPTS)); dttOpts.dwFlags = NativeMethods.DrawThemeTextFlags.Composited | NativeMethods.DrawThemeTextFlags.GlowSize | NativeMethods.DrawThemeTextFlags.TextColor; dttOpts.crText = ColorTranslator.ToWin32(foreColor); dttOpts.iGlowSize = glowSize; NativeMethods.RECT textBounds = new NativeMethods.RECT(padding.Left, padding.Top, bounds.Width - padding.Right, bounds.Height - padding.Bottom); NativeMethods.DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; NativeMethods.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); } } finally { dc.ReleaseHdc(); } }
//Draw text on the glass surface public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize) { if (isGlassSupported()) { RECT rc = new RECT(); RECT rc2 = new RECT(); rc.left = ctlrct.Left; rc.right = ctlrct.Right; rc.top = ctlrct.Top; rc.bottom = ctlrct.Bottom; rc2.left = 6; rc2.top = 5; rc2.right = rc.right - rc.left; rc2.bottom = rc.bottom - rc.top; IntPtr destdc = GetDC(hwnd); IntPtr Memdc = CreateCompatibleDC(destdc); IntPtr bitmap; IntPtr bitmapOld = IntPtr.Zero; IntPtr logfnotOld; int uFormat = DT_SINGLELINE | DT_NOPREFIX; BITMAPINFO dib = new BITMAPINFO(); dib.bmiHeader.biHeight = -(rc.bottom - rc.top); dib.bmiHeader.biWidth = rc.right - rc.left; dib.bmiHeader.biPlanes = 1; dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); dib.bmiHeader.biBitCount = 32; dib.bmiHeader.biCompression = BI_RGB; if (!(SaveDC(Memdc) == 0)) { bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0); if (!(bitmap == IntPtr.Zero)) { bitmapOld = SelectObject(Memdc, bitmap); IntPtr hFont = font.ToHfont(); logfnotOld = SelectObject(Memdc, hFont); try { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS)); dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE; dttOpts.iGlowSize = iglowSize; DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts); BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY); } catch (Exception e) { Console.WriteLine(e.Message); } SelectObject(Memdc, bitmapOld); SelectObject(Memdc, logfnotOld); DeleteObject(bitmap); DeleteObject(hFont); ReleaseDC(Memdc, -1); DeleteDC(Memdc); } } } }
public static void PaintTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, bool copySourceBackground, bool renderGlow, int glowSize) { IntPtr hdc = g.GetHdc(); const int SRCCOPY = 0x00CC0020; try { IntPtr memdc = WinApi.CreateCompatibleDC(hdc); try { WinApi.BITMAPINFO info = new WinApi.BITMAPINFO(); info.biWidth = rect.Width; info.biHeight = -rect.Height; info.biPlanes = 1; info.biBitCount = 32; info.biSize = Marshal.SizeOf(info); IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0); WinApi.SelectObject(memdc, dib); IntPtr fontHandle = font.ToHfont(); WinApi.SelectObject(memdc, fontHandle); Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height)); System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); Themes.DTTOPTS dttOpts = new Themes.DTTOPTS(); dttOpts.iGlowSize = glowSize; dttOpts.crText = new Themes.COLORREF(textColor); dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (renderGlow ? (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE : 0) | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR; dttOpts.dwSize = Marshal.SizeOf(dttOpts); if (copySourceBackground) WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left, rect.Top, SRCCOPY); Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts); WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY); WinApi.DeleteObject(fontHandle); WinApi.DeleteObject(dib); } finally { WinApi.DeleteDC(memdc); } } finally { g.ReleaseHdc(hdc); } }
/// <summary> /// Provides the size, in pixels, of the specified text. /// </summary> /// <param name="dc">The device context in which to measure the text.</param> /// <param name="text">The text to measure.</param> /// <param name="font">The <see cref="Font"/> to apply to the measured text.</param> /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <returns>The <see cref="Size"/>, in pixels, of <paramref name="text"/> drawn with the specified <paramref name="font"/> and format.</returns> /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception> /// <exception cref="ArgumentNullException"><paramref name="dc"/>, <paramref name="text"/> or <paramref name="font"/> is <see langword="null"/>.</exception> public static Size MeasureCompositedText(IDeviceContext dc, string text, Font font, TextFormatFlags textFormat) { if( !IsDwmCompositionEnabled ) throw new NotSupportedException(Properties.Resources.GlassNotSupportedError); if( dc == null ) throw new ArgumentNullException("dc"); if( text == null ) throw new ArgumentNullException("text"); if( font == null ) throw new ArgumentNullException("font"); IntPtr primaryHdc = dc.GetHdc(); try { Rectangle bounds = new Rectangle(0, 0, int.MaxValue, int.MaxValue); using( SafeDeviceHandle memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc) ) using( SafeGDIHandle fontHandle = new SafeGDIHandle(font.ToHfont(), true) ) using( SafeGDIHandle dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc) ) { NativeMethods.SelectObject(memoryHdc, fontHandle); System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); NativeMethods.RECT bounds2 = new NativeMethods.RECT(bounds); NativeMethods.RECT rect; NativeMethods.GetThemeTextExtent(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref bounds2, out rect); return new Size(rect.Right - rect.Left, rect.Bottom - rect.Top); } } finally { dc.ReleaseHdc(); } }
public static void PaintShadowTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, Color shadowColor, bool copySourceBackground) { Point transformPoint = new Point(); using (Matrix trans = g.Transform) { Point[] pts = new Point[1]; pts[0] = transformPoint; trans.TransformPoints(pts); transformPoint = pts[0]; } IntPtr hdc = g.GetHdc(); const int SRCCOPY = 0x00CC0020; try { IntPtr memdc = WinApi.CreateCompatibleDC(hdc); try { WinApi.BITMAPINFO info = new WinApi.BITMAPINFO(); info.biWidth = rect.Width; info.biHeight = -rect.Height; info.biPlanes = 1; info.biBitCount = 32; info.biSize = Marshal.SizeOf(info); IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0); WinApi.SelectObject(memdc, dib); IntPtr fontHandle = font.ToHfont(); WinApi.SelectObject(memdc, fontHandle); Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height)); System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); Themes.DTTOPTS dttOpts = new Themes.DTTOPTS(); dttOpts.crText = new Themes.COLORREF(shadowColor); dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR; dttOpts.dwSize = Marshal.SizeOf(dttOpts); if (copySourceBackground) WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, SRCCOPY); // Shadow bounds.Offset(1, 2); Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts); bounds.Offset(-1, -1); dttOpts.crText = new Themes.COLORREF(textColor); Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts); //Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts); WinApi.BitBlt(hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY); WinApi.DeleteObject(fontHandle); WinApi.DeleteObject(dib); } finally { WinApi.DeleteDC(memdc); } } finally { g.ReleaseHdc(hdc); } }
protected override void OnDrawNode(DrawTreeNodeEventArgs e) { Brush back = new SolidBrush(backColor); Brush fore; e.Graphics.FillRectangle(back, e.Bounds); if (this.SelectedNode == e.Node) { if (backBrush == null || backBrush.Rectangle.Height != e.Bounds.Height) { backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(Point.Empty, new Point(0, e.Bounds.Height), this.selectedColor1, this.selectedColor2); } backBrush.ResetTransform(); backBrush.MultiplyTransform(new System.Drawing.Drawing2D.Matrix(0, 1, 1, 0, e.Bounds.Location.X, e.Bounds.Location.Y - e.Bounds.Height / 2)); e.Graphics.FillRectangle(backBrush, e.Bounds); fore = new SolidBrush(selectedForeColor); } else { fore = new SolidBrush(foreColor); } if ((int)(e.State & TreeNodeStates.Focused) != 0) { Rectangle bound2 = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1); e.Graphics.DrawRectangle(new Pen(this.selectedColor1), bound2); } Rectangle textBound = e.Bounds; int indent = this.Indent * e.Node.Level; if (this.ShowRootLines) { indent += this.Indent; } textBound.X += indent; textBound.Width -= indent; if (this.ShowPlusMinus && e.Node.Nodes.Count > 0) { Rectangle glyphBounds = new Rectangle(textBound.X - this.Indent, textBound.Y, this.Indent, textBound.Height); if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsSupported) { if (this.renderOpened == null) { this.renderOpened = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView.Glyph.Opened); } if (this.renderClosed == null) { this.renderClosed = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView.Glyph.Closed); } (e.Node.IsExpanded ? this.renderOpened : this.renderClosed).DrawBackground(e.Graphics, glyphBounds); } else { DrawText(-1, e.Node.IsExpanded ? "-" : "+", this.Font, fore, glyphBounds, this.stringFormat2, e.Graphics, this.SelectedNode == e.Node); } } if (this.ImageList != null) { e.Graphics.DrawImage(GetImage(e.Node), textBound.X + 2, textBound.Y + (textBound.Height - this.ImageList.ImageSize.Height) / 2); textBound.X += this.ImageList.ImageSize.Width + 2; textBound.Width -= this.ImageList.ImageSize.Width + 2; } DrawText(e.Node.Index, e.Node.Text, this.Font, fore, textBound, this.stringFormat, e.Graphics, this.SelectedNode == e.Node); }
public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize) { if (IsCompositionEnabled()) { RECT rc = new RECT(); RECT rc2 = new RECT(); rc.left = ctlrct.Left; rc.right = ctlrct.Right + 2 * iglowSize; //make it larger to contain the glow effect rc.top = ctlrct.Top; rc.bottom = ctlrct.Bottom + 2 * iglowSize; //Just the same rect with rc,but (0,0) at the lefttop rc2.left = 0; rc2.top = 0; rc2.right = rc.right - rc.left; rc2.bottom = rc.bottom - rc.top; IntPtr destdc = GetDC(hwnd); //hwnd must be the handle of form,not control IntPtr Memdc = CreateCompatibleDC(destdc); // Set up a memory DC where we'll draw the text. IntPtr bitmap; IntPtr bitmapOld = IntPtr.Zero; IntPtr logfnotOld; int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX; //text format BITMAPINFO dib = new BITMAPINFO(); dib.bmiHeader.biHeight = -(rc.bottom - rc.top); // negative because DrawThemeTextEx() uses a top-down DIB dib.bmiHeader.biWidth = rc.right - rc.left; dib.bmiHeader.biPlanes = 1; dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); dib.bmiHeader.biBitCount = 32; dib.bmiHeader.biCompression = BI_RGB; if (!(SaveDC(Memdc) == 0)) { bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0); // Create a 32-bit bmp for use in offscreen drawing when glass is on if (!(bitmap == IntPtr.Zero)) { bitmapOld = SelectObject(Memdc, bitmap); IntPtr hFont = font.ToHfont(); logfnotOld = SelectObject(Memdc, hFont); try { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active); DTTOPTS dttOpts = new DTTOPTS(); dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS)); dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE; dttOpts.iGlowSize = iglowSize; DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts); BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY); } catch (Exception e) { Trace.WriteLine(e.Message); } //Remember to clean up SelectObject(Memdc, bitmapOld); SelectObject(Memdc, logfnotOld); DeleteObject(bitmap); DeleteObject(hFont); ReleaseDC(Memdc, -1); DeleteDC(Memdc); } } } }
/// <summary> /// Paint the header with a Gradient Background /// </summary> private void OnHeaderPaint(object sender, PaintEventArgs e) { Bitmap buffer = new Bitmap(this.Width, this.Height, e.Graphics); Graphics g = Graphics.FromImage(buffer); //draw the header Rectangle headerR = new Rectangle(0, 0, this.Width, headerHeight); Brush l = new LinearGradientBrush(headerR, IrcColor.colors[_parent.IceChatColors.PanelHeaderBG1], IrcColor.colors[_parent.IceChatColors.PanelHeaderBG2], 300); g.FillRectangle(l, headerR); if (this.Parent.Parent.GetType() != typeof(FormFloat)) { if (Application.RenderWithVisualStyles) { if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)) { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal); //which side are we docked on Rectangle rect = Rectangle.Empty; if (((IceDockPanel)this.Parent.Parent.Parent.Parent).Dock == DockStyle.Right) rect = new Rectangle(0, 0, 22, 22); else rect = new Rectangle(this.Width - 22, 0, 22, 22); renderer.DrawBackground(g, rect); } } } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; Font headerFont = new Font("Verdana", 10); Rectangle centered = headerR; centered.Offset(0, (int)(headerR.Height - g.MeasureString(headerCaption, headerFont).Height) / 2); g.DrawString(headerCaption, headerFont, new SolidBrush(IrcColor.colors[_parent.IceChatColors.PanelHeaderForeColor]), centered, sf); e.Graphics.DrawImageUnscaled(buffer, 0, 0); buffer.Dispose(); g.Dispose(); l.Dispose(); headerFont.Dispose(); }
internal void DrawControl(Graphics g) { try { //draw the background g.Clear(IrcColor.colors[_parent.IceChatColors.TabbarBackColor]); if (this._TabPages.Count == 0) return; if (this._TabPages.Count != 0 && _selectedIndex == -1) SelectedIndex = 0; if (this._selectedIndex > (_TabPages.Count - 1)) SelectedIndex = 0; CalculateTabSizes(g); if (singleRow && !showScrollItems && _tabStartXtra != 0) { //recalculate, we do not need extra space , no buttons _tabStartXtra = 0; CalculateTabSizes(g); } //check that right most tab, is right most if (showScrollItems && singleRow) { //sometimes a blank space is there Rectangle rectTab = _tabSizeRects[_tabSizeRects.Count-1]; if ((rectTab.X + rectTab.Width) < (this.Width - 44)) { //845:1056 //int d = _tabStartXtra = _tabStartXtra + rectTab.Width; CalculateTabSizes(g); } } bool flashTabs = false; //check if we have any flashing tabs for (int i = 0; i < _TabPages.Count; i++) { if (_TabPages[i].FlashTab == true) { flashTabs = true; break; } } if (flashTabs == true) { //enable the flash tab timer flashTabTimer.Enabled = true; flashTabTimer.Start(); } else { //disable the flash tab timer flashTabTimer.Stop(); flashTabTimer.Enabled = false; } if (singleRow && showScrollItems) { //draw the button for left - right if need be if (Application.RenderWithVisualStyles) { //draw the background for the buttons area System.Windows.Forms.VisualStyles.VisualStyleRenderer leftButton; System.Windows.Forms.VisualStyles.VisualStyleRenderer rightButton; if (leftButtonHover) leftButton = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ScrollBar.ArrowButton.LeftHot); else leftButton = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ScrollBar.ArrowButton.LeftNormal); Rectangle leftRect = new Rectangle(this.Width - 44, 0, 22, 22); leftButton.DrawBackground(g, leftRect); if (rightButtonHover) rightButton = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ScrollBar.ArrowButton.RightHot); else rightButton = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ScrollBar.ArrowButton.RightNormal); Rectangle rightRect = new Rectangle(this.Width - 22, 0, 22, 22); rightButton.DrawBackground(g, rightRect); } //limit drawing area g.Clip = new Region(new Rectangle(0, 0, this.Width - 44, this.Height)); } for (int i = 0; i < _TabPages.Count; i++) DrawTab(g, _TabPages[i], i); } catch (Exception) { //System.Diagnostics.Debug.WriteLine("IceChatControl DrawControl Error:" + e.Message); //_parent.WriteErrorFile(_parent.InputPanel.CurrentConnection, "IceTabControl DrawControl", e); } }
private void OnPaint(object sender, PaintEventArgs e) { try { //make the buffer we draw this all to Bitmap buffer = new Bitmap(this.Width, this.Height, e.Graphics); Graphics g = Graphics.FromImage(buffer); //draw the header g.Clear(IrcColor.colors[FormMain.Instance.IceChatColors.ServerListBackColor]); g.InterpolationMode = InterpolationMode.Low; g.SmoothingMode = SmoothingMode.HighSpeed; g.PixelOffsetMode = PixelOffsetMode.None; g.CompositingQuality = CompositingQuality.HighSpeed; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; Font headerFont = new Font("Verdana", 10); Rectangle headerR = new Rectangle(0, 0, this.Width, headerHeight); Brush l = new LinearGradientBrush(headerR, IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderBG1], IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderBG2], 300); g.FillRectangle(l, headerR); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; Rectangle centered = headerR; centered.Offset(0, (int)(headerR.Height - e.Graphics.MeasureString(headerCaption, headerFont).Height) / 2); g.DrawString(headerCaption, headerFont, new SolidBrush(IrcColor.colors[FormMain.Instance.IceChatColors.PanelHeaderForeColor]), centered, sf); if (this.Parent.Parent.GetType() != typeof(FormFloat)) { if (Application.RenderWithVisualStyles) { if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal)) { System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal); //which side are we docked on Rectangle rect = Rectangle.Empty; if (((IceDockPanel)this.Parent.Parent.Parent.Parent).Dock == DockStyle.Right) rect = new Rectangle(0, 0, 22, 22); else rect = new Rectangle(this.Width - 22, 0, 22, 22); renderer.DrawBackground(g, rect); } } } //draw each individual server Rectangle listR; if (this.panelButtons.Visible == true) listR = new Rectangle(0, headerHeight, this.Width, this.Height - headerHeight - panelButtons.Height); else listR = new Rectangle(0, headerHeight, this.Width, this.Height - headerHeight); int currentY = listR.Y; int _lineSize = Convert.ToInt32(this.Font.GetHeight(g)); BuildServerNodes(); int nodeCount = 0; bool flashTabs = false; //check if we have any flashing tabs for (int i = 0; i < FormMain.Instance.TabMain.TabPages.Count ; i++) { if (FormMain.Instance.TabMain.TabPages[i].FlashTab == true) { flashTabs = true; break; } } if (flashTabs == true) { //enable the flash tab timer flashTabTimer.Enabled = true; flashTabTimer.Start(); } else { //disable the flash tab timer flashTabTimer.Stop(); flashTabTimer.Enabled = false; } foreach (KeyValuePair<string, object> de in serverNodes) { //get the object type for this node string node = (string)de.Key; string[] nodes = node.Split(':'); object value = de.Value; int x = 16; Brush b; Pen p = new Pen(IrcColor.colors[FormMain.Instance.IceChatColors.TabBarCurrent]); nodeCount++; if (nodeCount <= topIndex) continue; if (nodeCount == selectedNodeIndex) { g.FillRectangle(new SolidBrush(SystemColors.Highlight), 0, currentY, this.Width, _lineSize); b = new SolidBrush(SystemColors.HighlightText); } else { b = new SolidBrush(IrcColor.colors[Convert.ToInt32(nodes[2])]); } if (value.GetType() == typeof(ServerSetting)) { if (nodeCount == selectedNodeIndex) { selectedServerID = ((ServerSetting)value).ID; } //TreeCollapse -- 0 - no items :: 1- show + sign (not collapsed) :: 2- show - sign (collapsed) if (((ServerSetting)value).TreeCollapse > 0) g.DrawRectangle(p, x - 12, currentY + 2, 8, 8); //now draw the + or - if it is collapsed or not if (((ServerSetting)value).TreeCollapse == 1) { //the plus sign g.DrawLine(p, x - 12, currentY + 6, x - 4, currentY + 6); g.DrawLine(p, x - 8, currentY + 2, x - 8, currentY + 10); } else if (((ServerSetting)value).TreeCollapse == 2) { //the minus sign g.DrawLine(p, x - 12, currentY + 6, x - 4, currentY + 6); } x = 16; } if (value.GetType() == typeof(IceTabPage)) { x = 32; if (((IceTabPage)value).WindowStyle == IceTabPage.WindowType.Channel || ((IceTabPage)value).WindowStyle == IceTabPage.WindowType.Query || ((IceTabPage)value).WindowStyle == IceTabPage.WindowType.DCCChat) { if (nodeCount == selectedNodeIndex) { selectedServerID = ((IceTabPage)value).Connection.ServerSetting.ID; ((IceTabPage)value).FlashTab = false; } } else if (((IceTabPage)value).WindowStyle == IceTabPage.WindowType.Window) { if (((IceTabPage)value).Connection == null) x = 16; } } switch (nodes[1]) { case "0": //disconnected g.DrawImage(StaticMethods.LoadResourceImage("disconnect-icon.png"), x, currentY, 16, 16); break; case "1": //connected g.DrawImage(StaticMethods.LoadResourceImage("connect-icon.png"), x, currentY, 16, 16); break; case "2": //connecting g.DrawImage(StaticMethods.LoadResourceImage("refresh-icon.png"), x, currentY, 16, 16); break; case "3": //channel //check if we are flashing or not if (((IceTabPage)value).FlashTab == true) { if (((IceTabPage)value).FlashValue == 1) g.DrawImage(StaticMethods.LoadResourceImage("channel.png"), x, currentY, 16, 16); } else g.DrawImage(StaticMethods.LoadResourceImage("channel.png"), x, currentY, 16, 16); break; case "4": //query case "5": //dcc chat if (((IceTabPage)value).FlashTab == true) { if (((IceTabPage)value).FlashValue == 1) g.DrawImage(StaticMethods.LoadResourceImage("new-query.ico"), x, currentY, 16, 16); } else g.DrawImage(StaticMethods.LoadResourceImage("new-query.ico"), x, currentY, 16, 16); break; case "6": //channel list g.DrawImage(StaticMethods.LoadResourceImage("channellist.png"), x, currentY, 16, 16); break; case "7": g.DrawImage(StaticMethods.LoadResourceImage("window-icon.ico"), x, currentY, 16, 16); break; } g.DrawString(nodes[4], this.Font, b, x + 16, currentY); b.Dispose(); if (currentY >= (listR.Height + listR.Y)) { vScrollBar.Maximum = serverNodes.Count - 2; vScrollBar.LargeChange = ((listR.Height - _lineSize) / _lineSize); break; } currentY += _lineSize; } if (currentY > listR.Height || vScrollBar.Value > 0) vScrollBar.Visible = true; else vScrollBar.Visible = false; l.Dispose(); sf.Dispose(); //paint the buffer onto the usercontrol e.Graphics.DrawImageUnscaled(buffer, 0, 0); buffer.Dispose(); headerFont.Dispose(); g.Dispose(); } catch (Exception ee) { FormMain.Instance.WriteErrorFile(FormMain.Instance.InputPanel.CurrentConnection,"ServerTree OnPaint", ee); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Application.RenderWithVisualStyles) { if (cachedRenderer==null) { cachedRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer ( System.Windows.Forms.VisualStyles.VisualStyleElement.Button.PushButton.Normal ); } cachedRenderer.DrawParentBackground ( e.Graphics, new Rectangle(0, 0, ClientSize.Width, ClientSize.Height), this ); } Rectangle rect = new Rectangle(0, 0, ClientSize.Width/2+1, ClientSize.Height); if (rect.Width<2) rect.Width = 2; ControlPaint.DrawBorder3D ( e.Graphics, rect, Border3DStyle.Etched, Border3DSide.Right ); }