史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   [使用版本VB2008]螢幕擷取 (http://forum.slime.com.tw/thread275438.html)

魔術王子 2014-02-07 08:43 PM

[使用版本VB2008]螢幕擷取
 
程式畫面
https://imagizer.imageshack.us/v2/1075x753q90/833/ixjl.jpg
程式可以截取目前畫面或讀取剪貼簿的圖,或開啟已經存在的圖檔
程式在執行有一個需要注意的地方,就是程式需要兩個游標檔
https://imagizer.imageshack.us/v2/809x655q90/841/xqrb.jpg
https://imagizer.imageshack.us/v2/32x32q90/854/vahr.pngmove.curhttps://imagizer.imageshack.us/v2/32x32q90/844/r4q4.pngmovekd.cur
因為程式可以移動圖的位置,所以必須顯示不同的游標提醒使用者
引用:

作者: 程式元件
Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents ToolStripButton1 As System.Windows.Forms.ToolStripButton
Friend WithEvents ToolStripButton2 As System.Windows.Forms.ToolStripButton
Friend WithEvents ToolStripButton3 As System.Windows.Forms.ToolStripButton
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents ToolStripSeparator1 As System.Windows.Forms.ToolStripSeparator
Friend WithEvents ToolStripButton4 As System.Windows.Forms.ToolStripButton
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog

引用:

作者: 程式碼
Public Class Form1
Dim kmx As Single, kmy As Single

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Panel1.AutoScroll = True
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim g As Graphics
Dim bmp As Bitmap
Dim i As Integer = 0
My.Application.DoEvents()
bmp = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
g = Graphics.FromImage(bmp)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height))
g.Dispose()
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = bmp.Width
PictureBox1.Height = bmp.Height
PictureBox1.Image = bmp
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = My.Computer.Clipboard.GetImage.Width
PictureBox1.Height = My.Computer.Clipboard.GetImage.Height
PictureBox1.Image = My.Computer.Clipboard.GetImage
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim newImage As Image
newImage = Image.FromFile(OpenFileDialog1.FileName)
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = newImage.Width
PictureBox1.Height = newImage.Height
PictureBox1.Image = newImage
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End If
End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then
PictureBox1.Cursor = New Cursor("movekd.cur")
kmx = e.Location.X
kmy = e.Location.Y
PictureBox1.Tag = 1
End If
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then
PictureBox1.Cursor = New Cursor("move.cur")
PictureBox1.Tag = 0
End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If PictureBox1.Tag = 1 Then Panel1.AutoScrollPosition = New Point(Panel1.HorizontalScroll.Value + kmx - e.Location.X, Panel1.VerticalScroll.Value + kmy - e.Location.Y)
End Sub

Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName)
End If
End Sub
End Class

若沒有這兩個檔案,請將程式內PictureBox1.Cursor = New Cursor("move.cur")和PictureBox1.Cursor = New Cursor("movekd.cur")拿掉


所有時間均為台北時間。現在的時間是 09:02 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1