vb.net给窗体截图 (VB.net,仿照Windows原版截图,类库——9)

20 篇文章 1 订阅
17 篇文章 1 订阅

参考 :前面我写的文章VB.net类库——4给屏幕截图

有一定的局限性,因为当时只想到了rectangle类的参数是:左上角point as point , width as integer,height as integer,就写从左上角滑到右下角。

基本思路:注意,那边的斜杠不是除以,是或者的意思d049efb546054698ab2cacf982e76435.png

在Windows截图中:可以使用win+shift+s来截图,可以全屏,矩形,选择窗口和自定义截图,功能甚是强大。

我们在传参数时,仍然只要在MouseDown时传p1,在MouseUp时传p2,MouseMove啥要不要

看修改后的Cut窗体的代码:

'Imports GDI_Make_NET4_5.myScreen
Public Class Cut
    Public GDIscr As New GDI_Make_NET4_5.myScreen
    Private ispick As Boolean
    Public Sub ShowMe(bmp As Bitmap)
        Pic.Location = New Point(0, 0)
        Pic.Width = bmp.Width
        Pic.Height = bmp.Height
        Pic.Image = bmp
        ispick = True
        Me.Show()
    End Sub

    Private Sub Pic_MouseDown(sender As Object, e As MouseEventArgs) Handles Pic.MouseDown
        If ispick = True Then
            GDIscr.p1 = New Point(e.X, e.Y)
        End If
    End Sub

    Private Sub Pic_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic.MouseUp
        If ispick = True Then
            GDIscr.p2 = New Point(e.X, e.Y)


            GDIscr.PointList() '改动在这里


            Pic.Image = GDIscr.CutScren(Pic.Image)
            Clipboard.SetImage(Pic.Image)
            MsgBox("已复制到剪切板,双击图片退出")
            ispick = False
        End If
    End Sub

    Private Sub Pic_DoubleClick(sender As Object, e As EventArgs) Handles Pic.DoubleClick
        Close()
    End Sub
End Class

topMost=true 

WindowState=Maximized

6dff731848fa4798bdefb2b456bbf562.png

 在类库里写

    Public p3 As Point
    Public p4 As Point

    Public width As Integer
    Public height As Integer
    Public LeftTop As Point




 Public Function CutScren(bmp As Bitmap)
        g = Graphics.FromImage(bmp)
        Dim rc As Rectangle = New Rectangle(LeftTop, New Size(width, height))   '起点和长宽,这里有改动
        Image = bmp.Clone(rc, Imaging.PixelFormat.Format32bppArgb)
        Return Image
    End Function

Public Function PointList()

        If p1.X < p2.X AndAlso p1.Y < p2.Y Then
            p3 = New Point(p2.X, p1.X)
            p4 = New Point(p1.X, p2.Y)
            width = p3.X - p1.X
            height = p4.Y - p1.Y
            LeftTop = p1
        ElseIf p1.X > p2.X AndAlso p1.Y < p2.Y Then
            p3 = New Point(p1.X, p2.Y)
            p4 = New Point(p2.X, p1.Y)
            width = p1.X - p4.X
            height = p2.Y - p4.Y
            LeftTop = p4
        ElseIf p1.X > p2.X AndAlso p1.Y > p2.Y Then
            p3 = New Point(p1.X, p2.X)
            p4 = New Point(p2.X, p1.Y)
            width = p3.X - p2.X
            height = p4.Y - p2.Y
            LeftTop = p2
        ElseIf p1.X < p2.X AndAlso p1.Y > p2.Y Then
            p3 = New Point(p2.X, p1.Y)
            p4 = New Point(p1.X, p2.Y)
            width = p2.X - p4.X
            height = p1.Y - p4.Y
            LeftTop = p4
        End If

    End Function

 之前的注释可以把 “两个顶点样式为从左上角划向右下角。”改掉了4dd17dac0e8541d08a152e636e74b59e.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值