0

我正在使用 Visual Basic.Net 并在屏幕上绘制图形。

这是我的代码:

Private Sub Button1_Click(ByVal sender As System.Object, 
                          ByVal e As System.EventArgs) Handles Button1.Click
Dim gr As Graphics = Graphics.FromHwnd(New IntPtr(0))
gr.DrawString("text on screen", 
               New Font(Me.Font.FontFamily, 25, 
               FontStyle.Regular), Brushes.Red, 50, 50)
End Sub

在上面的代码中,文本被绘制在屏幕上。我的问题是:如何删除绘制到屏幕上的文本?我看到有一个 .Clear 方法,但是,它'清除整个绘图表面并用指定的背景颜色填充它',而不仅仅是删除绘制的文本。

提前致谢。

编辑

我想开发一个潜意识消息应用程序,当用户使用其他应用程序时,它将在屏幕上显示消息。透明的表格会是最好的方法吗?

4

3 回答 3

0

我发现以下代码有效:

    Private WithEvents TextForm As New Form
Private Zipper As New FontFamily("Zipper")

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    With TextForm
        .BackColor = Color.DimGray
        .TransparencyKey = Color.DimGray
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .ShowInTaskbar = False
        .WindowState = FormWindowState.Maximized
        .Opacity = 0
        .Show(Me)
    End With
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Static showText As Boolean
    showText = Not showText
    If showText Then TextForm.Opacity = 0.99 Else TextForm.Opacity = 0
End Sub

Private Sub TextForm_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles TextForm.Paint
    e.Graphics.DrawString("text on screen 12345", New Font(Zipper, 30, FontStyle.Bold), Brushes.Red, 50, 50)
End Sub
于 2013-03-23T03:55:25.730 回答
0

采用不同的位图并在单独的位图中绘制每个新事物,然后将新位图与旧位图合并。当您要删除文本时,请重新加载没有文本的旧位图。在新位图中搜索绘图并保存绘图。

于 2013-03-23T14:58:05.493 回答
0

你可以试试这个:

Dim Graphics0 as Graphics = Graphics.fromHwnd(0) 'This is the desktop's graphics
Graphics0.DrawText("Test 1..2..3..",New Font(Arial,10),Brushes.Black,New Point(0,0))
于 2019-06-16T10:01:40.323 回答