Solved

GDI Paint question

Posted on 2009-05-08
5
728 Views
Last Modified: 2012-06-27
I am looking at creating a particular effect on a form, yes in some way i am taking some ideas from the old winamp skin but i am just starting with GDI. What i am aiming to do is create a coloured border around the form with some effects on it to make it look 3d. However i'm not bothered on the 3d effect for the moment. I have done it but i feel this is inefficient and a bit long winded and i am sure there is another way around this. I have attached the code below so you can see what i m doing.
I have also attached a random screenshot i grabbed from google images of winamp so you can see what i am trying to sort of achieve (it is the really thin border around the outside.

Currently i am drawing 4 rectangles around the outside of the form, which obviously gives it the border effect i am looking for but there must be another way to do this?
public frmMain()
		{
			InitializeComponent();
			this.BackColor = Color.FromArgb(56, 55, 87);
		}
 
		#region Paint Stuff
 
		protected override void OnPaint(PaintEventArgs e)
		{
			PaintFormBorder(e.Graphics);
		}
 
		private void PaintFormBorder(Graphics e)
		{
			// Before i work out how to draw this properly, lets do it this way.
			// Create the brush
			SolidBrush brush = new SolidBrush(Color.FromArgb(25, 20, 26));
			e.FillRectangle(brush, new Rectangle(0, 0, 8, this.Height));
			e.FillRectangle(brush, new Rectangle(0, 0, this.Width, 8));
			e.FillRectangle(brush, new Rectangle(this.Width - 8, 0, 8, this.Height));
			e.FillRectangle(brush, new Rectangle(0, this.Height - 8, this.Width, 8));
		}
 
		protected override void OnResize(EventArgs e)
		{
			this.Invalidate();
		}
 
		#endregion

Open in new window

winamp.bmp
0
Comment
Question by:superchief
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Author Comment

by:superchief
ID: 24334725
I have now updated the paint to this (in total):

private Int32 _titleBarHeight = 0;
		private Int32 _borderHeight = 8;
		private Int32 _borderWidth = 8;
 
		public frmMain()
		{
			InitializeComponent();
			this.BackColor = Color.FromArgb(56, 55, 87);
		}
 
		#region Paint Stuff
 
		protected override void OnPaint(PaintEventArgs e)
		{
			PaintFormBorder(e.Graphics);
		}
 
		private void PaintFormBorder(Graphics e)
		{
			// Before i work out how to draw this properly, lets do it this way.
			// Create the brush
			SolidBrush brush = new SolidBrush(Color.FromArgb(25, 20, 26));
			e.FillRectangle(brush, new Rectangle(0, 0, this._borderWidth, this.Height));
			e.FillRectangle(brush, new Rectangle(0, 0, this.Width, this._borderHeight));
			e.FillRectangle(brush, new Rectangle(this.Width - 8, 0, 8, this.Height));
			e.FillRectangle(brush, new Rectangle(0, this.Height - 8, this.Width, 8));
			// draw 3d lines
 
 
 
			brush.Color = Color.FromArgb(94, 92, 103);
			e.DrawLine(new Pen(brush), 8, 8, this.Width - 8, 8);
			e.DrawLine(new Pen(brush), 8, 8, 8, this.Height - 8);
			brush.Color = Color.FromArgb(99, 99, 111);
			e.DrawLine(new Pen(brush), 8, this.Height - 8, this.Width - 8, this.Height - 8);
			e.DrawLine(new Pen(brush), this.Width - 8, 8, this.Width - 8, this.Height - 8);
		}
 
		protected override void OnResize(EventArgs e)
		{
			this.Invalidate();
		}
 
		#endregion

Open in new window

0
 
LVL 16

Accepted Solution

by:
CuteBug earned 125 total points
ID: 24334874
What you can do instead is set the background color of the form to your border color. (In Line 8)

Now you can fill the rectangle which is inside your border with your actual background color.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24334980
Not sure if you are aware, but Winamp uses graphics for its skins. Even the borders are part of some graphic.
0
 
LVL 1

Author Comment

by:superchief
ID: 24335121
@kaufmed:

I do know that winamp uses graphics, however for me this is more a self training thing for GDI. I find the best way to teach myself something is to start a project that needs the particular thing i want to learn and then jump in. I know this is not the best method but working through examples doesn't really help me for real world situations. So in this instance, i am going to draw an app with everything drawn through GDI
0
 
LVL 1

Author Closing Comment

by:superchief
ID: 31579450
Strange i didn't see this option before, cheers
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 57
Groupbox Control ? 2 29
pressing download button in c# 7 36
Visual C# Windows Project - Clone Form 4 26
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question