[[kresleni]]
 

na zacatek tridy

        Pen p;
        Brush b;

na konec konstruktoru

        p = new Pen (panel1.BackColor);
        b = new SolidBrush (panel1.BackColor);

na konec newColorMenuItem_Click

        p = new Pen(t.BackColor);

upravit pictureBox_MouseMove

                /*
                Brush b = new LinearGradientBrush(new Point(0, 0),
                                                  new Point(100, 100),
                                                  Color.Red,
                                                  Color.Blue);
                */
                g.FillEllipse (b, X0, Y0, X1 - X0, Y1 - Y0);
                g.DrawEllipse (p, X0, Y0, X1 - X0, Y1 - Y0);

upravit panel1_MouseDown

              colorDialog1.Color = t.BackColor;
              if (colorDialog1.ShowDialog() == DialogResult.OK)
              {
                  t.BackColor = colorDialog1.Color;
                  p = new Pen(t.BackColor);
              }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace kresleni
{
    public partial class MyWindow : Form
    {
        int X0, Y0;
        bool s = false;
        Bitmap save = null;
        Pen p;
        Brush b;
        int cnt = 1;
 
        public MyWindow()
        {
            InitializeComponent();
            pictureBox_SizeChanged(null, null);
            p = new Pen (panel1.BackColor);
            b = new SolidBrush (panel1.BackColor);
        }
 
        private void newColorMenuItem_Click(object sender, EventArgs e)
        {
            Panel t = new Panel();
            t.Parent = toolPanel;
            // toolPanel.Controls.Add (t);
            t.BackColor = Color.CornflowerBlue;
 
            cnt++;
            t.Left = cnt * panel1.Left + (cnt - 1) * panel1.Width;
            t.Top = panel1.Top;
            t.Width = panel1.Width;
            t.Height = panel1.Height;
 
            t.MouseDown += panel1_MouseDown;
 
            p = new Pen(t.BackColor);
        }
 
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            Control t = (Control) sender;
            if (e.Button == MouseButtons.Middle)
            {
              colorDialog1.Color = t.BackColor;
              if (colorDialog1.ShowDialog() == DialogResult.OK)
              {
                  t.BackColor = colorDialog1.Color;
                  p = new Pen(t.BackColor);
              }
            }
            else if (e.Button == MouseButtons.Left)
            {
                p = new Pen (t.BackColor);
            }
            else if (e.Button == MouseButtons.Right)
            {
                b = new SolidBrush (t.BackColor);
            }
        }
 
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            X0 = e.X;
            Y0 = e.Y;
            s = true;
            save = new Bitmap (pictureBox.Image);
        }
 
        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (s)
            {
                Graphics g = Graphics.FromImage(pictureBox.Image);
                g.DrawImage (save, 0, 0);
                // Pen p = new Pen(Color.Red);
                // g.DrawLine(p, X0, Y0, e.X, e.Y);
 
                int X1 = e.X;
                int Y1 = e.Y;
                if (X1 < X0) { int t = X0; X0 = X1; X1 = t; }
                if (Y1 < Y0) { int t = Y0; Y0 = Y1; Y1 = t; }
                /*
                Brush b = new LinearGradientBrush(new Point(0, 0),
                                                  new Point(100, 100),
                                                  Color.Red,
                                                  Color.Blue);
                */
                g.FillEllipse (b, X0, Y0, X1 - X0, Y1 - Y0);
                g.DrawEllipse (p, X0, Y0, X1 - X0, Y1 - Y0);
                pictureBox.Invalidate();
            }
        }
 
        private void pictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            s = false;
            /*
            int X1 = e.X;
            int Y1 = e.Y;
            if (X1 < X0) { int t = X0; X0 = X1; X1 = t; }
            if (Y1 < Y0) { int t = Y0; Y0 = Y1; Y1 = t; }
            // g.DrawRectangle(p, X0, Y0, X1 - X0, Y1 - Y0);
 
            // using System.Drawing.Drawing2D;
            Brush b = new SolidBrush(Color.Yellow);
            b = new HatchBrush(HatchStyle.Cross,
                               Color.Blue,
                               Color.Yellow);
            b = new LinearGradientBrush (new Point(0, 0),
                                         new Point(100, 100),
                                         Color.Red,
                                         Color.Blue);
            g.FillEllipse (b, X0, Y0, X1 - X0, Y1 - Y0);
            g.DrawEllipse (p, X0, Y0, X1 - X0, Y1 - Y0);
            */
 
        }
 
        private void pictureBox_SizeChanged(object sender, EventArgs e)
        {
            int w = pictureBox.Width;
            int h = pictureBox.Height;
 
            Image old = pictureBox.Image;
            int w0 = (old == null) ? 0 : old.Width;
            int h0 = 0;
            if (old != null) h0 = old.Width;
 
            w = Math.Max(w, w0);
            h = Math.Max(h, h0);
 
            pictureBox.Image = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(pictureBox.Image);
            Brush b = new SolidBrush(Color.White);
            g.FillRectangle(b, 0, 0, w, h);
            if (old != null)
                g.DrawImage(old, 0, 0);
        }
 
        private void exitMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
 
    }
}
 
kresleni.txt · Last modified: 2013/10/22 13:12 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki