Treceți la conținutul principal

painter 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
    {
       public int modD = 0;
        public int x1, x2, y1, y2;
        public System.Drawing.Rectangle square = new Rectangle();
        public Pen pen0 = new Pen(Color.Black);
        public Brush brush0 = new SolidBrush(Color.Black);
        private Bitmap GraphicsImage;
        public int mouseisdown = 0;
        public int xx=0, yy=0;

        //variabile pentru animatie

        public int axx1 = 0, ayy1 = 0;
        public int axx2 = 0, ayy2 = 0;
        public int aN = 90;

        public int ai;
        //


        public Form1()
        {
            InitializeComponent();
            GraphicsImage = new Bitmap(DrawingPanel.Width, DrawingPanel.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
       
            Graphics.FromImage(GraphicsImage).Clear(Color.White);
        }

        
        private void ClearButton_Click(object sender, EventArgs e)
        {
            Graphics.FromImage(GraphicsImage).Clear(Color.White);
            DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
        }

       

        private void DrawingPanel_MouseUp(object sender, MouseEventArgs e)
        {

            mouseisdown = 0;
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
           

       
            square.X = x1;
            square.Y = y1;
            txty2.Text = y2.ToString();
            txtx2.Text = x2.ToString();
            square.Width = Math.Abs(x1-x2);
            square.Height = Math.Abs(y1-y2);
            txtw.Text = square.Width.ToString();
            txth.Text = square.Height.ToString();

          

            //numericUpDown1.Value = square.Height;
            
        }
        private void DrawingPanel_MouseMove(object sender, MouseEventArgs e)
        {

            x1 = e.X;
            y1 = e.Y;
            /////rigla///
            
            this.lineShape2.X1 = x1+this.DrawingPanel.Left;
            this.lineShape2.Y1 = this.DrawingPanel.Top;
            this.lineShape2.X2 = x1+this.DrawingPanel.Left;
            this.lineShape2.Y2 = this.DrawingPanel.Top-10;
            this.lineShape1.X1 = this.DrawingPanel.Left-10;
            this.lineShape1.Y1 = this.DrawingPanel.Top+y1;
            this.lineShape1.X2 = this.DrawingPanel.Left;
            this.lineShape1.Y2 = this.DrawingPanel.Top+y1;
            //end rigla///

            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
            
            txtx.Text = e.X.ToString();
            txty.Text = e.Y.ToString();
            if (e.Button == MouseButtons.Left) 
            {
               

               
                if (AACheckBox.Checked)
                {
                   
                    DrawingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                }
                switch (ShapeComboBox.SelectedIndex)
                {
                    case 0: 
                        DrawingGraphics.FillEllipse(new SolidBrush(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 1:
                        DrawingGraphics.DrawEllipse(new Pen(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 2: 
                        DrawingGraphics.FillRectangle(new SolidBrush(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 3: 
                        DrawingGraphics.DrawRectangle(new Pen(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                }
              
                DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
            }
            if (mouseisdown == 1)
            {
                if (modD == 100)//pen mode
                {
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), x1, y1, x2, y2);
                }
            }

            if (mouseisdown == 1)//brush draw mode
            {
                if (modD == 101)
                {

                    DrawingGraphics.FillEllipse(new SolidBrush(ColorButton.BackColor), x1 - (int)(numericUpDown1.Value / 2), y1 - (int)(numericUpDown1.Value/2), (int)numericUpDown1.Value, (int)numericUpDown1.Value);
                       
                }
            }
            x2 = x1;
            y2 = y1; 
     }

        private void DrawingPanel_MouseDown(object sender, MouseEventArgs e)
        {
            mouseisdown = 1;
            x1 = e.X;
            y1 = e.Y;
            txtx1.Text = x1.ToString();
            txty1.Text = y1.ToString();
            if (e.Button == MouseButtons.Left) {
                System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
                if (AACheckBox.Checked)
                {
                    DrawingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                 
                }
                switch (ShapeComboBox.SelectedIndex)
                {
                    case 0: 
                        DrawingGraphics.FillEllipse(new SolidBrush(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 1: 
                        DrawingGraphics.DrawEllipse(new Pen(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 2: 
                        DrawingGraphics.FillRectangle(new SolidBrush(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    case 3: 
                        DrawingGraphics.DrawRectangle(new Pen(ColorButton.BackColor), new Rectangle(Convert.ToInt32(e.X - numericUpDown1.Value / 2), Convert.ToInt32(e.Y - numericUpDown1.Value / 2), Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown1.Value)));
                        break;
                    
                        
                    
                }
               
                DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
            }
            
        }

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

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            GraphicsImage.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
       
        }

        private void ColorButton_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
           
            ColorButton.BackColor = colorDialog1.Color;
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);
            
            if (modD == 0){
                //default = 0
            }
            if (modD == 2)
            {
                //point
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx2.Text), Convert.ToInt16(txty2.Text));
 
            }
            if (modD == 1){
                //line
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx1.Text)-5, Convert.ToInt16(txty1.Text));
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text)-5);
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx1.Text) + 5, Convert.ToInt16(txty1.Text));
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text) + 5);
                
            }
            if (modD == 7){
                //patrulater
                DrawingGraphics.DrawRectangle(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtx2.Text), Convert.ToInt16(txty2.Text));
            }

            if (modD == 4)
            {
                //patrat
                DrawingGraphics.DrawRectangle(new Pen(ColorButton.BackColor), Convert.ToInt16(txtx1.Text), Convert.ToInt16(txty1.Text), Convert.ToInt16(txtw.Text), Convert.ToInt16(txth.Text));
            }

        }

        private void plottingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

           int xx1=0,yy1=0;
           int xx2=0,yy2=0;
           int N=90;
           int i;
            
                N = (Convert.ToInt16(txtNGon.Text));
           
            for(i = 0;i<=361;i+=N){
                    xx1 = (int)(Math.Cos(i/57.4)*100+100);
                    yy1 = (int)(Math.Sin(i/57.4)*100+100);
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor),xx1,yy1,xx2,yy2);
                    xx2 = xx1; yy2 = yy1;                        
                }


        }

        private void sinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

            int xx1 = 0, yy1 = 0;
            int xx2 = 0, yy2 = 0;
            int N = 90;
            int i;

            N = (Convert.ToInt16(txtNGon.Text));

            for (i = 0; i <= 361; i += N)
            {
                yy1 = (int)(Math.Sin(i / 57.4) * 100 + 100);
                xx1 = i;
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), xx1, yy1, xx2, yy2);
                xx2 = xx1; yy2 = yy1;
            }

        }

        private void cosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

            int xx1 = 0, yy1 = 0;
            int xx2 = 0, yy2 = 0;
            int N = 90;
            int i;

            N = (Convert.ToInt16(txtNGon.Text));

            for (i = 0; i <= 361; i += N)
            {
                yy1 = (int)(Math.Cos(i / 57.4) * 100 + 100);
                xx1 = i;
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), xx1, yy1, xx2, yy2);
                xx2 = xx1; yy2 = yy1;
            }
        }

        private void tanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

            int xx1 = 0, yy1 = 0;
            int xx2 = 0, yy2 = 0;
            int N = 90;
            int i;

            N = (Convert.ToInt16(txtNGon.Text));

            for (i = 0; i <= 361; i += N)
            {
                yy1 = (int)(Math.Tan(i / 57.4) * 100 + 100);
                xx1 = i;
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), xx1, yy1, xx2, yy2);
                xx2 = xx1; yy2 = yy1;
            }
        }

        
        private void animationToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            modD = 1000;
            aN = (Convert.ToInt16(txtNGon.Text));
            ai = 0;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            this.DrawingPanel.Refresh();

            if (modD == 1000) {
                //animation
                if (ai <= 361)
                {
                    System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);


                    ayy1 = (int)(Math.Cos(ai / 57.4) * 100 + 100);
                    axx1 = (int)(Math.Sin(ai / 57.4) * 100 + 100);
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), axx1, ayy1, axx2, ayy2);
                    axx2 = axx1; ayy2 = ayy1;
                    ai++;
                   
                }
                if (ai >= 362)
                {
                    if (loopAnim.Checked == true) { ai = 0; }
                }
            }

            if (modD == 1001)
            {
                //animation sinus
                if (ai <= 361)
                {
                    System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);


                    ayy1 = (int)(Math.Sin(ai / 57.4) * 100 + 100);
                    axx1 = ai;
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), axx1, ayy1, axx2, ayy2);
                    axx2 = axx1; ayy2 = ayy1;
                    ai++;

                }
                if (ai >= 362)
                {
                    if (loopAnim.Checked == true) { ai = 0; }
                }
            }

            if (modD == 1002)
            {
                //animation cosinus
                if (ai <= 361)
                {
                    System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);


                    ayy1 = (int)(Math.Cos(ai / 57.4) * 100 + 100);
                    axx1 = ai;
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), axx1, ayy1, axx2, ayy2);
                    axx2 = axx1; ayy2 = ayy1;
                    ai++;

                }
                if (ai >= 362)
                {
                    if (loopAnim.Checked == true) { ai = 0; }
                }
            }

            if (modD == 1003)
            {
                //animation tangenta
                if (ai <= 361)
                {
                    System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);


                    ayy1 = (int)(Math.Tan(ai / 57.4) * 100 + 100);
                    axx1 = ai;
                    DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), axx1, ayy1, axx2, ayy2);
                    axx2 = axx1; ayy2 = ayy1;
                    ai++;

                }
                if (ai >= 362)
                {
                    if (loopAnim.Checked == true) { ai = 0; }
                }
            }


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.DrawingPanel.Refresh();
            this.ShapeComboBox.SelectedIndex = 4;

        }

        private void circleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

            int xx1 = 0, yy1 = 0;
            int xx2 = 0, yy2 = 0;
            int N = 0;
           //txtNGon.Text = N.ToString();
            int i;

            N = (Convert.ToInt16(txtNGon.Text));

            for (i = 0; i <= 361; i += N)
            {
                yy1 = (int)(Math.Sin(i / 57.324) * 100 + (Convert.ToInt16(txty1.Text)));
                xx1 = (int)(Math.Cos(i / 57.324) * 100 + (Convert.ToInt16(txtx1.Text)));
                DrawingGraphics.DrawLine(new Pen(ColorButton.BackColor), xx1, yy1, xx2, yy2);
                xx2 = xx1; yy2 = yy1;
            }
        }

        private void Form_Activate(object sender, EventArgs e)
        {
            this.DrawingPanel.Refresh();
        }

        private void DrawingPanel_Click(object sender, EventArgs e)
        {
            button2_Click(sender, e);
        }

        private void pointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 1; // point

        }

        private void squareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 4; // square
        }

        private void patrulaterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 7; // patrulater
        }

        private void lineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 2; // line
        }

        private void penToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 100;//pen
        }

        private void animToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 1001;//anim sinus

            aN = (Convert.ToInt16(txtNGon.Text));
            ai = 0;
        }

        private void animToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            modD = 1002;//anim cosinus

            aN = (Convert.ToInt16(txtNGon.Text));
            ai = 0;
        }

        private void animToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            modD = 1003;//anim tangenta

            aN = (Convert.ToInt16(txtNGon.Text));
            ai = 0;
        }

        private void drawToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modD = 101;//draw free
        }




    }
}

Comentarii

Postări populare de pe acest blog

WINDOWS 10 COMPUTER FREEZING PROBLEM SOLVED

good news : a BIOS UPDATE can resolve the problem but just for a Windows 7 on 64 bits o.s. and the system is not stable all the time. even after  bios update the system can freeze.
new info : u can try to low the screen brightness and see if this error appear so often after 
news: last info !!! maybe a virus. scann our system now with an antivirus i generate this error using other device ( a tablet pc) connected in the same network and the laptop i have this problem just freeze  http://thehackernews.com/2013/10/backdoor-found-in-chinese-tenda.html

news : if u use a tenda router this make couse all this problems



what i discover so far :
1.the electric company have many failure and affect the main ISP router/switch for building  also the router/switch installed by the ISP may be affected by overheating and will crash after a long utilisation on heat conditions 2.the router/switch of ISP affect any router of the user between this router and pc/laptop of client 3.the router and any other device of t…

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='+'…

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…