Category Archives: Drawing/Graphics

These posts or articles are based on drawing or related to graphics coding.

Free eBook: Patterns & Practices Application Architecture Guide 2.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (23 votes, average: 4.35 out of 5)

A while back Microsoft made available a new eBook for free called: Patterns and Pratices Application Architecture Guide 2.0

The download is about 3 megs of info and in the .pdf format. This book is should be very useful and helpful for .NET developers. Below are some of the features and Chapters in the free book.


Part I, Fundamentals
Part II, Design
Part III, Layers
Part IV, Archetypes


  • Foreword by S. Somasegar
  • Foreword by Scott Guthrie


  • Introduction
  • Architecture and Design Solutions At a Glance
  • Fast Track


Part I, Fundamentals

  • Chapter 1 – Fundamentals of Application Architecture
  • Chapter 2 – .NET Platform Overview
  • Chapter 3 – Architecture and Design Guidelines


Part II, Design

  • Chapter 4 – Designing Your Architecture
  • Chapter 5 – Deployment Patterns
  • Chapter 6 – Architectural Styles
  • Chapter 7 – Quality Attributes
  • Chapter 8 – Communication Guidelines


Part III, Layers

  • Chapter 9 – Layers and Tiers
  • Chapter 10 – Presentation Layer Guidelines
  • Chapter 11 – Business Layer Guidelines
  • Chapter 12 – Data Access Layer Guidelines
  • Chapter 13 – Service Layer Guidelines


Part IV, Archetypes

  • Chapter 14 – Application Archetypes
  • Chapter 15 – Web Applications
  • Chapter 16 – Rich Internet Applications (RIA)
  • Chapter 17 – Rich Client Applications
  • Chapter 18 – Services
  • Chapter 19 – Mobile Applications
  • Chapter 20 – Office Business Applications (OBA)
  • Chapter 21 – SharePoint Line-Of-Business (LOB) Applications



  • Cheat Sheet – patterns & practices Pattern Catalog
  • Cheat Sheet – Presentation Technology Matrix
  • Cheat Sheet – Data Access Technology Matrix
  • Cheat Sheet – Workflow Technology Matrix
  • Cheat Sheet – Integration Technology Matrix

As you can see, this book can be very useful and helpful for those programming using the .NET framework. I recommend you download and check it out. Have fun!


More Microsoft “How Do I” Video Updates and Service Pack 1 for 2008

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 4.00 out of 5)

I just wanted to mention that Microsoft officially launched the RTM version Service Pack 1 for Visual Studio 2008 a couple weeks ago. It includes many fixes and some other features and improvements. WPF (Windows Presentation Foundation) performance has been greatly increased as well. Click Here to check out the Service Pack for VB 2008.

Also Microsoft has been adding new How Do I videos for Visual Basic 2008 the past couple of months it appears. Its definitely worth checking out. It looks like Microsoft added many newer videos working with Excel and Microsoft Office and services. Linq and data-based programming looks to be updated as well. Remember that MSDN has many 2005 based videos as well. Anyways, Click Here if you want to check out the full list of MSDN’s “How Do I” video series. Have Fun!


How to Display Text in the System Tray/Notify Icon in VB.NET and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (9 votes, average: 3.56 out of 5)

You’ve probably seen some applications that are able to display what looks like text in the notify icon system tray. You may have noticed that the NotifyIcon control we use in VB.NET has no feature for displaying actual text in the tray So, how could you show text in the icon tray like other applications do? A simple little trick will display your icon as text.

More Info…

You actually have to make a bitmap in memory, draw the text you want to display, and use that bitmap you made as the icon to show in the system tray or notify area as some call it. This article has full sample code to accomplish this using Visual Basic.NET, Visual Basic 2008, VB 2010, and Visual Basic 2013. You can also download an example for doing this by clicking here.

Unfortunately there is only about 16×16 pixels of space for your icon text. So it will definitely limit the amount of text you can show in each spot. You should experiment with different Font Types and Font Sizes to get the best results. I also recommend you set the TextRenderingHint property to a higher quality setting like AntiAliasing which could make the text look much better compared to the default rendering hint. Also try to fine tune the position of the text drawn on your Icon to make full use of the icon area.

Getting Started…

The first thing you want to do once you open up your project is add a NotifyIcon component to your project from the Toolbox. I named mine “notifyText”. You can also add a context menu to be used during a Right Mouse Click. Go to the Notify Icon Properties and under the ContextMenu option select the context menu if you added one. If you want, under the ‘Text’ property you can set the Tooltip Text for when the Mouse is hovering over the Notify Icon in the System Tray. There are also some events for the Notify Icon if you want to make use of them like _MouseDown, _DoubleClick, etc.

Visual Basic.NET, Visual Basic 2008, VB 2010, and Higher Source Code…

The first code is a “DestroyIcon” API Function I use to completely destroy/remove the icon from existance when i’m done with it. IF you do get a generic gdi+ error (or it may just say a Generic Error has Occured? I don’t remember), then try using this API call to kill the Icon you created in memory. I made an app that will display and update the cpu clockspeed/usage in the tray update every second or so and that Generic Error would popup every once in awhile and not really say much about it except it had something to do with something in the icon code. This function is good to use anyways to release the resources used by the icon.

    'I'm using this in the createTextIcon sub to releases all of the resources that the icon/icons would have used.
    Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Int32) As Int32

Remember to optimize your text icon as much as you can so you can take full advantage of the limited space you have available for clarity. Set the “System.Drawing.Text.TextRenderingHint” to “System.Drawing.Text.TextRenderingHint.AntiAlias” to get smoother and easier to read text. You should setup the font and X/Y coordinates to make full use of the small space. And of course select a brush color that the user would be able to see well.

The code here is the declaration based code for variables and such…

    'You should fine tune the font you want to use so the user can see the text you want them to see.
    'Certain Fonts will obviously display your text better than other fonts might.
    Dim fontToUse As Font = New Font("Microsoft Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Pixel)

    'A basic brush with a Dark Blue Color. This should show up pretty well in the icon tray if the user uses the default tray color.
    Dim brushToUse As Brush = New SolidBrush(Color.DarkBlue)

    'A bitmap used to setup how the icon will display.
    Dim bitmapText As Bitmap = New Bitmap(16, 16)

    'A simply Grahics object to draw the text to a bitmap.
    Dim g As Graphics = Drawing.Graphics.FromImage(bitmapText)

    'Will be used to get the Handle to the bitmap Icon.
    Dim hIcon As IntPtr

The code below will draw the text onto the bitmap image and set the notify icon to display it by using its handle.

    'This code was actually taken from my CPUMonLite Application which displays the processors clockspeed in
    'the system tray. But the clockspeed code is removed
    Sub createTextIcon()


            'Clear any previous ‘stuff’ instead of creating a new bitmap.

            'Setup the text, font, brush, and position for the system tray icon. For the font type and
            'size I used, a good position for the X coordinate is a -1 or -2. And the Y coordinate seems
            'to work well at a 5.
            'You specify the actual text you want to be displayed in the draw string parameter that you
            'want to display in the notify area of the system tray. You will only be able to display a
            'few characters, depending on the font, size of the font, and the coordinates you used.
            g.DrawString("Text!", fontToUse, brushToUse, -2, 5)

            'Get a handle to the bitmap as a Icon.
            hIcon = (bitmapText.GetHicon)

            'Display that new usage value image in the system tray.
            notifyText.Icon = Drawing.Icon.FromHandle(hIcon)

            'Added this to try and get away from a rare Generic Error from the code above. Using this API Function seems to have stopped that error from happening.

        Catch exc As Exception

            MessageBox.Show(exc.InnerException.ToString, "Somethings not right?", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub


The code from this article in use!


Now all you have to do is call that Sub above each time you want the text to change/update in the System Tray! Hopefully I made some sense in this article and you were able to follow ok. Have fun!


Minor Revision: 2014

How to Easily add a Preconfigured SplashScreen with Visual Basic 08, VB 2010, and newer

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)

This little tip is only to show how to very simply add a default Preconfigured Splashscreen to your project, not really anything beyond that 🙂 This feature is available in VB 2005, Visual Basic.NET 2008, Visual Basic 2010, and higher. The first thing you want to do is goto the “Project” menu and click on.. “Add New Item”. IT will then display a window with the available objects you can add to your project. Find and Click on the “SplashScreen” object. IT will then add the object to your project. Now all you have to do is simply go back to the “Project” menu and click on your projects “Properties” selection. On the “Application” tab your will see a option for “Splash Screen”. In that combobox simply select the new Splash Screen form you added earlier. Now your project will show that splash form when your program is loading. The default splashscreen is probably not how you want it to be for your application, so you can design the splashscreen form however you like. There is a feature for your Splashscreen that you might want to use. Its called: MinimumSplashScreenDisplayTime. As the name suggests, it will set the minimum time that your splashscreen will be visible via a milli-seconds value. IF you set it to 5000(ms), then your splashscreen will stay opened for 5 seconds before your main application form is loaded. Edit: Click here to see how to add the code  in Application Events. Example:

My.Application.MinimumSplashScreenDisplayTime = 1000

Well, that’s all there is to it to add a preconfigured default Splash screen form to your projects. Remember this tip will ONLY work with Visual Basic 2005 and Visual Basic 2008. Or as some like to call Visual Basic 8 and Visual Basic 9. Have fun 🙂


Revised: 2015

Easy way to take a screenshot in VB 2008 and Visual Basic.NET 2010

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

The newer 2.0 version of the DotNET Framework added alot of new features. One of them is the ability to natively copy the visual contents of the screen. You can find this Sub() under the: System.Drawing.Graphics namespace named – ‘CopyFromScreen’. The ‘CopyFromScreen’ Sub has 4x overloads. You can specify the Destination coordinates to put the image and the Source coordinates to get the image. Also available is CopyPixelOperation which allows you to select the way you want to copy the pixels. System.Drawing.CopyPixelOperation.SourceCopy is the most common operation. Below is a simple demonstration to take a screenshot in your applications.

This basic sample only needs a picturebox.

'Copy the screen contents to the picturebox control. Select the X and Y positions to get the‘screens image,
'then select the X,Y positions to set the screen image to the picturebox control.
'You then simply specify how much of the image you want to copy. picScreen is the name of the picturebox I used.

picScreen.CreateGraphics.CopyFromScreen(0, 0, 0, 0, New Size(100, 100))

How to Draw String on a Form or Control using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This will draw a string on the WindowsForm using Visual Basic.NET

'create a new brush with a single, solid color

Dim myBrush AsNew SolidBrush(Color.Purple)

'create a new basic font. you can mess around and make it cooler

Dim f As Font = New Font(Font.Bold, 20)

'draw the string onto the form. At Position (0 left), (10 top)

Me.CreateGraphics.DrawString("Hello, This is just a test!", f, myBrush, 0, 10)

Draw Gradient on Form using VB.NET and GDI+

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

How to use VB.NET and GDI+ to draw a gradient backcolor on the windows forms background.

        'In the Form_Paint event. Put the following code:
        'create a new recatangle
        Dim rec As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
        'Create a new brush. Make is a Gradient style brush.
        Dim myBrush As Brush = New Drawing.Drawing2D.LinearGradientBrush(rec, Color.Aqua, _
          Color.Yellow, Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal)
        'draw the gradient onto the form.
        e.Graphics.FillRectangle(myBrush, rec)

Clear the Drawing Surface using VB.NET and GDI+

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Clears the drawing surfice using GDI+ and VB.NET

        'Change e to whatever your graphics variable is.
        'Change Black to whatever you want the color to be

Add all Known GDI+ Web Colors to a Combobox or Listbox control.

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This will add the list of all known colors to a combobox or listbox control.

Imports System.Drawing


Dim kColor As KnownColor

For kColor = KnownColor.AliceBlue To KnownColor.YellowGreen