Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / Visual Basic

Screen Shot Application

Rate me:
Please Sign up or sign in to vote.
3.74/5 (69 votes)
24 Sep 2010CPOL5 min read 303.6K   18.6K   210  
Screen Shot is a simple application that allows a user to quickly capture images from the screen and save them in a user predefined folder.
'Author: Arman Ghazanchyan
'Created date: 01/27/2007
'Last updated: 01/28/2007
Imports System.Drawing.Drawing2D

Public Class Shape

    ''' <summary>
    ''' Rounds a rectangle corners' and returns the graphics path.
    ''' </summary>
    ''' <param name="rec">A rectangle whose corners should be rounded.</param>
    ''' <param name="r">The radius of the rounded corners. This value should be 
    ''' bigger then 0 and less or equal to the (a half of the smallest value 
    ''' of the rectangle�s width and height).</param>
    ''' <param name="exclude_TopLeft">A value that specifies if the top-left 
    ''' corner of the rectangle should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_TopRight">A value that specifies if the top-right 
    ''' corner of the rectangle should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_BottomRight">A value that specifies if the bottom-right 
    ''' corner of the rectangle should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_BottomLeft">A value that specifies if the bottom-left 
    ''' corner of the rectangle should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    Public Shared Function RoundedRectangle(ByVal rec As Rectangle, ByVal r As Integer, _
    Optional ByVal exclude_TopLeft As Boolean = False, _
    Optional ByVal exclude_TopRight As Boolean = False, _
    Optional ByVal exclude_BottomRight As Boolean = False, _
    Optional ByVal exclude_BottomLeft As Boolean = False) As Drawing2D.GraphicsPath

        Dim path As New GraphicsPath
        Dim s As Integer = r * 2
        'If 's' is less than or equal to zero, 
        'then return a simple rectangle.
        If Not s > 0 Then
            path.StartFigure()
            path.AddLine(rec.Right, rec.Y, rec.Right, rec.Y)
            path.AddLine(rec.Right, rec.Bottom, rec.Right, rec.Bottom)
            path.AddLine(rec.X, rec.Bottom, rec.X, rec.Bottom)
            path.AddLine(rec.X, rec.Y, rec.X, rec.Y)
            path.CloseAllFigures()
            Return path
        End If
        'If 's' is bigger than the smallest value of the size, 
        'then assign the value to 's'.
        If rec.Height <= rec.Width Then
            If s > rec.Height Then
                s = rec.Height
            End If
        Else
            If s > rec.Width Then
                s = rec.Width
            End If
        End If
        path.StartFigure()
        'Set top-right corner.
        If Not exclude_TopRight Then
            path.AddArc(rec.Right - s, rec.Y, s, s, 270, 90)
        Else
            path.AddLine(rec.Right, rec.Y, rec.Right, rec.Y)
        End If
        'Set bottom-right corner.
        If Not exclude_BottomRight Then
            path.AddArc(rec.Right - s, rec.Bottom - s, s, s, 0, 90)
        Else
            path.AddLine(rec.Right, rec.Bottom, rec.Right, rec.Bottom)
        End If
        'Set bottom-left corner.
        If Not exclude_BottomLeft Then
            path.AddArc(rec.X, rec.Bottom - s, s, s, 90, 90)
        Else
            path.AddLine(rec.X, rec.Bottom, rec.X, rec.Bottom)
        End If
        'Set top-left corner.
        If Not exclude_TopLeft Then
            path.AddArc(rec.X, rec.Y, s, s, 180, 90)
        Else
            path.AddLine(rec.X, rec.Y, rec.X, rec.Y)
        End If
        path.CloseAllFigures()
        Return path
    End Function

    ''' <summary>
    ''' Rounds the corners of the newly created rectangle-shape region and returns the region.
    ''' </summary>
    ''' <param name="rSize">The size of the region.</param>
    ''' <param name="r">The radius of the rounded corners. This value should be 
    ''' bigger then 0 and less or equal to the (a half of the smallest value 
    ''' of the region�s width and height).</param>
    ''' <param name="exclude_TopLeft">A value that specifies if the top-left 
    ''' corner of the region should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_TopRight">A value that specifies if the top-right 
    ''' corner of the region should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_BottomRight">A value that specifies if the bottom-right 
    ''' corner of the region should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    ''' <param name="exclude_BottomLeft">A value that specifies if the bottom-left 
    ''' corner of the region should be rounded. If the value is True 
    ''' then the corner is not rounded otherwise it is.</param>
    Public Shared Function RoundedRegion(ByVal rSize As Size, ByVal r As Integer, _
    Optional ByVal exclude_TopLeft As Boolean = False, _
    Optional ByVal exclude_TopRight As Boolean = False, _
    Optional ByVal exclude_BottomRight As Boolean = False, _
    Optional ByVal exclude_BottomLeft As Boolean = False) As Region

        Dim s As Integer = r * 2
        Dim path As New GraphicsPath
        'If 's' is less than or equal to zero, 
        'then return a simple rectangle.
        If Not s > 0 Then
            path.StartFigure()
            path.AddLine(rSize.Width, 0, rSize.Width, 0)
            path.AddLine(rSize.Width, rSize.Height, rSize.Width, rSize.Height)
            path.AddLine(0, rSize.Height, 0, rSize.Height)
            path.AddLine(0, 0, 0, 0)
            path.CloseAllFigures()
            Return New Region(path)
        End If
        'If 's' is bigger than the smallest value of the size, 
        'then assign the value to 's'.
        If rSize.Height < rSize.Width Then
            If s > rSize.Height Then
                s = rSize.Height
            End If
        Else
            If s > rSize.Width Then
                s = rSize.Width
            End If
        End If
        path.StartFigure()
        'Set top-right corner.
        If Not exclude_TopRight Then
            path.AddArc(rSize.Width - s, 0, s - 1, s - 1, 270, 90)
        Else
            path.AddLine(rSize.Width, 0, rSize.Width, 0)
        End If
        'Set bottom-right corner.
        If Not exclude_BottomRight Then
            path.AddLine(rSize.Width, r, rSize.Width, rSize.Height - r)
            path.AddArc(rSize.Width - s, rSize.Height - s, s - 1, s - 1, 0, 90)
        Else
            path.AddLine(rSize.Width, rSize.Height, rSize.Width, rSize.Height)
        End If
        'Set bottom-left corner.
        If Not exclude_BottomLeft Then
            path.AddLine(rSize.Width - r, rSize.Height, r, rSize.Height)
            path.AddArc(0, rSize.Height - s, s - 1, s - 1, 90, 90)
        Else
            path.AddLine(0, rSize.Height, 0, rSize.Height)
        End If
        'Set top-left corner.
        If Not exclude_TopLeft Then
            path.AddArc(0, 0, s - 1, s - 1, 180, 90)
        Else
            path.AddLine(0, 0, 0, 0)
        End If
        path.CloseAllFigures()
        Return New Region(path)
    End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) ZipEdTech
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions