如何删除图片框内的文字 [英] How can I delete text inside of a picturebox

查看:117
本文介绍了如何删除图片框内的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次点击图片框后,程序都会放置一个圆圈,其中包含一个圆圈。下一次单击将放置2,依此类推。如果用户在他们不想要的时候意外点击,我添加了一个撤消按钮。如何删除写入图片框的文字?



我尝试了什么:



这是我用来编写带有数字的圆圈的代码:

After every click on the picturebox the program will place a circle with a one in it. The next click will put a 2 and so on. I added an undo button if the user accidentally clicked when they didn't want to. How can I delete the text that was written into the picturebox?

What I have tried:

This is the code I have used to write the circle with the number inside of it:

Public Class Form1
    Dim Counter As Integer
    Dim g As Graphics
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        g = PictureBox1.CreateGraphics
        Counter = 0
    End Sub

    Private Sub PictureBox1_MouseDown(sender As Object, e As EventArgs) Handles PictureBox1.MouseDown
        Dim X As Integer
        Dim Y As Integer
        Dim f As New Font("Arial", 10)
        X = Cursor.Position.X
        Y = Cursor.Position.Y
        Counter = Counter + 1
        TextBox1.Text = Counter
        If Counter = 1 Then
            g.DrawEllipse(Pens.Black, New Rectangle(X - 289, Y - 157, 20, 20))
            g.DrawString("1.", f, Brushes.Black, New Point(X - 285, Y - 155))
        End If
        If Counter = 2 Then
            g.DrawEllipse(Pens.Black, New Rectangle(X - 289, Y - 157, 20, 20))
            g.DrawString("2.", f, Brushes.Black, New Point(X - 285, Y - 155))
        End If
    End Sub
End Class

推荐答案

基本上,你不能。一旦它被绘制它就是永久性的。



所以,你要做的就是实现撤销功能。在一个相当简单的实现中,这意味着跟踪您对图片所做的每个操作(更改)。



撤消操作时,重新开始,应用每个操作您添加到列表中的操作是您开始使用的原始图像,最后一个除外。这是你的撤消步骤。
Basically, you can't. Once it's drawn it's permanent.

So, what you have to do is implement Undo functionality. In a rather simplistic implementation, that means keeping track of each operation (change) you make to the picture.

When you undo an operation, you start over, applying each operation you added to the list to the original image you started with, except for the last one. There's your "undone" step.


如果图片框背景是一种颜色,你可以根据需要使用颜色选择器将你的圆圈颜色设置为相同的颜色,然后在一样的地方。 Perst-o改变 - 它消失了。将你的颜色设置回来并且士兵开启。



我已经完成了这个。
If the picturebox background is one color, you can set your circle color to be the same color using a color picker if necessary, and draw it again in the same place. Prest-o change-o it's gone. Set your color back and soldier on.

I've done this.


引用:

如何删除写入图片框的文本?

How can I delete the text that was written into the picturebox?



简答:正如以前的解决方案所说,你可以' t删除最后一次更改。

因为任何更改是累积的,并且可能与图片中的内容重叠,所以无法知道更改会覆盖什么。

唯一的方法是记住原始图片,并以允许您将图片重建到之前状态的方式完成每个更改。


Short answer: as told by previous solutions, you can't delete last change.
Because any change is cumulative, and can overlap things already in picture, it is impossible to know what was overwritten by change.
The only way is to memorize the original picture and every change done in a way that will allow you to rebuild the picture up to previous state.


这篇关于如何删除图片框内的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆