Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to make viewback color of a propertygrid transparent

how to make viewback color of a propertygrid transparent

Scheduled Pinned Locked Moved Visual Basic
csstutorialquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartyK2007
    wrote on last edited by
    #1

    hello, the questions in the title. how would I do this. The reason is I am using a panel which has a gradient color scheme and I want to drop the property grid on the panel. But I dont want to ruin the gradient effect. Any Ideas?? thanks Martin

    life is a bowl of cherries go on take a byte

    D 1 Reply Last reply
    0
    • M MartyK2007

      hello, the questions in the title. how would I do this. The reason is I am using a panel which has a gradient color scheme and I want to drop the property grid on the panel. But I dont want to ruin the gradient effect. Any Ideas?? thanks Martin

      life is a bowl of cherries go on take a byte

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You can't do this without making your own PropertyGrid control and ownerdrawing the whole grid. The BackColor property of the PropertyGrid doesn't support Transparent.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You can't do this without making your own PropertyGrid control and ownerdrawing the whole grid. The BackColor property of the PropertyGrid doesn't support Transparent.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        M Offline
        M Offline
        MartyK2007
        wrote on last edited by
        #3

        thanks for that dave, speaking as a person who has never ever used VB's drawing commands and as someone who had a play at the weekend and got nowhere - how would I do that? any tips, ideas, code??? thanks Martin

        life is a bowl of cherries go on take a byte

        D 1 Reply Last reply
        0
        • M MartyK2007

          thanks for that dave, speaking as a person who has never ever used VB's drawing commands and as someone who had a play at the weekend and got nowhere - how would I do that? any tips, ideas, code??? thanks Martin

          life is a bowl of cherries go on take a byte

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You start with creating your own PropertyGrid class, inheriting from the existing class.

          Public Class MyPropertyGrid
          Inherits PropertyGrid
          .
          .
          .

          Then you override the OnPaint and/or OnPaintBackground methods and supply your own drawing code to draw everything you need. If you haven't used the drawing methods, or even have a basic understanding of how painting works, you're going to find this a frustrating process. Google for "vb.net drawing" for lots of examples and articles.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            You start with creating your own PropertyGrid class, inheriting from the existing class.

            Public Class MyPropertyGrid
            Inherits PropertyGrid
            .
            .
            .

            Then you override the OnPaint and/or OnPaintBackground methods and supply your own drawing code to draw everything you need. If you haven't used the drawing methods, or even have a basic understanding of how painting works, you're going to find this a frustrating process. Google for "vb.net drawing" for lots of examples and articles.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            M Offline
            M Offline
            MartyK2007
            wrote on last edited by
            #5

            hi, I have tried Public Class myProp Inherits PropertyGrid Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs) MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs) MyBase.OnPaint(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub but these dont seem to cover the area where the "view back color" paints. In actual fact they seem to paint on only one or two lines between the text time and the outer rim of the cocontroller area. thanks Martin

            life is a bowl of cherries go on take a byte

            D 1 Reply Last reply
            0
            • M MartyK2007

              hi, I have tried Public Class myProp Inherits PropertyGrid Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs) MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs) MyBase.OnPaint(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub but these dont seem to cover the area where the "view back color" paints. In actual fact they seem to paint on only one or two lines between the text time and the outer rim of the cocontroller area. thanks Martin

              life is a bowl of cherries go on take a byte

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              MartyK2007 wrote:

              Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs) MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub

              First, you don't create your own Graphics object. You'll find it in the PaintEventArgs that you're getting when your code is called.

              Dim g As Graphics = pevent.Graphics
              

              Your next mistake is that if you want to REPLACE the background functionality, you don't call the base classes OnPaintBackground method. That will paint the background of the control just like you didn't even attempt to make your own version of it. Third, the Graphics objects to DID create, you didn't Dispose of. This will, most assuredly, run your machine out of resources and your app will eventully crash with an OutOfMemoryException. On top of that, if you didn't create the object, like Graphics, you do NOT Dispose of it.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              M 1 Reply Last reply
              0
              • D Dave Kreskowiak

                MartyK2007 wrote:

                Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs) MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub

                First, you don't create your own Graphics object. You'll find it in the PaintEventArgs that you're getting when your code is called.

                Dim g As Graphics = pevent.Graphics
                

                Your next mistake is that if you want to REPLACE the background functionality, you don't call the base classes OnPaintBackground method. That will paint the background of the control just like you didn't even attempt to make your own version of it. Third, the Graphics objects to DID create, you didn't Dispose of. This will, most assuredly, run your machine out of resources and your app will eventully crash with an OutOfMemoryException. On top of that, if you didn't create the object, like Graphics, you do NOT Dispose of it.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                M Offline
                M Offline
                MartyK2007
                wrote on last edited by
                #7

                hey, this was just sample code and not clean in any way.

                Dave Kreskowiak wrote:

                Dim g As Graphics = pevent.Graphics

                er if you look at the snippet - thats exactly what I do MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics

                Dave Kreskowiak wrote:

                REPLACE the background functionality

                dont really want to replace them as overwrite on top of them thats why I ran this first. Interestingly enough if I dont run the base classes then I get the same result.

                Dave Kreskowiak wrote:

                Third, the Graphics objects to DID create, you didn't Dispose of

                absolutely - this is a proof of concept , rather that a clean solution. Of course I will dispose of them properly when the solution happens. My problem is that my color gradient only appears behind the propertygrid ( its its view back color area).Effectively this means a couple of lines at the top of the pG and a couple between the description block and the rest of the PG. Try it and see what I mean. I need to change the color of the view back color area to a gradient which is the bit where there is no properties left to display on the PG. Pick a class then use the category view and minimise ecah category - the coloured background at the bottom is what I am after. thanks Martin

                life is a bowl of cherries go on take a byte

                D 1 Reply Last reply
                0
                • M MartyK2007

                  hey, this was just sample code and not clean in any way.

                  Dave Kreskowiak wrote:

                  Dim g As Graphics = pevent.Graphics

                  er if you look at the snippet - thats exactly what I do MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics

                  Dave Kreskowiak wrote:

                  REPLACE the background functionality

                  dont really want to replace them as overwrite on top of them thats why I ran this first. Interestingly enough if I dont run the base classes then I get the same result.

                  Dave Kreskowiak wrote:

                  Third, the Graphics objects to DID create, you didn't Dispose of

                  absolutely - this is a proof of concept , rather that a clean solution. Of course I will dispose of them properly when the solution happens. My problem is that my color gradient only appears behind the propertygrid ( its its view back color area).Effectively this means a couple of lines at the top of the pG and a couple between the description block and the rest of the PG. Try it and see what I mean. I need to change the color of the view back color area to a gradient which is the bit where there is no properties left to display on the PG. Pick a class then use the category view and minimise ecah category - the coloured background at the bottom is what I am after. thanks Martin

                  life is a bowl of cherries go on take a byte

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  MartyK2007 wrote:

                  er if you look at the snippet - thats exactly what I do MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics

                  My bad! I misread your code! :->

                  MartyK2007 wrote:

                  dont really want to replace them as overwrite on top of them thats why I ran this first. Interestingly enough if I dont run the base classes then I get the same result.

                  In order to get a transparent background, you have to replace the background drawing code. That's what your original post said you wanted.

                  MartyK2007 wrote:

                  My problem is that my color gradient only appears behind the propertygrid ( its its view back color area).Effectively this means a couple of lines at the top of the pG and a couple between the description block and the rest of the PG.

                  This would mean that the background of each "cell" in the PG is painted by the foreground OnPaint method. You would have to replace the standard OnPaint drawing code with your own. This means that you have to paint the entire control yourself! Is it worth it?

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  M 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    MartyK2007 wrote:

                    er if you look at the snippet - thats exactly what I do MyBase.OnPaintBackground(pevent) Dim g As Graphics = pevent.Graphics

                    My bad! I misread your code! :->

                    MartyK2007 wrote:

                    dont really want to replace them as overwrite on top of them thats why I ran this first. Interestingly enough if I dont run the base classes then I get the same result.

                    In order to get a transparent background, you have to replace the background drawing code. That's what your original post said you wanted.

                    MartyK2007 wrote:

                    My problem is that my color gradient only appears behind the propertygrid ( its its view back color area).Effectively this means a couple of lines at the top of the pG and a couple between the description block and the rest of the PG.

                    This would mean that the background of each "cell" in the PG is painted by the foreground OnPaint method. You would have to replace the standard OnPaint drawing code with your own. This means that you have to paint the entire control yourself! Is it worth it?

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    M Offline
                    M Offline
                    MartyK2007
                    wrote on last edited by
                    #9

                    Dave Kreskowiak wrote:

                    replace the standard OnPaint drawing code with your own

                    hi, I have added this to the properties grid onpaint event Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs) ' MyBase.OnPaint(pevent) Dim g As Graphics = pevent.Graphics Dim gradBrush As System.Drawing.Drawing2D.LinearGradientBrush gradBrush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Me.Width, Me.Height), Color.Green, Color.Blue) ' g.FillRectangle(gradBrush, 0, 0, Me.Width, Me.Height) g.FillRectangle(gradBrush, pevent.ClipRectangle) End Sub and I expected the control contents to vanish and be replaced with a gradient colour but nothing happened. does this mean each cell has its own onpaint function?? if so how do I find them ???

                    Dave Kreskowiak wrote:

                    Is it worth it?

                    yes if I can - I am trying to have a consistant look n feel in my gui app. of course scroll bars seem to be a problem because I cant find where to cheange them either. so yes any help would be appreciated Martin thanks Martin

                    life is a bowl of cherries go on take a byte

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups