[Multi Screen Capture Program by Smitty][1]
[1]: https://i.stack.imgur.com/A5GY7.png
The Form has
CheckBox2 - Checkbox - Button Style - Anchor = Top, Left
CB1 - ComboBox - Font size = 20 - Text = 1 - Anchor = Top, Left
PB1 - PictureBox - SizeMode = StretchImage - Anchor = Top, Right, Bottom, Left
This is the module1.vb code
This is the ScreenSpec.vb Class I createdCode:Imports System.Drawing.Drawing2D Imports System.Drawing.Imaging Imports System.Media Imports System.Threading Imports System.Management Imports System.Runtime.InteropServices Module Mod1 Dim x As Integer = Screen.AllScreens.Count Public mon(x) As ScreenSpecs <DllImport("gdi32.dll")> Public Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer End Function <DllImport("gdi32.dll", SetLastError:=True, CharSet:=CharSet.Ansi)> Public Function CreateDC(<MarshalAs(UnmanagedType.LPStr)> lpszDriver As String, <MarshalAs(UnmanagedType.LPStr)> lpszDevice As String, <MarshalAs(UnmanagedType.LPStr)> lpszOutput As String, lpInitData As IntPtr) As IntPtr End Function Public Function BeforeLast(value As String, a As String) As String If value = Nothing Then Return value Exit Function End If Dim posA As Integer = value.LastIndexOf(a) If posA = -1 Then Return "" Return value.Substring(0, posA) End Function Public Function BeforeFirst(value As String, a As String) As String If value = Nothing Then Return value Exit Function End If Dim posA As Integer = value.IndexOf(a) If posA = -1 Then Return "" Return value.Substring(0, posA) End Function Public Function AfterFirst(value As String, a As String) As String If value = Nothing Then Return value Exit Function End If Dim posA As Integer = value.IndexOf(a) If posA = -1 Then Return "" Dim adjustedPosA As Integer = posA + a.Length If adjustedPosA >= value.Length Then Return "" Return value.Substring(adjustedPosA) End Function Public Function AfterLast(value As String, a As String) As String If value = Nothing Then Return value Exit Function End If Dim posA As Integer = value.LastIndexOf(a) If posA = -1 Then Return "" Dim adjustedPosA As Integer = posA + a.Length If adjustedPosA >= value.Length Then Return "" Return value.Substring(adjustedPosA) End Function Public Function GrabScreen(Index As Integer) As Bitmap Dim MonWidth As Integer = mon(Index).Width Dim MonHeight As Integer If Form1.CheckBox2.Checked Then MonHeight = mon(Index).Height Else MonHeight = mon(Index).HeightNtb End If Dim screenSize As Size = New Size(MonWidth, MonHeight) Dim screenGrab As New Bitmap(MonWidth, MonHeight) Dim g As Graphics = Graphics.FromImage(screenGrab) g.CopyFromScreen(New Point(mon(Index).XStart, mon(Index).YStart), New Point(0, 0), screenSize) Return screenGrab End Function Public Function GetScalleFactor(index As Integer) As Double Dim desktop As IntPtr = CreateDC(Screen.AllScreens(index).DeviceName, Nothing, Nothing, IntPtr.Zero) Return GetDeviceCaps(desktop, 118) / GetDeviceCaps(desktop, 8) End Function End Module
This is the Form1.vb codeCode:Public Class ScreenSpecs Private BPPValue As Integer Private IndexValue As Integer Private NameValue As String Private WidthValue As Integer Private HeightValue As Integer Private HeightNtbValue As Integer Private ScaleValue As Double Private XStartValue As Integer Private YStartValue As Integer Public Property BPP() As Integer Get ' Gets the property value. Return BPPValue End Get Set(ByVal Value As Integer) ' Sets the property value. BPPValue = Value End Set End Property Public Property Index() As Integer Get ' Gets the property value. Return IndexValue End Get Set(ByVal Value As Integer) ' Sets the property value. IndexValue = Value End Set End Property Public Property Name() As String Get ' Gets the property value. Return NameValue End Get Set(ByVal Value As String) ' Sets the property value. NameValue = Value End Set End Property Public Property Width() As String Get ' Gets the property value. Return WidthValue End Get Set(ByVal Value As String) ' Sets the property value. WidthValue = Value End Set End Property Public Property Height() As String Get ' Gets the property value. Return HeightValue End Get Set(ByVal Value As String) ' Sets the property value. HeightValue = Value End Set End Property Public Property HeightNtb() As String Get ' Gets the property value. Return HeightNtbValue End Get Set(ByVal Value As String) ' Sets the property value. HeightNtbValue = Value End Set End Property Public Property Scale() As Double Get ' Gets the property value. Return ScaleValue End Get Set(ByVal Value As Double) ' Sets the property value. ScaleValue = Value End Set End Property Public Property XStart() As String Get ' Gets the property value. Return XStartValue End Get Set(ByVal Value As String) ' Sets the property value. XStartValue = Value End Set End Property Public Property YStart() As String Get ' Gets the property value. Return YStartValue End Get Set(ByVal Value As String) ' Sets the property value. YStartValue = Value End Set End Property End Class
When program starts it will find all monitors and list them in ComboBox.Code:Imports System.Drawing.Imaging Imports System.Runtime.InteropServices Imports System.Threading Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load On Error Resume Next CB1.Items.Clear() Dim x As Integer Dim MonH As Integer Dim MonHtb As Integer Dim MonW As Integer For x = 0 To (UBound(Screen.AllScreens)) mon(x) = New ScreenSpecs() mon(x).Index = x mon(x).Name = Screen.AllScreens(x).DeviceName.ToString mon(x).BPP = Screen.AllScreens(x).BitsPerPixel MonH = Screen.AllScreens(x).Bounds.Size.Height.ToString MonHtb = Screen.AllScreens(x).WorkingArea.Size.Height.ToString MonW = Screen.AllScreens(x).Bounds.Size.Width.ToString mon(x).Scale = GetScalleFactor(x) mon(x).Height = (MonH * mon(x).Scale) mon(x).HeightNtb = (MonHtb * mon(x).Scale) mon(x).Width = (MonW * mon(x).Scale) mon(x).XStart = Screen.AllScreens(x).Bounds.Location.X.ToString mon(x).YStart = Screen.AllScreens(x).Bounds.Location.Y.ToString CB1.Items.Add((x + 1)) Next End Sub Private Sub PB1_Click(sender As Object, e As EventArgs) Handles PB1.Click PB1.Image = GrabScreen((Int(CB1.Text) - 1)) End Sub Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged If CheckBox2.Checked = False Then CheckBox2.Text = "No Taskbar" CheckBox2.BackColor = Color.Pink Else CheckBox2.Text = "Show Taskbar" CheckBox2.BackColor = Color.LightGreen End If End Sub Private Sub CB1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CB1.SelectedIndexChanged Dim MonSpec As String = "" Dim x As Integer = sender.SelectedIndex Me.Text = "Monitor Number " & mon(x).Index & " - BitsPerPixel = " & mon(x).BPP & " - Scaling Factor = " & mon(x).Scale & " - Width = " & mon(x).Width & " - Height = " & mon(x).Height & " - X-Start = " & mon(x).XStart & " - Y-Start = " & mon(x).YStart End Sub End Class
Set ComboBox to monitor number you want and single-click PictureBox.
Your selected monitor will be captured in the PictureBox. The CheckBox is used as a (Show Task Bar/Hide Task Bar). Also as you switch ComboBox the selected monitors specs will show in the forms title bar.
---------------------------------------
Made change to the picturebox click which will hide the screenshot program.
Code:Private Sub PB1_Click(sender As Object, e As EventArgs) Handles PB1.Click Me.SendToBack() Application.DoEvents() PB1.Image = GrabScreen((Int(CB1.Text) - 1)) Application.DoEvents() Me.BringToFront() End Sub




Reply With Quote