protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); var g = pe.Graphics; if (!(Data is CodePart)) { g.DrawRectangle(new Pen(ControlPaint.Dark(BackColor, 0.01f), 5), ClientRectangle); g.DrawString(Text, Font, new SolidBrush(BackColor.TextColor()), ClientRectangle, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); } else { var part = (CodePart)Data; g.DrawRectangle(new Pen(Color.Orange, 3), ClientRectangle); g.DrawLine(Pens.Orange, ClientRectangle.X + 10, ClientRectangle.Y + ClientRectangle.Height / 4, ClientRectangle.X + ClientRectangle.Width - 10, ClientRectangle.Y + ClientRectangle.Height / 4); StringFormat headerAlign = new StringFormat() { Alignment = StringAlignment.Center }; g.DrawString(part.DisplayName, new Font("Courier New", 11.25F, (FontStyle.Bold | FontStyle.Underline), GraphicsUnit.Point, 0), Brushes.Black, new RectangleF(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height / 4), headerAlign); StringFormat detailsAlign = new StringFormat() { Alignment = StringAlignment.Center }; g.DrawString(part.Details, new Font("Courier New", 8.25F, FontStyle.Italic, GraphicsUnit.Point, 0), Brushes.Black, new RectangleF(ClientRectangle.X, ClientRectangle.Y + ClientRectangle.Height / 4, ClientRectangle.Width, ClientRectangle.Height / 4 * 3), detailsAlign); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var g = e.Graphics; var darkPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 5); Rectangle bounds = new Rectangle(-3, -3, Width + 3, Height + 3); g.DrawRectangle(darkPen, bounds); Rectangle dropdownBox = new Rectangle(bounds.Right - bounds.Height, bounds.Y, bounds.Height, bounds.Height); if (MouseButtons == MouseButtons.Left) { g.FillRectangle(new SolidBrush(ControlPaint.DarkDark(BackColor)), dropdownBox); } g.DrawRectangle(darkPen, dropdownBox); var ArrowPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 2); g.DrawLine(ArrowPen, dropdownBox.Left + dropdownBox.Width / 6, dropdownBox.Top + dropdownBox.Height / 3, dropdownBox.Left + dropdownBox.Width / 2, dropdownBox.Top + dropdownBox.Height / 3 * 2); g.DrawLine(ArrowPen, dropdownBox.Right - dropdownBox.Width / 6, dropdownBox.Top + dropdownBox.Height / 3, dropdownBox.Right - dropdownBox.Width / 2, dropdownBox.Top + dropdownBox.Height / 3 * 2); TextRenderer.DrawText(e.Graphics, Items[SelectedIndex].ToString(), Font, new Rectangle(0, 0, bounds.Width - bounds.Height, bounds.Height), BackColor.TextColor()); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_PAINT) { Graphics g = Graphics.FromHwnd(Handle); g.Clear(BackColor); var darkPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 5); Rectangle bounds = new Rectangle(0, 0, Width, Height); g.DrawRectangle(darkPen, bounds); Rectangle dropdownBox = new Rectangle(bounds.Right - bounds.Height, bounds.Y, bounds.Height, bounds.Height); if (MouseButtons == MouseButtons.Left) { g.FillRectangle(new SolidBrush(ControlPaint.DarkDark(BackColor)), dropdownBox); } g.DrawRectangle(darkPen, dropdownBox); var ArrowPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 2); g.DrawLine(ArrowPen, dropdownBox.Left + dropdownBox.Width / 6, dropdownBox.Top + dropdownBox.Height / 3, dropdownBox.Left + dropdownBox.Width / 2, dropdownBox.Top + dropdownBox.Height / 3 * 2); g.DrawLine(ArrowPen, dropdownBox.Right - dropdownBox.Width / 6, dropdownBox.Top + dropdownBox.Height / 3, dropdownBox.Right - dropdownBox.Width / 2, dropdownBox.Top + dropdownBox.Height / 3 * 2); if (SelectedIndex >= 0) { TextRenderer.DrawText(g, Items[SelectedIndex].ToString(), Font, new Rectangle(0, 0, bounds.Width - bounds.Height, bounds.Height), BackColor.TextColor()); } } }