gpt4 book ai didi

vb.net - 尝试删除以前在 Visual Basic 中创建的边框

转载 作者:行者123 更新时间:2023-12-04 05:11:43 24 4
gpt4 key购买 nike

我有这个代码:

Sub drawborder()
Dim objGraphics As Graphics
objGraphics = Me.CreateGraphics
objGraphics.Clear(System.Drawing.SystemColors.Control)
objGraphics.DrawRectangle(System.Drawing.Pens.Red, picShowPicture.Left - 1, picShowPicture.Top - 1, picShowPicture.Width + 1, picShowPicture.Height + 1)
objGraphics.Dispose()
borderstatus.Text = "Border Drawn"
End Sub

这会在图片框周围绘制一个边框。现在我想用另一个按钮再次删除它,但我似乎无法让它工作。

最佳答案

不要使用 CreateGraphics ,这只是一个临时绘图,当您最小化表单或将其移出屏幕等时,它将被删除。

尝试持有一个变量,然后使表单无效:

Private _ShowBorder As Boolean

Public Sub New()
InitializeComponent()
Me.DoubleBuffered = True
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_ShowBorder = Not _ShowBorder
Me.Invalidate()
End Sub

Protected Overrides Sub OnPaint(e As PaintEventArgs)
e.Graphics.Clear(Me.BackColor)

If _ShowBorder Then
e.Graphics.DrawRectangle(Pens.Red, PictureBox1.Left - 1, PictureBox1.Top - 1, PictureBox1.Width + 1, PictureBox1.Height + 1)
End If

MyBase.OnPaint(e)
End Sub

关于vb.net - 尝试删除以前在 Visual Basic 中创建的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14841441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com