Здравствуйте, нужна помощь в создании WPF интерфейса(C#) . Суть - должно быть поле, на котором при нажатии левой клавиши мышь появлялись пиксели (черные точки).
Пример на WindowsForms:
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace Point
{
class Point
{
protected int x;
protected int y;
public Point()
{
x = 5;
y = 5;
}
public Point(int k, int g)
{
x = k;
y = g;
}
public Point(Point p)
{
x = p.x;
y = p.y;
}
public int getx()
{
return x;
}
public int gety()
{
return y;
}
public void setx(int t)
{
x = t;
}
public void sety(int t)
{
y = t;
}
public double distance(Point p)
{
return Math.Sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
public void plus(Point p)
{
x = x + p.x;
y = y + p.y;
}
public bool testconv(Point p)
{
if ((x == p.x) && (y == p.y)) return true;
else return false;
}
public void displayin()
{
Console.WriteLine(" enter point\n");
x = y = Convert.ToInt32(Console.ReadLine());
}
public virtual void displayout()
{
Console.WriteLine(string.Format("Point({0},{1})\n", x, y));
}
class PColor : Point
{
private string c;
public override void displayout()
{
Console.WriteLine("Color " + c);
}
public PColor()
{
c = "white";
}
public PColor(int x1, int y1, string c1) : base(x1, y1)
{
c = c1;
}
public PColor(PColor p) : base(p)
{
c = p.c;
}
}
/*static void Main(string[] args)
{
int x, y;
Point a = new Point();
a.displayout();
a.displayin();
Console.WriteLine("you entered: " + a.getx() + " " + a.gety());
a.displayout();
Console.WriteLine("copy constructor test: ");
Point b = new Point(a);
b.displayout();
Console.WriteLine("enter x,y:\n");
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
a.setx(x);
a.sety(y);
Console.WriteLine("setter test: ");
a.displayout();
Console.WriteLine("parameter constructor test: ");
Point c = new Point(x, y);
c.displayout();
Console.WriteLine("distance: " + c.distance(b));
if (b.testconv(c)) Console.WriteLine("they are equal\n");
else Console.WriteLine("they are not equal\n");
Console.WriteLine("adding points result: ");
a.plus(b);
a.displayout();
PColor f = new PColor();
f.displayout();
PColor f1 = new PColor(3, 3, "green");
f1.displayout();
PColor f2 = new PColor(f1);
f2.displayout();
Console.ReadKey();
}*/
}
class Program : Form
{
private List<Point> points;
public Program()
{
points = new List<Point>();
this.Paint += new PaintEventHandler(this.onPaint);
this.MouseClick += new MouseEventHandler(this.onClick);
}
private void onPaint(object sender, PaintEventArgs e)
{
points.ForEach(delegate (Point point) {
e.Graphics.FillRectangle(Brushes.Black, point.getx(), point.gety(), 1, 1);
});
}
private void onClick(object sender, MouseEventArgs e)
{
Point point = new Point(e.X, e.Y);
points.Add(point);
Refresh();
}
public static void Main(string[] args)
{
Application.Run(new Program());
}
}
}