Hi @Štefan Mihael Rihar ,
Thanks for your feedback.
You can refer to the following way to use setclip method in keyup event.
Private state As String
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
Select Case e.KeyCode
Case Keys.O
state = "O"
Case Keys.Space
state = "Space"
End Select
Me.Invalidate()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Select Case state
Case "O"
Dim clipRect As New Rectangle(100, 100, 100, 100)
e.Graphics.SetClip(clipRect, CombineMode.Replace)
e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, 500, 500)
Case "Space"
Dim clipRect As New Rectangle(50, 50, 50, 50)
e.Graphics.SetClip(clipRect, CombineMode.Replace)
e.Graphics.FillRectangle(New SolidBrush(Color.Green), 0, 0, 500, 500)
End Select
End Sub
Press 'O':
Press 'Space':
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.