Cant get my graph to work correct

Mickeys
Mickeys used Ask the Experts™
on
I got someproblems with my graph.

When I add a x,y I want it to show as a DOT (but still be painted out as it is know)
I also would like to be abel to get my cursor on the panel and see where I am on the chart.
And last I could like it to be drawn correct when changing the intervalls. right now it seems that intervall only works ok.

I can split this question up into diffrent threads after they have been solved so you get your points. :-)

The code is below and you can just pase it into your workspace if that is needed
form1.design.cs
------------------------
namespace LChart
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.addButton = new System.Windows.Forms.Button();
            this.xTextBox = new System.Windows.Forms.TextBox();
            this.yTextBox = new System.Windows.Forms.TextBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.xRiktTextBox = new System.Windows.Forms.TextBox();
            this.yRiktTextBox = new System.Windows.Forms.TextBox();
            this.okButton = new System.Windows.Forms.Button();
            this.resetButton = new System.Windows.Forms.Button();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
            this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.sortXaxisToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.label3 = new System.Windows.Forms.Label();
            this.panel1 = new System.Windows.Forms.Panel();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // addButton
            // 
            this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.addButton.Location = new System.Drawing.Point(119, 82);
            this.addButton.Name = "addButton";
            this.addButton.Size = new System.Drawing.Size(75, 23);
            this.addButton.TabIndex = 0;
            this.addButton.Text = "Lägg till";
            this.addButton.UseVisualStyleBackColor = true;
            this.addButton.Click += new System.EventHandler(this.button1_Click);
            // 
            // xTextBox
            // 
            this.xTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.xTextBox.Location = new System.Drawing.Point(94, 19);
            this.xTextBox.Name = "xTextBox";
            this.xTextBox.Size = new System.Drawing.Size(100, 20);
            this.xTextBox.TabIndex = 1;
            // 
            // yTextBox
            // 
            this.yTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.yTextBox.Location = new System.Drawing.Point(94, 45);
            this.yTextBox.Name = "yTextBox";
            this.yTextBox.Size = new System.Drawing.Size(100, 20);
            this.yTextBox.TabIndex = 2;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.xTextBox);
            this.groupBox1.Controls.Add(this.yTextBox);
            this.groupBox1.Controls.Add(this.addButton);
            this.groupBox1.Location = new System.Drawing.Point(472, 46);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(200, 124);
            this.groupBox1.TabIndex = 3;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Ange punkter";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(6, 26);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(59, 13);
            this.label1.TabIndex = 3;
            this.label1.Text = "x-koordinat";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(6, 52);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(59, 13);
            this.label2.TabIndex = 4;
            this.label2.Text = "y-koordinat";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.okButton);
            this.groupBox2.Controls.Add(this.yRiktTextBox);
            this.groupBox2.Controls.Add(this.xRiktTextBox);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.label4);
            this.groupBox2.Location = new System.Drawing.Point(472, 176);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(200, 146);
            this.groupBox2.TabIndex = 4;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Inställningar";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(6, 32);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(110, 13);
            this.label4.TabIndex = 1;
            this.label4.Text = "Intervalsvärde i x-riktn";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(6, 65);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(115, 13);
            this.label6.TabIndex = 3;
            this.label6.Text = "Intervallsvärde i y-riktn.";
            // 
            // xRiktTextBox
            // 
            this.xRiktTextBox.Location = new System.Drawing.Point(138, 25);
            this.xRiktTextBox.Name = "xRiktTextBox";
            this.xRiktTextBox.Size = new System.Drawing.Size(56, 20);
            this.xRiktTextBox.TabIndex = 4;
            // 
            // yRiktTextBox
            // 
            this.yRiktTextBox.Location = new System.Drawing.Point(138, 62);
            this.yRiktTextBox.Name = "yRiktTextBox";
            this.yRiktTextBox.Size = new System.Drawing.Size(56, 20);
            this.yRiktTextBox.TabIndex = 6;
            // 
            // okButton
            // 
            this.okButton.Location = new System.Drawing.Point(80, 105);
            this.okButton.Name = "okButton";
            this.okButton.Size = new System.Drawing.Size(75, 23);
            this.okButton.TabIndex = 8;
            this.okButton.Text = "Ok";
            this.okButton.UseVisualStyleBackColor = true;
            this.okButton.Click += new System.EventHandler(this.okButton_Click);
            // 
            // resetButton
            // 
            this.resetButton.Location = new System.Drawing.Point(591, 394);
            this.resetButton.Name = "resetButton";
            this.resetButton.Size = new System.Drawing.Size(75, 23);
            this.resetButton.TabIndex = 5;
            this.resetButton.Text = "Reset";
            this.resetButton.UseVisualStyleBackColor = true;
            this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.toolsToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(687, 24);
            this.menuStrip1.TabIndex = 6;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.openToolStripMenuItem,
            this.toolStripSeparator,
            this.saveToolStripMenuItem,
            this.saveAsToolStripMenuItem,
            this.toolStripSeparator1,
            this.exitToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
            this.fileToolStripMenuItem.Text = "&File";
            // 
            // newToolStripMenuItem
            // 
            this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));
            this.newToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.newToolStripMenuItem.Name = "newToolStripMenuItem";
            this.newToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
            this.newToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.newToolStripMenuItem.Text = "&New";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripMenuItem.Image")));
            this.openToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
            this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.openToolStripMenuItem.Text = "&Open";
            // 
            // toolStripSeparator
            // 
            this.toolStripSeparator.Name = "toolStripSeparator";
            this.toolStripSeparator.Size = new System.Drawing.Size(149, 6);
            // 
            // saveToolStripMenuItem
            // 
            this.saveToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem.Image")));
            this.saveToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
            this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
            this.saveToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.saveToolStripMenuItem.Text = "&Save";
            // 
            // saveAsToolStripMenuItem
            // 
            this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
            this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.saveAsToolStripMenuItem.Text = "Save &As";
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6);
            // 
            // exitToolStripMenuItem
            // 
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.exitToolStripMenuItem.Text = "E&xit";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
            // 
            // toolsToolStripMenuItem
            // 
            this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.sortXaxisToolStripMenuItem});
            this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
            this.toolsToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
            this.toolsToolStripMenuItem.Text = "&Tools";
            // 
            // sortXaxisToolStripMenuItem
            // 
            this.sortXaxisToolStripMenuItem.Name = "sortXaxisToolStripMenuItem";
            this.sortXaxisToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.sortXaxisToolStripMenuItem.Text = "Sort x-axis";
            this.sortXaxisToolStripMenuItem.Click += new System.EventHandler(this.sortXaxisToolStripMenuItem_Click);
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(478, 404);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 13);
            this.label3.TabIndex = 7;
            this.label3.Text = "label3";
            // 
            // panel1
            // 
            this.panel1.Cursor = System.Windows.Forms.Cursors.Cross;
            this.panel1.Location = new System.Drawing.Point(0, 27);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(463, 410);
            this.panel1.TabIndex = 8;
            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
            this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(687, 434);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.resetButton);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.menuStrip1);
            this.Controls.Add(this.panel1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
 
        }
 
        #endregion
 
        private System.Windows.Forms.Button addButton;
        private System.Windows.Forms.TextBox xTextBox;
        private System.Windows.Forms.TextBox yTextBox;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.TextBox xRiktTextBox;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Button okButton;
        private System.Windows.Forms.TextBox yRiktTextBox;
        private System.Windows.Forms.Button resetButton;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator;
        private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem toolsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem sortXaxisToolStripMenuItem;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Panel panel1;
    }
}
 
 
------------------------------
Form1.cs
----------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
 
 
namespace LChart
{
 
    
    public partial class Form1 : Form
    {
        private Bitmap bmp;
        private Image image;
        private Line2D line2d;
        private float pointX = 1.0F;
        private float pointY = 1.0F;
        private ArrayList arX = new ArrayList();
        private ArrayList arY = new ArrayList();
        int xMouse = 0;
        int yMouse = 0;
 
 
        public Form1()
        {
            InitializeComponent();
            line2d = new Line2D();
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
            line2d.XAxisText = "X-Axel";
            line2d.YAxisText = "Y-Axel";
            line2d.Title = "MyGraph";
            line2d.TitleBackColor = Color.Linen;
            line2d.TitleForeColor = Color.HotPink;
 
            line2d.InitializeGraph();            
            bmp = line2d.GetGraph();
            image = bmp;
        }
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics drawingSurface = e.Graphics;
            // Clear the screen 
            Rectangle realClientArea = new Rectangle(0, 0, 500, 400);  //ClientRectangle; 
            drawingSurface.DrawImage(image, realClientArea);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (xTextBox.Text != "" && yTextBox.Text != "")
            {
                arX.Add(Convert.ToInt32(xTextBox.Text));
                arY.Add(Convert.ToInt32(yTextBox.Text));
                line2d.XAxis = arX;
                line2d.YAxis = arY;
                line2d.CreateGraph(Color.Red);
 
                this.Refresh();
            }
 
            else
                MessageBox.Show("You have to add a number in the x and y textbox", "Information");
        }
 
 
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
 
            Rectangle realClientArea = ClientRectangle;
            pointX = Math.Max(0, realClientArea.Width / 1140.0F);
            pointY = Math.Max(0, realClientArea.Height / 648.0F);
            this.Refresh();
 
        }
 
        private void okButton_Click(object sender, EventArgs e)
        {
            //line2d.XSlice = Convert.ToInt32(xIntTextBox.Text); 
            //line2d.YSlice = Convert.ToInt32(yIntTextBox.Text);
            line2d.XSlice = Convert.ToInt32(xRiktTextBox.Text); //sätter hopp på x
            line2d.YSlice = Convert.ToInt32(yRiktTextBox.Text); //sätter hopp på y
 
            line2d.InitializeGraph();
            bmp = line2d.GetGraph();
            image = bmp;
 
            this.Refresh();
 
        }
 
        private void resetButton_Click(object sender, EventArgs e)
        {
            xTextBox.Text = "";
            xRiktTextBox.Text = "";
            yTextBox.Text = "";
            yRiktTextBox.Text = "";
            arX = null;
            arY = null;
            arX = new ArrayList();
            arY = new ArrayList();
            line2d.XSlice = 1; //sätter hopp på x
            line2d.YSlice = 1; //sätter hopp på y
            line2d.InitializeGraph();
            bmp = line2d.GetGraph();
            image = bmp;
 
            this.Refresh();
        }
 
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        private void sortXaxisToolStripMenuItem_Click(object sender, EventArgs e)
        {
            arX.Sort();
            line2d.InitializeGraph();
            line2d.CreateGraph(Color.Red);
            bmp = line2d.GetGraph();
            image = bmp;
 
 
            this.Refresh();
        }
 
        
      
 
       
        protected void Position()
        {
            int x = panel1.Cursor.Handle.ToInt32(); //panel1.Width; //Cursor.Position.X;//Get position x from mouse
            int y = panel1.Cursor.HotSpot.Y;   //Cursor.Position.Y;//Get position Y from mouse 
            label3.Text = "X = " + x.ToString() + "\nY = " + y.ToString(); ;
            
        }
 
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            Position();//look at event  
        }
 
 
        
 
 
 
    }
}
 
-----------------------------------------
Line2D.cs
---------------------------------------
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Collections;
 
namespace LChart
{
	/// <summary>
	/// Summary description for Line2D.
	/// </summary>
	public class Line2D
	{
		private int m_Width = 700;						//Width of the rectangle container for graph.
		private int m_Height = 400;						//Height of the rectangle container for graph.
		private ArrayList m_XAxis;						//X-axis for the graph.
		private ArrayList m_YAxis;						//Y-Axis for the graph.
		private Color m_graphColor = Color.Red;			//Color of the line graph.
		private float m_XSlice = 1;						//Slice for X Axis.
		private float m_YSlice = 1;						//Slice for Y Axis.
		private Graphics objGraphics;
		private Bitmap objBitmap;
		private string m_XAxisText = "X-Axis";
		private string m_YAxisText = "Y-Axis";
		private string m_Title = "Line Graph";
		private Color m_TitleBackColor = Color.Cyan;
		private Color m_TitleForeColor = Color.Green;
		
 
 
		//Sets or Gets the Width for the rectangle container of graph.
		public int Width
		{
			get { return m_Width;}
			set 
			{ 
				if ( value > 200)
					m_Width = value;
				//else
					//Width should be greater than 200.
			}
		}
 
		//Sets or Gets the Height for the rectangle container of graph.
		public int Height
		{
			get { return m_Height;}
			set 
			{ 
				if ( value > 200)
					m_Height = value;
				//else
					//Height should be greater than 200.
			}
		}
 
		//Sets or Gets the X-Axis pixels for the graph.
		public ArrayList XAxis
		{
			set 
			{ 
				m_XAxis = value;
			}
			get { return m_XAxis;}
		}
 
		//Sets or Gets the Y-Axis pixels for the graph.
		public ArrayList YAxis
		{
			set { m_YAxis = value;}
			get { return m_YAxis;}
		}
 
		//Sets or Gets the Color of the line Graph.
		public Color GraphColor
		{
			set { m_graphColor = value;}
			get { return m_graphColor;}
		}
 
 
		//Sets or Gets the X Axis Slice.
		public float XSlice
		{
			set { m_XSlice = value;}
			get { return m_XSlice;}
		}
 
		//Sets or Gets the Y Axis Slice.
		public float YSlice
		{
			set { m_YSlice = value;}
			get { return m_YSlice;}
		}
 
		//Sets or Gets the X-Axis Text.
		public string XAxisText
		{
			get { return m_XAxisText;}
			set { m_XAxisText = value;}
		}
 
		//Sets or Gets the Y-Axis Text.
		public string YAxisText
		{
			get { return m_YAxisText;}
			set { m_YAxisText = value;}
		}
 
		//Sets or Gets the title for the Graph.
		public string Title
		{
			get { return m_Title;}
			set { m_Title = value;}
		}
 
		//Sets or Gets the title Backcolor.
		public Color TitleBackColor
		{
			get { return m_TitleBackColor;}
			set { m_TitleBackColor = value;}
		}
 
		//Sets or Gets the Title ForeColor.
		public Color TitleForeColor
		{
			get { return m_TitleForeColor;}
			set { m_TitleForeColor = value;}
		}
 
		//Default constructor.
		public Line2D()
		{
			
		}
 
 
		/******************************************************************************************
		 * Method	:	Public InitializeGraph
		 * Purpose	:	Initialises the Graph.Draws rectangle region and fills the region.
		 *				Draws X-Axis line and Y-Axis line.
		 *				Draws Origin (0,0) point.Sets Axis Text and creates Title.
		 * *****************************************************************************************/
		public void InitializeGraph()
		{
			
			//Creating a bitmap image with given height and width.
			objBitmap = new Bitmap(Width,Height);
 
			//Getting the bitmap image into the graphics portion of the screen.
			objGraphics = Graphics.FromImage(objBitmap);
 
			//Filling the rectangle portion of the graphics with custom color.
			objGraphics.FillRectangle(new SolidBrush(Color.LightGray),0,0,Width,Height);
			
			//Drawing X-Axis line.
			objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black),2),100,Height - 100,Width - 100,Height - 100);
 
			//Drawing Y-Axis line.
			objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black),2),100,Height - 100,100,10);
 
			//Plotting Origin(0,0).
			objGraphics.DrawString("0",new Font("Courier New",10),new SolidBrush(Color.White),90,Height - 90);
 
			//Sets Axis text.
			SetAxisText(ref objGraphics);
 
			//Sets the title for the Graph.
			CreateTitle(ref objGraphics);
		}
 
		
		/******************************************************************************************
		 * Method	:	Public CreateGraph
		 * Purpose	:	Calls SetPixel function to draw line in the rectangle region.	
		 * Input	:	Color of the line Graph.
		 * *****************************************************************************************/
		public void CreateGraph(Color _GraphColor)
		{
			GraphColor = _GraphColor;
			//Plotting the pixels.
			SetPixels(ref objGraphics);
		}
 
		/******************************************************************************************
		 * Method	:	Public Draw2D.
		 * Purpose	:	Creates 2D graph for the given X and Y Axis.
		 * Returns	:	(Bitmap) reference of the graphics portions.
		 * *****************************************************************************************/
		public Bitmap GetGraph()
		{
							
			//Creating X-Axis slices.
			SetXAxis(ref objGraphics,XSlice);
			
			//Creating Y-Axis slices.
			SetYAxis(ref objGraphics,YSlice);
			
				
			return objBitmap;
		}
 
 
		
		
		/******************************************************************************************
		 * Method	:	Public PlotGraph.
		 * Purpose	:	Draws Axis Line.
		 * Input	:	Graphics object,X Axis, Y Axis for both points.
		 ******************************************************************************************/
		private void PlotGraph(ref Graphics objGraphics,float x1,float y1,float x2,float y2)
		{
			objGraphics.DrawLine(new Pen(new SolidBrush(GraphColor),2),x1 + 100, (Height - 100) - y1 ,x2 + 100,(Height - 100) - y2  );
		}
 
 
		/******************************************************************************************
		 * Method	:	Public SetXAxis.
		 * Purpose	:	Draws X-Axis Slices.
		 * Input	:	Graphics object, Slices for the XAxis.
		 ******************************************************************************************/
		private  void SetXAxis(ref Graphics objGraphics,float iSlices)
		{
			float x1 = 100,y1 = Height - 110,x2 = 100,y2 = Height - 90;
 
			int iCount = 0;
			int iSliceCount = 1;
 
			for(int iIndex = 0;iIndex <= Width - 200;iIndex += 10)
			{
 
				if(iCount == 5)
				{
					objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)),
						x1+iIndex,y1,x2+iIndex,y2);
					objGraphics.DrawString(Convert.ToString(iSlices * iSliceCount),new Font("verdana",8),new SolidBrush(Color.White),
						x1 + iIndex - 10,y2);
					iCount = 0;
					iSliceCount++;
 
				}
				else
				{
					objGraphics.DrawLine(new Pen(new SolidBrush(Color.Goldenrod)),
						x1+iIndex,y1+5,x2+iIndex,y2-5);
				}
				iCount++;
				
			}
 
		}
 
 
		/******************************************************************************************
		 * Method	:	Public SetYAxis.
		 * Purpose	:	Draws Y-Axis Slices.
		 * Input	:	Graphics object, Slices for the axis.
		 ******************************************************************************************/
		private void SetYAxis(ref Graphics objGraphics,float iSlices)
		{
			int x1 = 95; 
			int y1 = Height - 110;
			int x2 = 105;
			int y2 = Height - 110;
			int iCount = 1;
			int iSliceCount = 1;
 
			for(int iIndex = 0;iIndex<Height - 200;iIndex+=10)
			{
				if(iCount == 5)
				{
					objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)),
						x1 - 5, y1 - iIndex,x2 + 5,y2 - iIndex);
					objGraphics.DrawString(Convert.ToString(iSlices * iSliceCount),new Font("verdana",8),new SolidBrush(Color.White),
						60,y1 - iIndex );
					iCount = 0;
					iSliceCount++;
 
				}
				else
				{
					objGraphics.DrawLine(new Pen(new SolidBrush(Color.Goldenrod)),
						x1, (y1 - iIndex),x2,(y2 - iIndex));
				}
				iCount ++;
			}
 
		}
 
 
 
		/******************************************************************************************
		 * Method	:	Public SetPixels.
		 * Purpose	:	Plots pixels.
		 * Input	:	Graphics object.
		 ******************************************************************************************/
		private void SetPixels(ref Graphics objGraphics)
		{
			
			float X1 = float.Parse(XAxis[0].ToString());
			float Y1 = float.Parse(YAxis[0].ToString());
 
			if(XAxis.Count == YAxis.Count)
			{
		
				for(int iXaxis = 0,iYaxis =0;(iXaxis < XAxis.Count - 1 && iYaxis < YAxis.Count - 1);iXaxis++,iYaxis++)
				{
					PlotGraph(ref objGraphics,X1,Y1,float.Parse(XAxis[iXaxis + 1].ToString()),float.Parse(YAxis[iYaxis + 1].ToString()));
					X1 = float.Parse(XAxis[iXaxis + 1].ToString());
					Y1 = float.Parse(YAxis[iYaxis + 1].ToString());
 
				}
				
			}
			else
			{
				//X and Y axis length should be same.
			}
		}
 
 
		/******************************************************************************************
		 * Method	:	Private SetAxisText.
		 * Purpose	:	Sets the Axis text.
		 * Input	:	Graphics object.
		 ******************************************************************************************/
		private void SetAxisText(ref Graphics objGraphics)
		{
			objGraphics.DrawString(XAxisText,new Font("Courier New",10),new SolidBrush(Color.LimeGreen),
				Width / 2 - 50,Height - 50);
 
			int X = 30;
			int Y = (Height / 2 ) - 50;
			for(int iIndex = 0;iIndex < YAxisText.Length;iIndex++)
			{
				objGraphics.DrawString(YAxisText[iIndex].ToString(),new Font("Courier New",10),new SolidBrush(Color.LimeGreen),
					X,Y);
				Y += 10;
			}
 
		}
 
 
		/******************************************************************************************
		 * Method	:	Public CreateTitle.
		 * Purpose	:	Creates title for the graph.
		 * Input	:	Graphics object.
		 ******************************************************************************************/
		private void CreateTitle(ref Graphics objGraphics)
		{
			objGraphics.FillRectangle(new SolidBrush(TitleBackColor),Height - 100,20,Height - 200,20);
			Rectangle rect = new Rectangle(Height - 100,20,Height - 200,20);
			objGraphics.DrawString(Title,new Font("Verdana",10),new SolidBrush(TitleForeColor),rect);
			
		}
 
		
	}
}

Open in new window

Unavngivet.bmp
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
anarki_jimbelSenior Developer

Commented:
I would recommend you to split the question to a number of specific questions.

Second, you need to explain in more details what you problem is. And, e.g., what you program should do. Etc.
Also, thre are some comments in the Line2D class but not very extensive. The rest of code is not commented. It would be easier for experts (really, anyone dealing with your code) if code is commented better.

Good luck!
Commented:
Check the files.

quote:
"When I add a x,y I want it to show as a DOT (but still be painted out as it is know)" this part of the task is finished I guess.

I introduced a bool variable called dotmode, so that the original line functionality is not lost. (it would be better to create a property for dotmode later.)

next we have to fix the scaling.
Form1.cs.txt
Form1.Designer.cs.txt
Line2D.cs.txt

Author

Commented:
Thx. This helped me alot. I will open a new thread if I get stuck.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial