Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > WPF, UWP, WinRT, XAML
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 27.03.2016, 20:34   #1
fade24th
Новичок
Джуниор
 
Регистрация: 27.03.2016
Сообщений: 1
По умолчанию Поле для добавления пикселей на XAML

Здравствуйте, нужна помощь в создании 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());
        }
    }
}
fade24th вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Конструкция #IF #ELSE для XAML Ader WPF, UWP, WinRT, XAML 1 05.02.2016 09:16
Поле "Дата" в форме для добавления новых записей в основную таблицу (Access) Zercon Помощь студентам 1 13.01.2013 14:41
App.xaml, MainPage.xaml, и тд. Chelovekpredel Общие вопросы .NET 0 19.12.2012 14:52
включить побочный Generic.xaml файл в основной App.xaml ImmortalAlexSan WPF, UWP, WinRT, XAML 1 21.09.2012 19:58
Расчет количества пикселей для отображения записи Lokos Общие вопросы Delphi 11 07.04.2011 08:33