Make screen grey apart from window area...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I am using the following code to place a rectangle around a form / form control, however what I want to do is make my screen grey and only the form / form control area be displayed in colour.

VB.NET:
Imports System.Diagnostics
Imports System.Drawing
Imports System.Windows.Forms

Namespace CodeReflection.ScreenCapturingDemo
	''' <summary>
	''' Summary description for WindowHighlighter.
	''' </summary>
	Public Class WindowHighlighter
		''' <summary>
		''' Highlights the specified window just like Spy++
		''' </summary>
		''' <param name="hWnd"></param>
		Public Shared Sub Highlight(hWnd As IntPtr)
			Const  penWidth As Single = 3
			Dim rc As New Win32.Rect()
			Win32.GetWindowRect(hWnd, rc)

			Dim hDC As IntPtr = Win32.GetWindowDC(hWnd)
			If hDC <> IntPtr.Zero Then
				Using pen As New Pen(Color.Black, penWidth)
					Using g As Graphics = Graphics.FromHdc(hDC)
						g.DrawRectangle(pen, 0, 0, rc.right - rc.left - CInt(Math.Truncate(penWidth)), rc.bottom - rc.top - CInt(Math.Truncate(penWidth)))
					End Using
				End Using
			End If
			Win32.ReleaseDC(hWnd, hDC)
		End Sub

		''' <summary>
		''' Forces a window to refresh, to eliminate our funky highlighted border
		''' </summary>
		''' <param name="hWnd"></param>
		Public Shared Sub Refresh(hWnd As IntPtr)
				' TRUE 
			Win32.InvalidateRect(hWnd, IntPtr.Zero, 1)
			Win32.UpdateWindow(hWnd)
			Win32.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, Win32.RDW_FRAME Or Win32.RDW_INVALIDATE Or Win32.RDW_UPDATENOW Or Win32.RDW_ALLCHILDREN)
		End Sub
	End Class
End Namespace

I have googled for ages trying to find something on this, but with no luck.

To illistrate this better they are using the same functionality in snagit 10, please see below link to a page that has a video link showing this (23 sec into video)

TechSmith | Snagit, screen capture software, features

Thanks

Simon
 
Make image grey and rectangle area colour...

I have created a screen capture functionality in my application that captures the entire desktop and then displays this in a picturebox on a form that is maximised. The user then can define a rectangle by draging there cursor which at the moment displays a red rectangle. What I would like to do is make the image black and white and then as the user defines their rectangle display the content of the rectangle in colour.

I have googled for ages trying to find something on this, but with no luck.

To illistrate this better they are using the same functionality in snagit 10, please see below link to a page that has a video link showing this (55 sec into video)

TechSmith | Snagit, screen capture software, features

Thanks

Simon
 
So you have the selection rectangle, you can use a Region object the size of the picturebox and Exclude the selection rectangle, then use use a SolidBrush from a semitransparent gray color (Color.FromArgb) and e.Graphics.FillRegion from the picturebox Paint event. When you get the selection rectangle, Invalidate that before and after selection change and Update picturebox.

For screen capture there is Graphics.CopyFromScreen method that you can use.
 
Back
Top