3 Replies - 8464 Views - Last Post: 31 March 2009 - 04:42 PM Rate Topic: -----

#1 Chucksta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-February 09

How do you create a heart shaped control ?

Posted 13 February 2009 - 03:30 PM

How do you make different shaped controls (heart, star, circular etc.) ?

I bought a book on custom controls, but they do not say anything on making them with a different shape to the norm :(

This is for a Uni project for developing a visual programming language for Neverwinter Nights. It will assist the user in the scripting side, by allowing them to build up an event (Give gold to Player) by manipulating graphical objects that represent components of the event(s), then on the press of a "Save" the finished product will be saved as a script.

I want to make these graphical object appear like peices of a puzzle, but I do not know how to make controls with any other shape than the default.

Any help will be very much appreciated :-)

Is This A Good Question/Topic? 0
  • +

Replies To: How do you create a heart shaped control ?

#2 nbarten  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 162
  • Joined: 30-April 07

Re: How do you create a heart shaped control ?

Posted 14 February 2009 - 01:52 AM

Yes i'm interested in this too... like a circular button instead the normal one.
Was This Post Helpful? 0
  • +
  • -

#3 jeh71  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-March 09

Re: How do you create a heart shaped control ?

Posted 31 March 2009 - 12:01 PM

I was just doing some research on creating a round control, and found an interesting .NET class called GraphicsPath. This is part of the System.Drawing.Drawing2D Namespace. I have not finished the research, so I don't yet have any code examples to post. However, you can learn more on the MSDN website at the following location:

http://msdn.microsof...y/b5hek5ky.aspx

It looks like this class will allow you to add a variety of shapes to the GraphicsPath object, and it will combine these in the order you add them. Therefore, you could build a heart shape using two arcs and two lines. (Add the first arc, then a diagonal line down, then a diagonal line up, the the second arc. Ensure that the starting point of the first arc and the ending point of the second arc are at the same location.)

To make a control use this shape as its region, you would assign the GraphicsPath with the heart shape to the Control.Region property of your custom control. Again, this is more fully documented on the MSDN website:

Control.Region Property on MSDN

I hope this helps. I will post an update later with an example of my custom control -- a round LED indicator.

Happy coding!
Was This Post Helpful? 0
  • +
  • -

#4 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Re: How do you create a heart shaped control ?

Posted 31 March 2009 - 04:42 PM

[quote name='Chucksta' date='13 Feb, 2009 - 09:30 PM' post='542238']
How do you make different shaped controls (heart, star, circular etc.)

Start a new windows forms project, add a button to the top left hand corner; set it's text property to 'Close Form'. Set the 'FormBorderStyle' property 'None' & the 'BackColor' to red. Now add the following code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TriangularWindowsForm
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void btnCloseForm_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			System.Drawing.Drawing2D.GraphicsPath myPath = new
				System.Drawing.Drawing2D.GraphicsPath();
			myPath.AddPolygon(new Point[] {new Point(0,0), new Point(0,this.Height),
				new Point(this.Width, 0) });
			Region myRegion = new Region(myPath);
			this.Region = myRegion;
		}
	}
}



Obviously if you play about with this you will get the idea of non-rectangular forms in general. All the best!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1