'截图函数 Functions.Execute("PainterDraw") 可以加给窗体中任何事件比如button的click事件,必须是窗体中才可以
Dim frm As WinForm.Form = Forms.ActiveForm
If frm IsNot Nothing Then
Dim PainterDraw As WinForm.Painter
PainterDraw = Forms(Forms.ActiveForm.Name).CreateControl("Painter123321", ControlTypeEnum.Painter)
PainterDraw.SetBounds(-10,-10,6,6) '指定位置和尺寸
Forms(Forms.ActiveForm.Name).AddControl(PainterDraw)
'===============
Dim memoryImage As Bitmap
Dim p As WinForm.Painter = Forms(Forms.ActiveForm.Name).Controls("Painter123321")
Dim myGraphics As Graphics = p.Graphics
'Dim myGraphics As Graphics = Me.CreateGraphics()
Dim s As Size = New Size(SysInfo.ScreenWidth,SysInfo.ScreenHeight)
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s)
'=========以上截图=============
Dim fnt As New Font("宋体",16)
Dim msg As String
msg = "【计算机名】" & SysInfo.ComputerName & vbcrlf '计算机名
msg = msg & "【操作系统】" & SysInfo.OSFullName & vbcrlf '操作系统名称
msg = msg & "【版-本-号】" & SysInfo.OSVersion & vbcrlf '操作系统版本号
msg = msg & "【用-户-名】" & SysInfo.UserName & vbcrlf '登陆操作系统的用户名
msg = msg & "【可用内存】" & SysInfo.AvailablePhysicalMemory \ (1024 * 1024) & "MB" & vbcrlf '可用的物理内存
msg = msg & "【总-内-存】" & SysInfo.TotalPhysicalMemory \ (1024 * 1024) & "MB" & vbcrlf '总的物理内存
msg = msg & "【截图时间】" & Date.Now & vbcrlf '截图时间
memoryGraphics.DrawString(msg,fnt,Brushes.Red,10,10)
'=========以上水印文字============
Dim str As String = "自动截图(" & Format(Date.Now,"yyMMddHHmm") & ")" & Rand.Next(1,10000) & ".jpg"
memoryImage.Save(ProjectPath & Str) '这是自动保存,以下是选择保存
'========选择保存======
'Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
'dlg.Filter = "图像文件|*.jpg" '设置筛选器
'dlg.Title = "截图保存为" '设置对话框标题
'dlg.FileName = str '设置默认文件名
'If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
' MessageBox.Show("你要保存为:" & dlg.FileName,"提示") '提示用户选择的文件
'memoryImage.Save(dlg.FileName)
'End If
'========选择保存======
Forms(Forms.ActiveForm.Name).RemoveControl("Painter123321") '从窗口删除指定名称的控件
Else
MessageBox.Show("无活动窗口!无法截图" )
End If
你好.请教:如何保存截图到指定的文件夹下面?