Treceți la conținutul principal

paint cs

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;

namespace Paint
{
    public partial class Form1 : Form
    {
        //start init Globals
        private Bitmap GraphicsImage;
        Color frontcolor;
        Color backcolor;
        int eX, eY, eX2, eY2,eXC1,eYC1;
        int mode;
        int ToolPaint;
        int isMouseDown;
        Color CurrentPixel;
        int inputedData;
        //*end init Globals

        public Form1()
        {

            
            InitializeComponent();
           
            GraphicsImage = new Bitmap(DrawingPanel.Width, DrawingPanel.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
       
            Graphics.FromImage(GraphicsImage).Clear(Color.White);
        
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            mode = 600;
            this.Left = 0;
            this.Top = 0;

            this.DrawingPanel.MouseMove += new MouseEventHandler(DrawingPanel_MouseMove);
            this.DrawingPanel.MouseDown += new MouseEventHandler(DrawingPanel_MouseDown);
            this.DrawingPanel.MouseUp += new MouseEventHandler(DrawingPanel_MouseUp);

            this.pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
            this.pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
            
            frontcolor = System.Drawing.Color.Black;
            backcolor=System.Drawing.Color.Red;
            ToolPaint = 0;
            isMouseDown = 0;
            inputedData = 0;
        }
        private void DrawingAForm() {
            /*try
            {*/
                System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
           /* }
            catch (Exception)
            {
                throw new ApplicationException("Error DrawingAForm Function , Indexed Image error");
            }*/
            
        if (AACheckBox.Checked)
        {
            //AntiAliasing is to be used
            DrawingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        }
            switch (ToolPaint)
            {
                case 0:
                    break;
                case 1: //draw an open circle
                    DrawingGraphics.DrawEllipse(new Pen(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                    break;
                case 2: //draw a filled square
                    DrawingGraphics.FillRectangle(new SolidBrush(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                    break;
                case 3: //draw an open square
                    DrawingGraphics.DrawRectangle(new Pen(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                    break;
                case 4: //draw a filled circle
                    DrawingGraphics.FillEllipse(new SolidBrush(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                    break;
                case 5://point
                     Pen myPen = new Pen(frontcolor, 1);

                    myPen.Color = frontcolor;
                    myPen.Width = 1;

                     DrawingGraphics.DrawLine(myPen, eX + 5, eY, eX, eY + 5);
                    DrawingGraphics.DrawLine(myPen, eX, eY, eX + 5, eY + 5);
                    break;
                /*case 6://point
                    Punct.xyPoint PunctXY;
                    PunctXY = new Punct.xyPoint();
                    PunctXY.Left = eX;
                    PunctXY.Top = eY;
                    PunctXY.BackColor = Color.Black;
                    PunctXY.Width = 10;
                    PunctXY.Height = 10;
                    this.Controls.Add(PunctXY);
                    break;*/
                default:
                    break;
            }


            DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
        
        }
        private void GetMousePosition(){
            this.Text = "Paint " + Convert.ToString(eX);
            this.Text += " : ";
            this.Text += Convert.ToString(eY);
            this.txtPosX.Text = Convert.ToString(eX);
            this.txtPosY.Text = Convert.ToString(eY);
        }
        private void DrawingPanel_MouseDown(object sender, MouseEventArgs e)
        {
            
            eX2 = e.X;
            eY2 = e.Y;
            GetMousePosition();
            DrawingAForm();
            isMouseDown = 1;
            txtColorHex.Text = (GraphicsImage.GetPixel(eX, eY)).ToString();
            CurrentPixel = GraphicsImage.GetPixel(eX, eY);
            this.pbColorPixelSet.BackColor = CurrentPixel;
        }
        private void DrawingPanel_MouseMove(object sender, MouseEventArgs e)
        {
            GetMousePosition();
            if(e.X>0 && e.Y>0 && e.X<599 && e.Y<599){
            eX = e.X;
            eY = e.Y;
            if (isMouseDown==1)
            {
                GetMousePosition();
                DrawingAForm();
            }
            if (eX > GraphicsImage.Height || eY > GraphicsImage.Width)
            {
                
            }
            else
            {
                txtColorHex.Text = (GraphicsImage.GetPixel(eX, eY)).ToString();
            
            
            CurrentPixel = GraphicsImage.GetPixel(eX, eY);
            this.pbColorPixel.BackColor = CurrentPixel;
           } 
            }

        }
        private void DrawingPanel_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = 0;
        }
        private void DrawingPanel_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImageUnscaled(GraphicsImage, new Point(0, 0));

         }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {ResetToolsColors();
        //circle nonfiled
            if (ToolPaint != 1)
            {
                ToolPaint = 1;
                
                this.button1.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button1.BackColor = Color.Red;
            }

        }
        private void button2_Click(object sender, EventArgs e)
        { ResetToolsColors();
            //filled rectangle
            if (ToolPaint != 2)
            {
                ToolPaint = 2;
               
                this.button2.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button2.BackColor = Color.Red;
            }
            
        }
        private void button3_Click(object sender, EventArgs e)
        {ResetToolsColors();
            //nonfilled rectangle
            if (ToolPaint != 3)
            {
                ToolPaint = 3;
                
                this.button3.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button3.BackColor = Color.Red;
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            ResetToolsColors();
            //filled circle
            if (ToolPaint != 4)
            {
                ToolPaint = 4;
                
                this.button4.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button4.BackColor = Color.Red;
            }
        }
        private void ResetToolsColors() {
            this.button1.BackColor = Color.Red;
            this.button2.BackColor = Color.Red;
            this.button3.BackColor = Color.Red;
            this.button4.BackColor = Color.Red;
            this.button5.BackColor = Color.Red;
        }
        private void label3_Click(object sender, EventArgs e)
        {

        }
        private void button5_Click(object sender, EventArgs e)
        {
            ResetToolsColors();
            //filled circle
            if (ToolPaint != 5)
            {
                ToolPaint = 5;

                this.button5.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button5.BackColor = Color.Red;
            }
        }
        private void pbColorBack_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            this.backcolor = colorDialog1.Color;
            pbColorBack.BackColor = this.backcolor;
        }
        private void pbColorFront_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            this.frontcolor = colorDialog1.Color;
            pbColorFront.BackColor = this.frontcolor;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            //Fills the image with white
            Graphics.FromImage(GraphicsImage).Clear(Color.White);
            //Draw the GraphicsImage onto the DrawingPanel
            DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
        }
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
            saveFileDialog1.ShowDialog();
            GraphicsImage.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
            }
            catch (Exception)
            {
                throw new ApplicationException("Failed Saving image");
            }

        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            
            try
            {

                openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Bitmap bit = new Bitmap(openFileDialog1.FileName);
                    if (bit.Width != 600) { MessageBox.Show("Error! Width dimension not right! Open a 600x600 file image please!"); }
                    if (bit.Height != 600) { MessageBox.Show("Error!Height dimension not right! Open a 600x600 file image please!"); }
                    GraphicsImage = (Bitmap)Image.FromFile(openFileDialog1.FileName, true);
                    MessageBox.Show(Convert.ToString(GraphicsImage.Height) +":" +Convert.ToString(GraphicsImage.Height));
                    DrawingPanel.CreateGraphics().DrawImageUnscaled(bit, new Point(0, 0));
       
                     
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Failed loading image");
            }
        }
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
            if (e.X > 0 && e.Y > 0 && e.X < 254 && e.Y < 254)
            {
                eXC1 = e.X;
                eYC1 = e.Y;

                txtColorHex.Text = ((pictureBox1.Image as Bitmap).GetPixel(eXC1, eYC1)).ToString();
                CurrentPixel = ((pictureBox1.Image as Bitmap).GetPixel(eXC1, eYC1));
                this.pbColorPixel.BackColor = CurrentPixel;
            }
           
        }
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            
            eXC1 = e.X;
            eYC1 = e.Y;

            txtColorHex.Text = ((pictureBox1.Image as Bitmap).GetPixel(eXC1,eYC1)).ToString();
            CurrentPixel = ((pictureBox1.Image as Bitmap).GetPixel(eXC1, eYC1));
            
            this.pbColorPixelSet.BackColor = CurrentPixel;
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        private void pbColorPixelSet_Click(object sender, EventArgs e)
        {
            pbColorBack.BackColor = this.pbColorPixelSet.BackColor;
            this.backcolor = pbColorBack.BackColor;
        }


        private void DrawingAFormCMD()
        {
            
            eX = Convert.ToInt32(this.txtPosX.Text);
            eY = Convert.ToInt32(this.txtPosY.Text);
            eX2 = Convert.ToInt32(this.txtPosX2.Text);
            eY2 = Convert.ToInt32(this.txtPosY2.Text);
            if (eX > 599) { eX = 599; }
            if (eX < 1) { eX = 1; }
            if (eY > 599) { eY = 599; }
            if (eY < 1) { eY = 1; }

            if (eX2 > 599) { eX2 = 599; }
            if (eX2 < 1) { eX2 = 1; }
            if (eY2 > 599) { eY2 = 599; }
            if (eY2 < 1) { eY2 = 1; }

            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
            if (AACheckBox.Checked)
            {
                //AntiAliasing is to be used
                DrawingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }
            switch (ToolPaint)
            {
                case 0:
                    MessageBox.Show("ToolBox not selected");
                    break;
                case 1: //draw an open circle
                    if (inputedData==1)
                    {
                        DrawingGraphics.DrawEllipse(new Pen(backcolor), new Rectangle(eX, eY, eX2, eY2));

                    }
                    else
                    {
                        DrawingGraphics.DrawEllipse(new Pen(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        //MessageBox.Show("traced");
                    }
                    break;
                case 2: //draw a filled square
                    if (inputedData == 1)
                    {
                        DrawingGraphics.FillRectangle(new SolidBrush(backcolor), new Rectangle(eX,eY,eX2,eY2));

                    }
                    else
                    {
                        DrawingGraphics.FillRectangle(new SolidBrush(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        //MessageBox.Show("traced");
                    }
                    break;
                case 3: //draw an open square
                    if (inputedData == 1)
                    {
                        DrawingGraphics.DrawRectangle(new Pen(backcolor), new Rectangle(eX,eY,eX2,eY2));

                    }
                    else
                    {
                        DrawingGraphics.DrawRectangle(new Pen(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        //MessageBox.Show("traced");
                    }
                    break;
                case 4: //draw a filled circle
                    if (inputedData == 1)
                    {
                        DrawingGraphics.FillEllipse(new SolidBrush(backcolor), new Rectangle(eX, eY, eX2, eY2));

                    }
                    else
                    {
                        DrawingGraphics.FillEllipse(new SolidBrush(backcolor), new Rectangle(Convert.ToInt32(eX - numericUpDown1.Value / 2), Convert.ToInt32(eY - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        //MessageBox.Show("traced");
                    }
                    break;
                case 5://point
                    if (inputedData == 1)
                    {
                        Pen myPen = new Pen(frontcolor, 1);

                        myPen.Color = frontcolor;
                        myPen.Width = 1;

                        DrawingGraphics.DrawLine(myPen, eX + 5, eY, eX, eY + 5);
                        DrawingGraphics.DrawLine(myPen, eX, eY, eX + 5, eY + 5);
                    }
                    else
                    {
                        //MessageBox.Show("traced");
                    
                    Pen myPen = new Pen(frontcolor, 1);

                    myPen.Color = frontcolor;
                    myPen.Width = 1;

                    DrawingGraphics.DrawLine(myPen, eX + 5, eY, eX, eY + 5);
                    DrawingGraphics.DrawLine(myPen, eX, eY, eX + 5, eY + 5);
                    }

                    break;

            }


            DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));

        }

        private void button7_Click(object sender, EventArgs e)
        {
            DrawingAFormCMD();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            /*ResetToolsColors();
            //filled circle
            if (ToolPaint != 6)
            {
                ToolPaint = 6;

                this.button8.BackColor = Color.Blue;
            }
            else
            {
                ToolPaint = 0;
                this.button8.BackColor = Color.Red;
            }*/
        }

        private void xyPoint1_Click(object sender, EventArgs e)
        {

        }

        private void ckX2Y2_CheckedChanged(object sender, EventArgs e)
        {
            if (!ckX2Y2.Checked) { inputedData = 0; }
            else
            {
                inputedData = 1; 
            }
            
        }
        
   }

  }

Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…