public Locality(Config conf, Calendar cal) { SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); InitializeComponent(); comboBoxZones.Items.Add("Select time zone..."); comboBoxZones.Items.AddRange(Config.AllZones); this.conf = conf; formCalendar = cal; formCalendar.FormLocalityOpen = true; Closing += new System.ComponentModel.CancelEventHandler(this.formClosing); for (int i = 0; i < conf.PlaceNum; i++) { comboBoxCity.Items.Add(conf.Places[i].Name); } comboBoxCity.Text = conf.DefaultLocality.Name; if (!PInvoke.VisualStylesEnabled()) { Config.FixRadioButtons(Controls, FlatStyle.Standard); } }
protected override void OnPaintBackground(PaintEventArgs e) { if (!PInvoke.VisualStylesEnabled()) { using (SolidBrush sb = new SolidBrush(BackColor)) e.Graphics.FillRectangle(sb, DisplayRectangle); return; } IntPtr hTheme = PInvoke.OpenThemeData(Handle, "Tab"); if (hTheme == IntPtr.Zero) { using (SolidBrush sb = new SolidBrush(BackColor)) e.Graphics.FillRectangle(sb, DisplayRectangle); return; } PInvoke.Rect rDisplayRect = new PInvoke.Rect(DisplayRectangle); PInvoke.Rect rClipArea = new PInvoke.Rect(e.Graphics.VisibleClipBounds); IntPtr hDC = e.Graphics.GetHdc(); PInvoke.DrawThemeBackground(hTheme, hDC, PInvoke.TABP_BODY, 0, ref rDisplayRect, ref rClipArea); e.Graphics.ReleaseHdc(hDC); PInvoke.CloseThemeData(hTheme); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { // Apparantly OnPaintBackground isn't used in CheckBox so we must do this here. if (BackColor == Color.Transparent && PInvoke.VisualStylesEnabled()) { IntPtr bghDC = e.Graphics.GetHdc(); PInvoke.Rect rBounds = new PInvoke.Rect(0, 0, Width, Height); PInvoke.DrawThemeParentBackground(Handle, bghDC, ref rBounds); e.Graphics.ReleaseHdc(bghDC); } else { using (SolidBrush sb = new SolidBrush(BackColor)) e.Graphics.FillRectangle(sb, new Rectangle(0, 0, Width, Height)); } if (!PInvoke.VisualStylesEnabled()) { base.OnPaint(e); return; } IntPtr hTheme = PInvoke.OpenThemeData(Handle, "Button"); if (hTheme == IntPtr.Zero) { base.OnPaint(e); return; } RectangleF leftF = new RectangleF(0, 0, 14, Height); RectangleF clipF = e.Graphics.VisibleClipBounds; PInvoke.Rect rLeft = new PInvoke.Rect(leftF); PInvoke.Rect rClip = /*rLeft;*/ new PInvoke.Rect(clipF); Rectangle rRight = new Rectangle(15, 0, Width - 15, Height); IntPtr hDC = e.Graphics.GetHdc(); PInvoke.DrawThemeBackground(hTheme, hDC, PInvoke.BP_CHECKBOX, checkBoxState(), ref rLeft, ref rClip); PInvoke.CloseThemeData(hTheme); e.Graphics.ReleaseHdc(hDC); if (Text != null && Text.Length > 0) { using (StringFormat sf = stringFormatOf(TextAlign)) using (SolidBrush sb = new SolidBrush(Enabled ? ForeColor : SystemColors.GrayText)) { e.Graphics.DrawString(Text, Font, sb, rRight, sf); if (Focused && !pressed) { SizeF sz = e.Graphics.MeasureString(Text, Font, rRight.Width, sf); Rectangle rText = new Rectangle(15, 0, (int)Math.Ceiling(sz.Width), (int)Math.Ceiling(sz.Height)); if (UseFocusRectangle) { ControlPaint.DrawFocusRectangle(e.Graphics, rText); } } } } }
// Paint the glyph, title, text and close button. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { // Draw the glyph image e.Graphics.DrawImage(glyphImage, padding + 2, (int)Math.Ceiling(szTitle.Height) + (padding * 2), glyphImage.Width, glyphImage.Height); Font useFont; Brush useBrush; if (titleHover) { useFont = ulTitleFont; } else { useFont = titleFont; } if (titleMouseDown) { useBrush = Brushes.Gray; } else { useBrush = Brushes.Black; } // Title string e.Graphics.DrawString("ChronosXP", useFont, useBrush, rTitle, tFormat); if (textHover) { useFont = ulFont; } else { useFont = Font; } if (textMouseDown) { useBrush = Brushes.Gray; } else { useBrush = Brushes.Black; } // "Day of ____", "Hour of ___" text. e.Graphics.DrawString(line1, useFont, useBrush, rLine1, tFormat); e.Graphics.DrawString(line2, useFont, useBrush, rLine2, tFormat); if (PInvoke.VisualStylesEnabled()) { drawThemeCloseButton(e.Graphics); } else { drawLegacyCloseButton(e.Graphics); } }
protected override void OnPaintBackground(PaintEventArgs e) { if (conf.UseGradient && PInvoke.VisualStylesEnabled()) { using (LinearGradientBrush lgb = new LinearGradientBrush(DisplayRectangle, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical)) e.Graphics.FillRectangle(lgb, DisplayRectangle); } else { e.Graphics.FillRectangle(SystemBrushes.ControlLight, DisplayRectangle); } }
protected override void OnPaintBackground(PaintEventArgs e) { if (!PInvoke.VisualStylesEnabled() || BackColor != Color.Transparent) { base.OnPaintBackground(e); return; } IntPtr hDC = e.Graphics.GetHdc(); PInvoke.Rect rBounds = new PInvoke.Rect(0, 0, Width, Height); PInvoke.DrawThemeParentBackground(Handle, hDC, ref rBounds); e.Graphics.ReleaseHdc(hDC); }
protected override void OnPaintBackground(PaintEventArgs e) { if (PInvoke.VisualStylesEnabled() && BackColor == Color.Transparent) { PInvoke.Rect rFull = new PInvoke.Rect(0, 0, Width, Height); IntPtr hDC = e.Graphics.GetHdc(); PInvoke.DrawThemeParentBackground(Handle, hDC, ref rFull); e.Graphics.ReleaseHdc(hDC); } else { Color useBackColor = BackColor; // If BackColor == Transparent, we must figure out the next Parent BackColor that isn't transparent and paint it ourself, since // ControlStyles.UserPaint and ControlStyles.AllPaintingInWmPaint are set. if (BackColor == Color.Transparent) { try { for (Control c = Parent; true; c = c.Parent) { if (c.BackColor != Color.Transparent) { useBackColor = c.BackColor; break; } } } catch { useBackColor = SystemColors.Control; } } using (SolidBrush sb = new SolidBrush(useBackColor)) e.Graphics.FillRectangle(sb, new Rectangle(0, 0, Width, Height)); } }
protected override void OnPaint(PaintEventArgs e) { if (!PInvoke.VisualStylesEnabled()) { base.OnPaint(e); return; } IntPtr hTheme = PInvoke.OpenThemeData(Handle, "Button"); if (hTheme == IntPtr.Zero) { base.OnPaint(e); return; } SizeF sz; // Text needs to be measured here because e.Graphics will soon be tied up with GetHdc() if (Text != null && Text.Length > 0) { sz = e.Graphics.MeasureString(Text, Font, DisplayRectangle.Width - 17, StringFormat.GenericDefault); } else { sz = new SizeF(); // have to set sz or else compiler will complain } // You'd think the height should be (Height - (Font.Height/2)), but using full Height gives a size consistent with FlatStyle.System XP GroupBox'es PInvoke.Rect rBounds = new PInvoke.Rect(0, Font.Height / 2, Width, Height); PInvoke.Rect rClip = new PInvoke.Rect(e.Graphics.VisibleClipBounds); IntPtr hDC = e.Graphics.GetHdc(); PInvoke.DrawThemeBackground(hTheme, hDC, PInvoke.BP_GROUPBOX, (Enabled ? PInvoke.GBS_NORMAL : PInvoke.GBS_DISABLED), ref rBounds, ref rClip); if (Text != null && Text.Length > 0) { RectangleF rText = new RectangleF(7, 0, sz.Width + 3.2F, sz.Height); PInvoke.Rect wrText = new PInvoke.Rect(rText); // Redraw the background over the border where text will be displayed if (BackColor == Color.Transparent) { PInvoke.DrawThemeParentBackground(Handle, hDC, ref wrText); e.Graphics.ReleaseHdc(hDC); } else { e.Graphics.ReleaseHdc(hDC); using (SolidBrush sb = new SolidBrush(BackColor)) e.Graphics.FillRectangle(sb, rText); } Color textColor; if (Enabled) { PInvoke.ColorRef rColor = new PInvoke.ColorRef(); PInvoke.GetThemeColor(hTheme, PInvoke.BP_GROUPBOX, PInvoke.GBS_NORMAL, PInvoke.TMT_TEXTCOLOR, ref rColor); textColor = rColor.ToColor(); } else // GetThemeColor (... GBS_DISABLED ...) always returns the default color - so use GrayText { textColor = SystemColors.GrayText; } rText.Inflate(-0.8F, 0); rText.Offset(0.4F, 0); using (SolidBrush sb = new SolidBrush(textColor)) e.Graphics.DrawString(Text, Font, sb, rText, StringFormat.GenericDefault); } else { e.Graphics.ReleaseHdc(hDC); } PInvoke.CloseThemeData(hTheme); }