» »

c#, free hand risanje

c#, free hand risanje

japol ::

Pri mouse move imam kodo:

if (e.Button == MouseButtons.Left)
{
int mouseX = e.X;
int mouseY = e.Y;
mousepath.AddLine (mouse.X, mouse.Y,mouse.X, mouse.Y);

System.Drawing.Graphics formgraphics20;
formgraphics20 = this.CreateGraphics();
Pen p = new Pen (panel1.BackColor, deb);
formgraphisc20.DrawPath(p, mousepath);
}
}


seveda je mousepath že pred tem določen z
mousepath = new System......
in
private System...... mousepath;

S to kodo rišeš prosto na form, dela, ampak ko hočeš risati 2 "čački" ali več, te "čačke" poveže med sabo - in tega bi se rad rešil.
nekaj podobno temu iščem:
http://www.codeproject.com/KB/GDI-plus/...
http://www.java2s.com/Code/CSharp/2D-Gr...

a pa še nekaj: rišeš na form in ko ga miniziraš in nato maksimiziraš ni več slik na formu, kako to rešit? Hvala

japol ::

Še en primer (sestavljen iz drugega linka):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
// 1. 
using System.Data;
using System.Drawing.Drawing2D;

namespace Risanje_z_MISKO_freehand_risanje
{
    public partial class Form1 : Form
    {
        // 2.
        private Point[] thePoints;
        private int counter;
        
        public Form1()
        {
            InitializeComponent();
            // 3.
            thePoints = new Point[1000]; 
            for (int i = 0; i < thePoints.Length; i++)
                thePoints[i] = new Point(0, 0);
            counter = 0;
        }
        // 4.
        protected override void OnPaint(PaintEventArgs e)
        {
            if (counter == 0)
                return;

            Pen greenPen = new Pen(Color.Red, 4);
            Point[] curvePoints = new Point[counter];

            for (int i = 0; i < curvePoints.Length; i++)
            {
                curvePoints[i] = new Point(0, 0);
                curvePoints[i].X = thePoints[i].X;
                curvePoints[i].Y = thePoints[i].Y;
            }
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.DrawCurve(greenPen, curvePoints);
        }
        //5.
        protected override void OnLoad(System.EventArgs e)
        {
            MouseMove += new MouseEventHandler(Form1_MouseMove);
            MouseUp += new MouseEventHandler(Form1_MouseUp);
        }
        //6.1.
        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                thePoints[counter].X = e.X;
                thePoints[counter].Y = e.Y;
                Label l = new Label();
                this.SuspendLayout();

                counter++;
                if (counter > 4)
                    this.Refresh();
            }
        }
        //6.2.
        private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                thePoints[counter].X = e.X;
                thePoints[counter].Y = e.Y;
                //Label l = new Label();
                //this.SuspendLayout();

                // ta povezuje krivulje med sabo
                //counter++;
                //if (counter > 4)
                    //this.Refresh();

                // s tem pa rišeš ponovno vsako zase a prejšnjo ?a?ko izbriše!:
                counter = 0;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
        }
    }
}


in tu je counter = 0; s tem sem ločil prejšnjo čačko od nove, sam mi pa prejšnjo izbriše, tega pa nočem, kakšna ideja?

Zgodovina sprememb…

japol ::

Še vedno noben k bi to znou narest? Kako popraut to kodo (drugi post) da mi bo čačke ločevalo med sabo in da ko bom hotu še kako drugo zrisat, da mi prve ne zbriše.

DubleG ::

V array list shrani vse kar rišeš.
GA-P55M-UD2,i5,12GB RAM,Radeon HD 4850,Crucial SSD 64GB,
WD 320GB,WD 5000GB,RevoDrive X2 100GB


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

c# form

Oddelek: Programiranje
131863 (1377) FuI2cY
»

[c#] ukaz radirka

Oddelek: Programiranje
91112 (905) japol
»

[c#] picturebox, slika na sliko

Oddelek: Programiranje
151085 (895) japol
»

[c#] Risanje z miško

Oddelek: Programiranje
221429 (1110) japol
»

Kako se tole naredi?

Oddelek: Izdelava spletišč
261499 (1199) njok

Več podobnih tem