史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2014-02-07, 08:43 PM   #1
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:42 | 在線時長:1983小時 | 升級還需:38小時級別:42 | 在線時長:1983小時 | 升級還需:38小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 2943
精華: 0
現金: 14755 金幣
資產: 2678385 金幣
預設 程式 - [使用版本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, 收花文章: 1552 篇, 收花: 3891 次
回覆時引用此帖
向 魔術王子 送花的會員:
power_ful55 (2015-02-07)
感謝您發表一篇好文章
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
程式 - [使用版本VB2008]TIF圖檔瀏覽 魔術王子 程式語言討論區 0 2014-02-06 09:01 PM
程式 - [使用版本VB2008]在桌面建立程式捷徑 魔術王子 程式語言討論區 0 2014-02-06 08:31 PM
程式 - [使用版本VB2008]使用INI檔儲存程式最後狀態 魔術王子 程式語言討論區 0 2014-02-05 07:46 PM
程式 - [使用版本VB2008]使用NotifyIcon(TrayIcon)偵測滑鼠有無移動 魔術王子 程式語言討論區 0 2014-02-05 07:32 PM
程式 - [使用版本VB2008]通訊錄存成Excel檔 魔術王子 程式語言討論區 0 2014-01-27 08:00 PM


所有時間均為台北時間。現在的時間是 02:31 PM


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


SEO by vBSEO 3.6.1