修复剪贴板被占用时无提示

This commit is contained in:
camileko
2026-09-22 23:25:55 +08:00
parent 8f76864574
commit d1e969d742
3 changed files with 15 additions and 20 deletions
+12 -14
View File
@@ -1021,22 +1021,20 @@ Public Module ModBase
''' <summary>
''' 设置剪贴板。将在另一线程运行,且不会抛出异常。
''' </summary>
Public Sub ClipboardSet(Text As String, Optional ShowSuccessHint As Boolean = True)
Public Sub ClipboardSet(Text As String, Optional ShowSuccessHint As Boolean = True, Optional SuccessHint As String = "")
RunInThread(
Sub()
Try
Retrier.Attempt(delay:=Function(Attempt) TimeSpan.FromMilliseconds(200), maxAttempts:=4, isRetryAllowed:=Function(ex) True, action:=
Sub()
RunInUi(
Sub()
My.Computer.Clipboard.Clear()
If Not String.IsNullOrEmpty(Text) Then My.Computer.Clipboard.SetText(Text)
End Sub)
End Sub)
If ShowSuccessHint Then Hint("已成功复制!", HintType.Green)
Catch ex As Exception
Logger.Error(ex, "可能由于剪贴板被其他程序占用,文本复制失败", LogBehavior.Toast)
End Try
RunInUi(
Sub()
Try
My.Computer.Clipboard.Clear()
If Not String.IsNullOrEmpty(Text) Then My.Computer.Clipboard.SetText(Text)
If ShowSuccessHint Then Hint(If(String.IsNullOrEmpty(SuccessHint), "已成功复制!", SuccessHint), HintType.Green)
Catch ex As Exception
Logger.Error(ex, behavior:=LogBehavior.None)
Hint("复制失败,可能由于剪贴板被其他程序占用!", HintType.Red)
End Try
End Sub)
End Sub)
End Sub
''' <summary>