Click here to Skip to main content
15,885,141 members
Articles / Programming Languages / C#

Universal Framework for Science and Engineering - Part 4: Space elevator

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
14 Aug 20066 min read 36.6K   2.2K   37  
An article on framework applications to the space elevator.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using CategoryTheory;
using DiagramUI;


namespace ImageTransformations
{
	/// <summary>
	/// Summary description for FormSourceBitmap.
	/// </summary>
	public class FormSourceBitmap : System.Windows.Forms.Form, IUpdatableForm
	{
		private System.Windows.Forms.Panel panelBitmap;
		private System.Windows.Forms.Panel panelComments;
		private System.Windows.Forms.OpenFileDialog openFileDialogBmp;
		private System.Windows.Forms.MainMenu mainMenuFile;
		private System.Windows.Forms.MenuItem menuItemFile;
		private System.Windows.Forms.MenuItem menuItemOpen;


		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private IObjectLabel label;
		private System.Windows.Forms.Panel panelBmp;
		private System.Windows.Forms.Label labelB;
		private System.Windows.Forms.Label labelG;
		private System.Windows.Forms.Label labelR;
		private System.Windows.Forms.Label labelY;
		private System.Windows.Forms.Label labelX;
		private SourceBitmap bitmap;

		private FormSourceBitmap()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}



		public FormSourceBitmap(IObjectLabel label)
		{
			InitializeComponent();
			ResourceService.Resources.LoadControlResources(this);
			panelBmp.Top = 0;
			panelBmp.Left = 0;
			this.label = label;
			bitmap = label.Object as SourceBitmap;
			UpdateFormUI();
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
		//	NamedComponent.RemoveForm(label);
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormSourceBitmap));
			this.panelBitmap = new System.Windows.Forms.Panel();
			this.panelBmp = new System.Windows.Forms.Panel();
			this.panelComments = new System.Windows.Forms.Panel();
			this.openFileDialogBmp = new System.Windows.Forms.OpenFileDialog();
			this.mainMenuFile = new System.Windows.Forms.MainMenu();
			this.menuItemFile = new System.Windows.Forms.MenuItem();
			this.menuItemOpen = new System.Windows.Forms.MenuItem();
			this.labelB = new System.Windows.Forms.Label();
			this.labelG = new System.Windows.Forms.Label();
			this.labelR = new System.Windows.Forms.Label();
			this.labelY = new System.Windows.Forms.Label();
			this.labelX = new System.Windows.Forms.Label();
			this.panelBitmap.SuspendLayout();
			this.SuspendLayout();
			// 
			// panelBitmap
			// 
			this.panelBitmap.AllowDrop = true;
			this.panelBitmap.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelBitmap.Controls.Add(this.panelBmp);
			this.panelBitmap.Location = new System.Drawing.Point(88, 136);
			this.panelBitmap.Name = "panelBitmap";
			this.panelBitmap.Size = new System.Drawing.Size(840, 592);
			this.panelBitmap.TabIndex = 0;
			// 
			// panelBmp
			// 
			this.panelBmp.Cursor = System.Windows.Forms.Cursors.Cross;
			this.panelBmp.Location = new System.Drawing.Point(128, 48);
			this.panelBmp.Name = "panelBmp";
			this.panelBmp.TabIndex = 0;
			this.panelBmp.Paint += new System.Windows.Forms.PaintEventHandler(this.panelBmp_Paint);
			this.panelBmp.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panelBmp_MouseMove);
			// 
			// panelComments
			// 
			this.panelComments.BackColor = System.Drawing.SystemColors.ControlLightLight;
			this.panelComments.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panelComments.Location = new System.Drawing.Point(96, 16);
			this.panelComments.Name = "panelComments";
			this.panelComments.Size = new System.Drawing.Size(832, 96);
			this.panelComments.TabIndex = 1;
			// 
			// openFileDialogBmp
			// 
			this.openFileDialogBmp.Filter = "Bitmap files |*.bmp";
			// 
			// mainMenuFile
			// 
			this.mainMenuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItemFile});
			// 
			// menuItemFile
			// 
			this.menuItemFile.Index = 0;
			this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItemOpen});
			this.menuItemFile.Text = "File";
			// 
			// menuItemOpen
			// 
			this.menuItemOpen.Index = 0;
			this.menuItemOpen.Text = "Open";
			this.menuItemOpen.Click += new System.EventHandler(this.menuItemOpen_Click);
			// 
			// labelB
			// 
			this.labelB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.labelB.ForeColor = System.Drawing.Color.Navy;
			this.labelB.Location = new System.Drawing.Point(944, 432);
			this.labelB.Name = "labelB";
			this.labelB.TabIndex = 20;
			this.labelB.Text = "B =";
			// 
			// labelG
			// 
			this.labelG.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.labelG.ForeColor = System.Drawing.Color.Green;
			this.labelG.Location = new System.Drawing.Point(944, 376);
			this.labelG.Name = "labelG";
			this.labelG.TabIndex = 19;
			this.labelG.Text = "G = ";
			// 
			// labelR
			// 
			this.labelR.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.labelR.ForeColor = System.Drawing.Color.Crimson;
			this.labelR.Location = new System.Drawing.Point(944, 328);
			this.labelR.Name = "labelR";
			this.labelR.TabIndex = 18;
			this.labelR.Text = "R = ";
			// 
			// labelY
			// 
			this.labelY.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.labelY.Location = new System.Drawing.Point(944, 280);
			this.labelY.Name = "labelY";
			this.labelY.TabIndex = 17;
			this.labelY.Text = "Y =";
			// 
			// labelX
			// 
			this.labelX.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));
			this.labelX.Location = new System.Drawing.Point(944, 232);
			this.labelX.Name = "labelX";
			this.labelX.TabIndex = 16;
			this.labelX.Text = "X = ";
			// 
			// FormSourceBitmap
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(1056, 773);
			this.Controls.Add(this.labelB);
			this.Controls.Add(this.labelG);
			this.Controls.Add(this.labelR);
			this.Controls.Add(this.labelY);
			this.Controls.Add(this.labelX);
			this.Controls.Add(this.panelComments);
			this.Controls.Add(this.panelBitmap);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenuFile;
			this.Name = "FormSourceBitmap";
			this.Text = "FormSourceBitmap";
			this.panelBitmap.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		#region IUpdatableForm Members

		public void UpdateFormUI()
		{
			Text = label.RootName;//NamedComponent.GetText(label);
		}

		#endregion


		private void menuItemOpen_Click(object sender, System.EventArgs e)
		{
			if (openFileDialogBmp.ShowDialog(this) != DialogResult.OK)
			{
				return;
			}
			Bitmap bmp = new Bitmap(openFileDialogBmp.FileName);
			bitmap.SetBitmap(bmp);
			Refresh();
		}

		private void panelBmp_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Bitmap bmp = bitmap.Bitmap;
			if (bmp == null)
			{
				return;
			}
			if ((panelBmp.Width != bmp.Width) | (panelBmp.Height != bmp.Height))
			{
				panelBmp.Width = bmp.Width;
				panelBmp.Height = bmp.Height;
			}
			e.Graphics.DrawImage(bmp, 0, 0);

		}

		private void panelBmp_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			int x = e.X;
			int y = e.Y;
			Bitmap bmp = bitmap.Bitmap;
			if (bmp == null)
			{
				return;
			}
			if ((x >= bmp.Width) | (y >= bmp.Height))
			{
				return;
			}
			labelX.Text = "X = " + x;
			labelY.Text = "Y = " + y;
			Color c = bmp.GetPixel(x, y);
			labelR.Text = "R = " + c.R;
			labelG.Text = "G = " + c.G;
			labelB.Text = "B = " + c.B;

		}
	}
}

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
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions