9 Nisan 2013 Salı

C Sharp Uygulamalar Mouse ile Çizgi ve Nokta Çizme



KONU : C Sharp Uygulamalar - C Sharp ( C# ) Form Uygulamalar farenin sol butonu ile çizgi çizme veya nokta çizme





UYGULAMAYI İNDİR

using System;
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.Drawing2D;

namespace MouseGrafikCizme
{
    public partial class Form1 : Form
    {

        Graphics graphic;
        private enum FormatEnum
        {
            Nokta = 0, Çizgi
        }

        FormatEnum lineFormat;

        bool draw = false;

        int pOldX = -1;
        int pOldY = -1;

        Bitmap drawing;

        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (draw)
            {
                Graphics panel = Graphics.FromImage(drawing);

                Pen pen = new Pen(Color.Blue, 5);

                pen.EndCap = LineCap.Round;

                pen.StartCap = LineCap.Round;


                switch (lineFormat)
                {
                    case FormatEnum.Nokta:

                        panel.DrawLine(pen, e.X, e.Y, e.X+1, e.Y+1);

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

                        break;

                    case FormatEnum.Çizgi:
                        
                        panel.DrawLine(pen, pOldX, pOldY, e.X, e.Y);

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

                        break;
                    default:
                        break;
                }
            }

            pOldX = e.X;

            pOldY = e.Y;
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            // Eğer mouse sol butona basılmaya başlanmışsa çizmeye başla

            draw = true; 

            pOldX = e.X;

            pOldY = e.Y;
        }

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

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

        private void btnNokta_Click(object sender, EventArgs e)
        {
            lineFormat = FormatEnum.Nokta;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            lineFormat = FormatEnum.Nokta;

            drawing = new Bitmap(panel1.Width, panel1.Height, panel1.CreateGraphics());

            Graphics.FromImage(drawing).Clear(Color.White);

        }

        private void btnCizgi_Click(object sender, EventArgs e)
        {
            lineFormat = FormatEnum.Çizgi;
        }

 
    }
}


UYGULAMAYI İNDİR

Hiç yorum yok :

Yorum Gönder