查看單個文章
舊 2014-02-07, 08:43 PM   #1
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:42 | 在線時長:1985小時 | 升級還需:36小時級別:42 | 在線時長:1985小時 | 升級還需:36小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 2945
精華: 0
現金: 14765 金幣
資產: 2678395 金幣
預設 [使用版本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")拿掉

此帖於 2014-02-07 08:59 PM 被 魔術王子 編輯.
魔術王子 目前離線  
送花文章: 1523, 收花文章: 1553 篇, 收花: 3892 次
回覆時引用此帖
向 魔術王子 送花的會員:
power_ful55 (2015-02-07)
感謝您發表一篇好文章