Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Edward_Zhao1-May-13 14:33
professionalEdward_Zhao1-May-13 14:33 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan1-May-13 21:02
mveRichard MacCutchan1-May-13 21:02 
QuestionSaving DrawLine to Image: SOLVED Pin
Member 792126830-Apr-13 3:34
Member 792126830-Apr-13 3:34 
AnswerRe: Saving DrawLine to Image Pin
Eddy Vluggen30-Apr-13 4:05
professionalEddy Vluggen30-Apr-13 4:05 
GeneralRe: Saving DrawLine to Image Pin
Member 792126830-Apr-13 5:11
Member 792126830-Apr-13 5:11 
AnswerRe: Saving DrawLine to Image Pin
Kenneth Haugland30-Apr-13 4:42
mvaKenneth Haugland30-Apr-13 4:42 
GeneralRe: Saving DrawLine to Image Pin
Member 79212681-May-13 0:46
Member 79212681-May-13 0:46 
AnswerRe: Saving DrawLine to Image: SOLVED Pin
Member 79212681-May-13 4:39
Member 79212681-May-13 4:39 
Member 7921268 wrote:
Thanks in advance to those who want to give me a tip.


Solved!, thanks all

Working release:

C#
using System.Collections.Generic;
using System.Text;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        bool flgDraw = false;

        Pen redPen;
        Pen blackPen1;
        Pen blackPen2;
        Pen orangePen;

        Bitmap drawing;
        GraphicsPath path = new GraphicsPath();

        private List<Point> polygonPoints = new List<Point>();

        public Form1()
        {
            InitializeComponent();

            redPen = new Pen(Color.Red, 2);
            blackPen1 = new Pen(Color.Black, 1);
            blackPen2 = new Pen(Color.Black, 2);
            orangePen = new Pen(Color.Orange, 1);

            panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
            panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
            panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
            panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
            
            Shown += Form1_Shown;

            drawing = new Bitmap(panel1.Width, panel1.Height, panel1.CreateGraphics());
            Graphics.FromImage(drawing).Clear(Color.White);
        }

        private void Form1_Shown(Object sender, EventArgs e)
        {
            Grid(); // draw grid
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (flgDraw)
            {
                Graphics Gpanel = Graphics.FromImage(drawing);
                panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
            }
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            flgDraw = true;

            Graphics Gpanel = Graphics.FromImage(drawing);

            switch (e.Button)
            {
                // left button, add line to path
                case MouseButtons.Left:
                    polygonPoints.Add(new Point(e.X, e.Y));

                    if (polygonPoints.Count > 1)
                    {
                        path.AddLine(polygonPoints[polygonPoints.Count - 2], polygonPoints[polygonPoints.Count - 1]);
                        
                        // draw segment
                        Gpanel.DrawPath(redPen, path);
                    }
                    
                    break;

                // right button, redraw shape from path and fill it
                case MouseButtons.Right:
                    if (polygonPoints.Count > 2)
                    {
                        path.CloseAllFigures();

                        Gpanel.DrawPath(redPen, path);
                        Gpanel.FillPath(new SolidBrush(Color.Orange), path);
                    }
                    break;
            }
            
            panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            flgDraw = false;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImageUnscaled(drawing, new Point(0, 0));
        }

        // draw grid every 10 pixel
        private void Grid()
        {
            Graphics Gpanel = Graphics.FromImage(drawing);

            for (int i = 0; i < panel1.Width; i += 10)
                Gpanel.DrawLine(blackPen1, i, panel1.Height, i, 0);

            for (int i = 0; i < panel1.Height; i += 10)
                Gpanel.DrawLine(blackPen1, 0, i, panel1.Width, i);

            Gpanel.DrawLine(blackPen2, 0, panel1.Height - 90, panel1.Width, panel1.Height - 90);

            panel1.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
        }

        // save image       
        private void btnSave_Click(object sender, EventArgs e)
        {
            drawing.Save("c:\\test.png", ImageFormat.Png);
        }
    }
}

QuestionThe performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 3:30
Rob Philpott30-Apr-13 3:30 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 4:01
professionalEddy Vluggen30-Apr-13 4:01 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:31
Rob Philpott30-Apr-13 4:31 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 8:33
harold aptroot30-Apr-13 8:33 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 8:44
Rob Philpott30-Apr-13 8:44 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 8:54
harold aptroot30-Apr-13 8:54 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 9:42
professionalEddy Vluggen30-Apr-13 9:42 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 4:03
Simon_Whale30-Apr-13 4:03 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:24
Rob Philpott30-Apr-13 4:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 4:46
Simon_Whale30-Apr-13 4:46 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:57
Rob Philpott30-Apr-13 4:57 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 5:32
Simon_Whale30-Apr-13 5:32 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Freak3030-Apr-13 4:36
Freak3030-Apr-13 4:36 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Dave Kreskowiak30-Apr-13 5:17
mveDave Kreskowiak30-Apr-13 5:17 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Pete O'Hanlon30-Apr-13 6:38
mvePete O'Hanlon30-Apr-13 6:38 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 6:49
Rob Philpott30-Apr-13 6:49 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 23:41
Simon_Whale30-Apr-13 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.