Click here to Skip to main content
15,891,936 members
Articles / Programming Languages / C#

Mapview

Rate me:
Please Sign up or sign in to vote.
2.28/5 (19 votes)
6 Jun 20042 min read 79.5K   3.1K   50  
Application is intended to create a 2D canvas from interactive, creating the vector graphics
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;

namespace GIS.Geometry
{
	public class Handle
	{
		#region Private members of the Graphic handles
		private int handlesize = 8;
		private Color normalcolor = Color.White;
		private Color disabledcolor=Color.Gray;
		private MapObjectArgs c1=null;
		private Label[] lbl;
		private int startl;
		private int startt;
		private int startw;
		private int starth;
		private int startx;
		private int starty;
		private bool dragging;
		#endregion
		#region Constructors for graphic handles
		public Handle()
		{
		}

		#endregion
		#region Methods of graphic handles
		//
		// Connect a Click event handler to the passed Control
		// that attaches a graphic handle to the graphic item when 
		// it is clicked
		//
		public void GetHandles(IMapviewObject g) 
		{
//			PointF[] v=new PointF(g.Vertices.Length);
//			for (int i=0; i<g.Vertices.Length; i++)
//			{
//				v[i]=new PointF(g.Vertices[i].X,g.Vertices[i].Y);
//			}
//			int cnt=v.Length;
//			Label[] lbl = new Label[cnt];
//			for (int i = 0; i<cnt; i++) 
//			{
//				lbl[i] = new System.Windows.Forms.Label();
//				lbl[i].TabIndex = i;
//				lbl[i].FlatStyle = 0 ;
//				lbl[i].BorderStyle = BorderStyle.FixedSingle;
//				lbl[i].BackColor = normalcolor;
//				lbl[i].Left=200-i; //; (int)v[i].X-handlesize/2;
//				lbl[i].Top=200 + i; //(int)v[i].Y-handlesize/2;
//				lbl[i].Text = "";
//				lbl[i].BringToFront();
//				lbl[i].Visible=true;
//				//				lbl[i].MouseDown += new MouseEventHandler(this.lbl_MouseDown);
//				//				lbl[i].MouseMove += new MouseEventHandler(this.lbl_MouseMove);
//				//				lbl[i].MouseUp += new MouseEventHandler(this.lbl_MouseUp);
//			}

//			//Position sizing handles around Control
//			MoveHandles();
//
//			//Display sizing handles
//			ShowHandles();
			//o.GraphicSelected+= new GraphicEvents(this.CreateHandles);
		}
		//
		// Attaches a graphic handle to the selected graphic item
		//
		private void CreateHandles(IMapviewObject g) 
		{
			PointF[] v=g.Vertices;
			for (int i = 0; i<v.Length; i++) 
			{
				lbl[i] = new Label();
				lbl[i].TabIndex = i;
				lbl[i].FlatStyle = 0 ;
				lbl[i].BorderStyle = BorderStyle.FixedSingle;
				lbl[i].BackColor = normalcolor;
				lbl[i].Left=(int)v[i].X-handlesize/2;
				lbl[i].Top=(int)v[i].Y-handlesize/2;
				lbl[i].Text = "";
				lbl[i].BringToFront();
				lbl[i].Visible=true;
//				lbl[i].MouseDown += new MouseEventHandler(this.lbl_MouseDown);
//				lbl[i].MouseMove += new MouseEventHandler(this.lbl_MouseMove);
//				lbl[i].MouseUp += new MouseEventHandler(this.lbl_MouseUp);
			}

			//Position sizing handles around Control
			MoveHandles();

			//Display sizing handles
			ShowHandles();
		}

		public void Remove() 
		{
			HideHandles();
//			m_control.Cursor = oldCursor;
		}
		public void MoveHandles()
		{
		}

		private void ShowHandles() 
		{
			if (c1!=null) 
			{
				for (int i = 0; i<8; i++) 
				{
					lbl[i].Visible = true;
				}
			}
		}

		private void HideHandles() 
		{
			for (int i = 0; i<8; i++) 
			{
				lbl[i].Visible = false;
			}
		}
		/////////////////////////////////////////////////////////////////
		// MOUSE EVENTS THAT IMPLEMENT SIZING OF THE PICKED CONTROL
		/////////////////////////////////////////////////////////////////

		//
		// Store control position and size when mouse button pushed over
		// any sizing handle
		//
		private void lbl_MouseDown(object sender, MouseEventArgs e) 
		{
			dragging = true;
//			startl = m_control.Left;
//			startt = m_control.Top;
//			startw = m_control.Width;
//			starth = m_control.Height;
			HideHandles();
		}

		//
		// Size the picked control in accordance with sizing handle being dragged
		//	0   1   2
		//  7       3
		//  6   5   4
		//
		private void lbl_MouseMove(object sender, MouseEventArgs e) 
		{
//			int l = m_control.Left;
//			int w = m_control.Width;
//			int t = m_control.Top;
//			int h = m_control.Height;
//			if (dragging) 
//			{
//				switch (((Label)sender).TabIndex) 
//				{
//					case 0: // Dragging top-left sizing box
//						l = startl + e.X < startl + startw - MIN_SIZE ? startl + e.X : startl + startw - MIN_SIZE;
//						t = startt + e.Y < startt + starth - MIN_SIZE ? startt + e.Y : startt + starth - MIN_SIZE;
//						w = startl + startw - m_control.Left;
//						h = startt + starth - m_control.Top;
//						break;
//					case 1: // Dragging top-center sizing box
//						t = startt + e.Y < startt + starth - MIN_SIZE ? startt + e.Y : startt + starth - MIN_SIZE;
//						h = startt + starth - m_control.Top;
//						break;
//					case 2: // Dragging top-right sizing box
//						w = startw + e.X > MIN_SIZE ? startw + e.X : MIN_SIZE;
//						t = startt + e.Y < startt + starth - MIN_SIZE ? startt + e.Y : startt + starth - MIN_SIZE;
//						h = startt + starth - m_control.Top;
//						break;
//					case 3: // Dragging right-middle sizing box
//						w = startw + e.X > MIN_SIZE ? startw + e.X : MIN_SIZE;
//						break;
//					case 4: // Dragging right-bottom sizing box
//						w = startw + e.X > MIN_SIZE ? startw + e.X : MIN_SIZE;
//						h = starth + e.Y > MIN_SIZE ? starth + e.Y : MIN_SIZE;
//						break;
//					case 5: // Dragging center-bottom sizing box
//						h = starth + e.Y > MIN_SIZE ? starth + e.Y : MIN_SIZE;
//						break;
//					case 6: // Dragging left-bottom sizing box
//						l = startl + e.X < startl + startw - MIN_SIZE ? startl + e.X : startl + startw - MIN_SIZE;
//						w = startl + startw - m_control.Left;
//						h = starth + e.Y > MIN_SIZE ? starth + e.Y : MIN_SIZE;
//						break;
//					case 7: // Dragging left-middle sizing box
//						l = startl + e.X < startl + startw - MIN_SIZE ? startl + e.X : startl + startw - MIN_SIZE;
//						w = startl + startw - m_control.Left;
//						break;
//				}
//				l =(l<0)?0:l;
//				t =(t<0)?0:t;
//				m_control.SetBounds(l,t,w,h);
//			}
		}

		//
		// Display sizing handles around picked control once sizing has completed
		//
		private void lbl_MouseUp(object sender, MouseEventArgs e) 
		{
			dragging = false;
			MoveHandles();
			ShowHandles();
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions