Hi,

I need to draw lines on a web application using Visual Studio 2008 C#. But i could only find drawing lines on a windows application. :sad: Can i convert the codes from windows application to a web application? Below is the code for windows application. I need guidances. Thanks!

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;

namespace nmLineRectangle
{
    public class clsLineRectangle
    {
        Rectangle SelectRect = new Rectangle();
        Point ps = new Point();
        Point pe = new Point();

        public clsLineRectangle()
        {

        }

        public void clsLineRectangle_OnMouseDown(Object sender, MouseEventArgs e)
        {
            SelectRect.Width = 0;
            SelectRect.Height = 0;
            SelectRect.X = e.X;
            SelectRect.Y = e.Y;

            ps.X = e.X;
            ps.Y = e.Y;
            pe = ps;
        }

        public void clsLineRectangle_OnMouseMove(Object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Form thisform = (Form)sender;

                // First DrawReversible to toggle to the background color
                // Second DrawReversible to toggle to the specified color
                if (((RadioButton)thisform.Controls[0]).Checked)
                {
                    ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
                    pe = new Point(e.X, e.Y);
                    ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
                }
                else
                {
                    ControlPaint.DrawReversibleFrame(thisform.RectangleToScreen(SelectRect), Color.Black, FrameStyle.Dashed);
                    SelectRect.Width = e.X - SelectRect.X;
                    SelectRect.Height = e.Y - SelectRect.Y;
                    ControlPaint.DrawReversibleFrame(thisform.RectangleToScreen(SelectRect), Color.Black, FrameStyle.Dashed);
                }
            }
        }

        public void clsLineRectangle_OnMouseUp(Object sender, MouseEventArgs e)
        {
            Form thisform = (Form)sender;
            Graphics g = thisform.CreateGraphics();
            Pen p = new Pen(Color.Blue, 2);
            if (((RadioButton)thisform.Controls[0]).Checked)
            {
                ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
                g.DrawLine(p, ps, pe);
            }
            else
            {
                ControlPaint.DrawReversibleFrame(thisform.RectangleToScreen(SelectRect), Color.Black, FrameStyle.Dashed);
                g.DrawRectangle(p, SelectRect);
            }
            g.Dispose();
        }
    }

    public class Form1 : System.Windows.Forms.Form
    {
        private RadioButton rdoLine;
        private RadioButton rdoRect;

        [STAThread]
        public static void Main()
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            clsLineRectangle im = new clsLineRectangle();
            this.MouseDown += new MouseEventHandler(im.clsLineRectangle_OnMouseDown);
            this.MouseMove += new MouseEventHandler(im.clsLineRectangle_OnMouseMove);
            this.MouseUp += new MouseEventHandler(im.clsLineRectangle_OnMouseUp);

            rdoLine = new RadioButton();
            rdoLine.Name = "rdoLine";
            rdoLine.Location = new Point(10, 10);
            rdoLine.Text = "Line";

            rdoRect = new RadioButton();
            rdoRect.Name = "rdoRect";
            rdoRect.Location = new Point(10, 40);
            rdoRect.Text = "Rectangle";

            this.Controls.AddRange(new Control[] { rdoLine, rdoRect });
        }

        private void rdo_OnClick(Object sender, EventArgs e)
        {
            if (rdoLine.Checked)
            {
                rdoRect.Checked = true;
                rdoLine.Checked = false;
            }
            else
            {
                rdoRect.Checked = false;
                rdoLine.Checked = true;
            }
        }
    }
}
namespace LineAndRect
{
    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()
        {
            this.components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Text = "Form1";
        }

        #endregion
    }
}

i want to draw a verticalline in asp.net 2008 at masterpage

Next time, create a new thread, instead of replying to a 6 year old thread.

Add a div (or other container to your page) and set the left or right border with CSS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.