Click here to Skip to main content
Click here to Skip to main content

Set Image as Background for DataGridView

By , 14 Feb 2007
 
Sample image

Introduction

I needed to set an image as the background of DataGridView. I searched the Internet but could not find anything useful, so I did it myself. It is easy and small; I have tested it and it is working ok. Before you use it, please test it.

How To Do It

Just create a new class and inherit it from DataGridView as follows:

Imports system.ComponentModel

Public Class usrDataGridView
    Inherits Windows.Forms.DataGridView

    Private m_Image As Drawing.Image

    Public Sub New()
        Me.m_Image = Drawing.Image.FromFile("c:\sisnetBG.jpg")
    End Sub

    Protected Overrides Sub PaintBackground(_
        ByVal graphics As System.Drawing.Graphics, _
        ByVal clipBounds As System.Drawing.Rectangle, _
        ByVal gridBounds As System.Drawing.Rectangle)
        MyBase.PaintBackground(graphics, clipBounds, gridBounds)

        graphics.DrawImage(Me.m_Image, gridBounds)

    End Sub

    <description("set /> _
    Public Property BackImage() As Drawing.Image
        Get
            Return Me.m_Image
        End Get
        Set(ByVal value As Drawing.Image)
            Me.m_Image = value
        End Set
    End Property

End Class

History

  • 14th February, 2007 -- Original version posted

License

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

About the Author

ELhajjNet
Lebanon Lebanon
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to apply it to the Form???membermhc200425 Aug '09 - 22:16 
QuestionHow to apply it to my formmemberjugnoginting4 Jul '09 - 0:48 
GeneralScroll ErrormemberArash Javadi26 Apr '09 - 12:41 
GeneralA couple of additionsmemberSnixtor5 Nov '08 - 11:35 
GeneralI need Source pleasememberElmurhaf4 Jul '08 - 11:14 
GeneralAbove Column Headersmemberhelitb28 Mar '07 - 3:06 
GeneralNice work! Here's how to get the rest of the imagememberPatrick Sears15 Feb '07 - 17:55 
GeneralRe: Nice work! Here's how to get the rest of the imagememberELhajjNet16 Feb '07 - 10:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 14 Feb 2007
Article Copyright 2007 by ELhajjNet
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid