vb2015像qq那样由用户自定义截图区进行截图的代码要怎么写?
1个回答
展开全部
'截图时打开这个半透明全屏的无边框窗口,用鼠标拖选边框,双击窗口,调用默认图片软件显示截图。
Public Class Form2
Private Sub Form2_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDoubleClick
Me.Close()
If oldRect <> Nothing Then
ControlPaint.DrawReversibleFrame(oldRect, Me.BackColor, FrameStyle.Thick)
Dim img As New Bitmap(oldRect.Width, oldRect.Height)
Graphics.FromImage(img).CopyFromScreen(oldRect.X, oldRect.Y, 0, 0, oldRect.Size)
img.Save("c:\cutimg.jpg", Imaging.ImageFormat.Jpeg)
Process.Start("c:\cutimg.jpg")
End If
End Sub
Dim startPoint As Point
Dim curRect As Rectangle
Public oldRect As Rectangle
Dim onRect As Boolean
Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
onRect = True
startPoint = e.Location
End If
End Sub
Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If onRect Then
Using Gr As Graphics = CreateGraphics()
If oldRect <> Nothing Then
ControlPaint.DrawReversibleFrame(oldRect, Me.BackColor, FrameStyle.Thick)
End If
curRect = Rectangle.FromLTRB(startPoint.X, startPoint.Y, e.X, e.Y)
If curRect.Width > 0 And curRect.Height > 0 Then
ControlPaint.DrawReversibleFrame(curRect, Me.BackColor, FrameStyle.Thick)
oldRect = curRect
End If
End Using
End If
End Sub
Private Sub Form2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
onRect = False
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oldRect = Nothing
End Sub
Public Sub New()
' 此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
' 在 InitializeComponent() 调用之后添加任何初始化。
ShowInTaskbar = False
Text = ""
ControlBox = False
TopMost = True
WindowState = FormWindowState.Maximized
Opacity = 0.3
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询