Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[C#] Draw custom sinisterly winForms using GDI+ filter_list
Author
Message
[C#] Draw custom sinisterly winForms using GDI+ #1
Hello folks,
I was kinda bored and decided to push my activity here again so let's start with some custom GDI+ WinForms drawing shenanigans. I just created this custom form to demonstrate how easy it can be to get some custom forms, it isn't that pretty but I just tried to get as close to the forums as possible. Please tell me if you are interested in a real tutorial of more advanced stuff or maybe a whole GDI+ tutorial, I don't know what people around here would like to see so anything C# related will be fine  Cool

Just put the following code into your forms PaintEventHandler and set the forms BorderStyle property to none.

Code:
String title = this.Text;

Color clBackground = Color.FromArgb(20, 20, 20); // background
Color clBackgroundBorder = Color.FromArgb(24, 24, 24); // background border
Color clForeground = Color.FromArgb(28, 28, 28); // foreground

Color clHeaderBackground = Color.FromArgb(17, 17, 17); // header background
Color clHeaderForeground = Color.FromArgb(31, 31, 31); // header foreground
Color clHeaderFont = Color.FromArgb(206, 206, 206); // header font

e.Graphics.FillRectangle(new SolidBrush(clBackground), new Rectangle(new Point(0, 0), new Size(this.Width, this.Height))); // Draw background
e.Graphics.DrawRectangle(new Pen(clBackgroundBorder), new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1))); // Draw background border
e.Graphics.FillRectangle(new SolidBrush(clHeaderBackground), new Rectangle(new Point(11, 11), new Size(this.Width - 22, 40))); // Draw header background

Size textSize = TextRenderer.MeasureText(title, new Font("Arial", 9.0f)); // Measure title size in px
int contentWidth = textSize.Width + 12; // Variable that holds the header foreground and TextRenderer width

e.Graphics.FillRectangle(new SolidBrush(clHeaderForeground), new Rectangle(15, 17, contentWidth, 28)); // Draw header foreground rectangle
Point[] trianglePoints = { new Point(contentWidth + 15, 17), new Point(contentWidth + 15, 45), new Point(contentWidth + 25, 31) }; // Calculate triangle points
e.Graphics.FillPolygon(new SolidBrush(clHeaderForeground), trianglePoints); // Draw triangle next to the header foreground rectangle
TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis; // TextFormat shenanigans
TextRenderer.DrawText(e.Graphics, title, new Font("Arial", 9.0f), new Rectangle(22, 17, contentWidth, 28), clHeaderFont, flags); // Draw title

e.Graphics.FillRectangle(new SolidBrush(clForeground), new Rectangle(new Point(11, 61), new Size(this.Width - 22, this.Height - 72))); // Draw foreground

[Image: uzayxkM.png]



Something else I'm currently working on in case you don't like the sinisterly example I just made:

[Image: szYcRcL.png]

Reply

RE: [C#] Draw custom sinisterly winForms using GDI+ #2
Code:
The only thing VB has going for it is the basic syntax if you grew on it so it has a sorta nostalgic value ("muh goto").

Reply







Users browsing this thread: 1 Guest(s)