Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何允许c#中的g.拉线在放入picturebox后进行调整_C#_Visual Studio 2010_Picturebox - Fatal编程技术网

如何允许c#中的g.拉线在放入picturebox后进行调整

如何允许c#中的g.拉线在放入picturebox后进行调整,c#,visual-studio-2010,picturebox,C#,Visual Studio 2010,Picturebox,我试着用一个图片盒,挑出2个点(照片中的眼睛)。我将用g.DrawString选择两点,在这里我将画两个不同的“x”。现在的问题是,如果用户将“x”放置在错误的位置,而我想对其进行调整,我会被卡住。是否有任何代码允许移动g.DrawString“x” using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

我试着用一个图片盒,挑出2个点(照片中的眼睛)。我将用
g.DrawString
选择两点,在这里我将画两个不同的“x”。现在的问题是,如果用户将“x”放置在错误的位置,而我想对其进行调整,我会被卡住。是否有任何代码允许移动
g.DrawString
“x”

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Camera
{
    public partial class CamDisplay : Form
    {

        public CamDisplay()
        {
            InitializeComponent();
            this.pictureBox1.ImageLocation = @"C:\center90\center90(1).jpg";
        }


        bool MousedClicked = true;
        bool MouseClicked2 = true;

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            base.OnMouseClick(e);

            if (MousedClicked == true)
            {
                txtXaxis.Text = e.X.ToString();
                txtYaxis.Text = e.Y.ToString();
                MousedClicked = false;

                using (Graphics g = Graphics.FromHwnd(pictureBox1.Handle))
                {
                    using (Font myFont = new Font("Calibri", 8))
                    {
                        g.DrawString("X", myFont, Brushes.Red, new PointF(e.X, e.Y));
                    }
                }
            }

            else if (MouseClicked2 == true)
            {
                txtRXaxis.Text = e.X.ToString();
                txtRYaxis.Text = e.Y.ToString();
                MouseClicked2 = false;

                using (Graphics g = Graphics.FromHwnd(pictureBox1.Handle))
                {
                    using (Font myFont = new Font("Calibri", 8))
                    {
                        g.DrawString("X", myFont, Brushes.Red, new PointF(e.X, e.Y));
                    }
                }
            }

            else
            {
                MousedClicked = false;
                MouseClicked2 = false;
            }

        }

        private void CamDisplay_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox1.Cursor = Cursors.Hand;
        }  
    }
}

你的问题不清楚。据我所知,您有两种选择:

  • 如果您使用图形对象直接操作BMP(即直接将字符串绘制到位图),则无法“撤消”以前的操作。您可以在内存中保留原始位图的本地副本,将其复制到第二个位图,然后仅对副本执行操作,该副本就是您在表单中显示的副本。当您需要“撤消”时,只需返回原始副本

  • 不要直接操作位图,而是在PictureBox的OnPaint()事件中执行绘图操作。这样,您只需在屏幕上绘制,保留原始Bmp不变。请参见此处的示例:


  • 我在我的代码中添加了一些可以给我一些建议我应该在哪里进行更改吗?很抱歉耽搁了很长时间,我一直很忙。快速浏览一下代码,您似乎在鼠标单击事件中直接绘制到窗口。这将是对上述建议(2)的一种修改。刷新窗口/控件实际上应该“擦除”两个标记。尝试调用pictureBox1.Refresh()。