void CustomComboBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) { return; } ComboBox cb = (ComboBox)sender; Graphics g = e.Graphics; Color clrText; Color clrHighlight; Color clrShadow; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { clrHighlight = ForeColor; clrText = BackColor; clrShadow = Color.Transparent; } else { clrHighlight = BackColor; if (Enabled) { clrText = ForeColor; } else { clrText = ColorTranslator.FromHtml("#A0A0A0"); } clrShadow = ShadowColor; } DrawingPlus.DrawBilinearHorizontalGradient(g, e.Bounds, clrHighlight, 3); if (clrShadow != Color.Transparent) { g.DrawString(cb.Items[e.Index].ToString(), e.Font, new SolidBrush(ShadowColor), new Point(e.Bounds.X - 1, e.Bounds.Y + 1)); } g.DrawString(cb.Items[e.Index].ToString(), e.Font, new SolidBrush(clrText), new Point(e.Bounds.X, e.Bounds.Y)); e.DrawFocusRectangle(); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Brush fb; Rectangle recBody = new Rectangle(Height, 0, Width - Height, Height); Rectangle recBuilding = new Rectangle(0, 0, Height, Height); g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if (Enabled) { fb = new SolidBrush(ForeColor); } else { fb = new SolidBrush(ColorTranslator.FromHtml("#A0A0A0")); } if (Selected == false) { g.FillRectangle(new SolidBrush(BackColor), recBody); g.FillRectangle(Brushes.DarkRed, recBuilding); } else { DrawingPlus.DrawBilinearHorizontalGradient(g, recBody, BackColor, -1); DrawingPlus.DrawBilinearHorizontalGradient(g, recBuilding, Color.DarkRed, -1); } g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawImage(Building.Icon[CultureID], new Rectangle(0, 4, 32, 25)); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; g.DrawString(Text, Font, new SolidBrush(ShadowColor), new Rectangle(recBody.X + 1, recBody.Y + 1, recBody.Width, recBody.Height), sf); g.DrawString(Text, Font, fb, recBody, sf); }
private void OnDraw(object sender, DrawToolTipEventArgs e) { Graphics g = e.Graphics; Color clrFaction = Faction.Color; int titleTextSpacer = 1; int borderSize = 1; Rectangle r = new Rectangle(1, 1, e.Bounds.Width - 2, e.Bounds.Height - 2); Rectangle rTitle = new Rectangle(r.X, r.Y, r.Width, 16); Rectangle rBody = new Rectangle(r.X, r.Y + rTitle.Height + borderSize, r.Width, r.Height - rTitle.Height - borderSize); g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.Clear(Color.Black); // Header DrawingPlus.DrawBilinearHorizontalGradient(g, rTitle, clrFaction, 2); // Body g.FillRectangle(new LinearGradientBrush(e.Bounds, clrFaction, Color.White, 45f), rBody); // Faction Symbol g.DrawImage(DrawingPlus.ResizeImage(Faction.Symbol, 39, 39), new Point(1, rBody.Y + (rBody.Height - 39) / 2)); // Resource Icon if (Region.Resource != 0) { g.DrawImage((DrawingPlus.ResizeImage(Resource.Icon, 16, 16)), new Point(titleTextSpacer, 1)); titleTextSpacer += 17; } // Religion Icon if (Region.DominantReligion != 0) { g.DrawImage((DrawingPlus.ResizeImage(Religion.Icon, 16, 16)), new Point(titleTextSpacer, 1)); titleTextSpacer += 17; } // Capital Icon if (Region.Type == RegionType.Capital) { Image imgCapital; if (Region.State == RegionState.Free) { imgCapital = DrawingPlus.ResizeImage(DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "Capital.PNG"), 16, 16); } else { imgCapital = DrawingPlus.ResizeImage(DrawingPlus.LoadImage(NarivianClass.IconsDirectory + "Capital Other.PNG"), 16, 16); } g.DrawImage(imgCapital, new Point(e.Bounds.Width - 17, 1)); } // Title g.DrawString(Region.Name, new Font("Microsoft Sans Serif", 10, FontStyle.Bold), Brushes.Black, new Point(rTitle.X + titleTextSpacer, rTitle.Y)); // Message g.DrawString(e.ToolTipText, new Font("Microsoft Sans Serif", 8), Brushes.Black, new PointF(40, rBody.Y + 2)); // Border //g.DrawRectangle(new Pen(Color.Black, borderSize * 2), new Rectangle( //e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1)); //g.DrawLine(new Pen(Color.Black, borderSize), new Point(0, 17), new Point(e.Bounds.Width, 17)); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Brush fb; Rectangle recBody = new Rectangle(Width / 4, 0, Width - Width / 4, Height); Rectangle recMap = new Rectangle(0, 0, Width / 4, Height); g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; if (Enabled) { fb = new SolidBrush(ForeColor); } else { fb = new SolidBrush(ColorTranslator.FromHtml("#A0A0A0")); } if (Selected == false) { g.FillRectangle(new SolidBrush(BackColor), recBody); g.FillRectangle(Brushes.DarkRed, recMap); } else { DrawingPlus.DrawBilinearHorizontalGradient(g, recBody, BackColor, -1); DrawingPlus.DrawBilinearHorizontalGradient(g, recMap, Color.DarkRed, -1); } // Status icon g.SmoothingMode = SmoothingMode.AntiAlias; Image imgStatus; if (Installed) { if (UpToDate) { imgStatus = Properties.Resources.Success; } else { imgStatus = Properties.Resources.Warning; } } else { imgStatus = Properties.Resources.Error; } g.DrawImage(imgStatus, new Rectangle(Width - Height, 0, Height, Height)); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; // Map Name g.DrawString(MapDisplayName + " (v" + MapVersion + ")", Font, new SolidBrush(ShadowColor), new Rectangle(recMap.X + 1, recMap.Y + 1, recMap.Width, recMap.Height), sf); g.DrawString(MapDisplayName + " (v" + MapVersion + ")", Font, fb, recMap, sf); // Map Description g.DrawString(MapDescription, Font, new SolidBrush(ShadowColor), new Rectangle(recBody.X + 1, recBody.Y + 1, recBody.Width, recBody.Height), sf); g.DrawString(MapDescription, Font, fb, recBody, sf); }