在第一个面板中画一个正方形,在第二个面板中得到一个完整的正方形

问题描述 投票:0回答:0

在第一个面板中画一个正方形,在第二个面板中得到一个完整的正方形,

我在 winForm 中有 2 个面板,

面板A

public partial class frmPaint : Form
    {
        public Point x = new();
        public Point y = new();
        public Pen penA = new(Color.Red, 2);
        public Pen Eraser = new(Color.White, 10);
        public Graphics graphics;
        public frmPaint()
        {
            InitializeComponent();
            graphics = panelDraw.CreateGraphics();
        }

        private void panelDraw_MouseDown(object sender, MouseEventArgs e)
        {
            y = e.Location;

            if (rbLineWidth5.Checked)
                penA.Width = 5;
            if (rbLineWidth10.Checked)
                penA.Width = 10;
            if (rbLineWidth15.Checked)
                penA.Width = 15;
        }

        private void panelDraw_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                x = e.Location;
                graphics.DrawLine(penA, x, y);
                y = e.Location;
            }

            if (e.Button == MouseButtons.Right)
            {
                x = e.Location;
                graphics.DrawLine(Eraser, x, y);
                y = e.Location;
            }
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            ColorDialog colorDialog = new();
            if (colorDialog.ShowDialog() == DialogResult.OK)
                penA.Color = colorDialog.Color;
        }
    }

我应该如何更改此代码,以便当我在 panelA 中绘制某些内容时,panelB 应该理解我绘制的内容,如果绘制的形状类似于正方形,则在 panelB 的相同位置应该有一个正方形

像这样

在这里输入链接描述

在这里输入链接描述

c# graphics windows-forms-designer
© www.soinside.com 2019 - 2024. All rights reserved.