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. C#
  4. OwnerDraw TreeView: OnPaint(...)

OwnerDraw TreeView: OnPaint(...)

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 3 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.
  • S Offline
    S Offline
    STW
    wrote on last edited by
    #1

    Owner-Draw TreeView with SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint,true); Problem with the overriden OnPaint methode: I added two nodes. When the control appears the first time, the OnPaint() methode panits only the first node!? When I move the mouse over the invisible second node then OnPaint draw the second node(but goes through OnPaint twice!?). So the nodes ar only painted when I move the mouse over the nodes. Refresh() or Invalidate() changes nothing. What could that be? Any suggestions that the TreeView paints its nodes the first time?

    C 1 Reply Last reply
    0
    • S STW

      Owner-Draw TreeView with SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint,true); Problem with the overriden OnPaint methode: I added two nodes. When the control appears the first time, the OnPaint() methode panits only the first node!? When I move the mouse over the invisible second node then OnPaint draw the second node(but goes through OnPaint twice!?). So the nodes ar only painted when I move the mouse over the nodes. Refresh() or Invalidate() changes nothing. What could that be? Any suggestions that the TreeView paints its nodes the first time?

      C Offline
      C Offline
      Carlos H Perez
      wrote on last edited by
      #2

      You cannot be using OwnerDrawn support and "ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint" because they are two different, mutually exclusive things. In Windows you usually can paint a control in three ways: 1- OwnerDraw which is when you handle the OnDrawItema and OnMeasureItem messages. In this situation the control ask you to do the drawing of a particular item at right time. Some of the oldest controls support this techinque: menus, combo box, etc. 2- Custom draw. This is a more fine grained version of the OwnerDraw version, here you have the oportunity to draw just part of the item instead of assumming full resposabilty for the whole drawing. Some of the more sophisticated common controls support this technique: TreeView, ListView. 3-. User Paint: You do the whole drawing yourself. In this case you don't have any help but you have full control as to what to paint. This is what you need to use when you are going to write a control from scratch. This is by far the best technique to write powerful controls because you have totally control of the painting. One last thing: how are you using OwnerDraw techinque for the TreeView control? As far as I known the TreeView control does not support OnMeasureItem or OnDrawItem methods. You could use CustomDraw but only if you hack the support yourselve using the fact that the .NET TreeView is just a wrapper for the native TreeView control in the Common Control library. Regards, Carlos H. Perez

      S 1 Reply Last reply
      0
      • C Carlos H Perez

        You cannot be using OwnerDrawn support and "ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint" because they are two different, mutually exclusive things. In Windows you usually can paint a control in three ways: 1- OwnerDraw which is when you handle the OnDrawItema and OnMeasureItem messages. In this situation the control ask you to do the drawing of a particular item at right time. Some of the oldest controls support this techinque: menus, combo box, etc. 2- Custom draw. This is a more fine grained version of the OwnerDraw version, here you have the oportunity to draw just part of the item instead of assumming full resposabilty for the whole drawing. Some of the more sophisticated common controls support this technique: TreeView, ListView. 3-. User Paint: You do the whole drawing yourself. In this case you don't have any help but you have full control as to what to paint. This is what you need to use when you are going to write a control from scratch. This is by far the best technique to write powerful controls because you have totally control of the painting. One last thing: how are you using OwnerDraw techinque for the TreeView control? As far as I known the TreeView control does not support OnMeasureItem or OnDrawItem methods. You could use CustomDraw but only if you hack the support yourselve using the fact that the .NET TreeView is just a wrapper for the native TreeView control in the Common Control library. Regards, Carlos H. Perez

        S Offline
        S Offline
        STW
        wrote on last edited by
        #3

        Thank you very much for answer! I found now a Sample Solution which seams to be good. So I will try it with CustomDraw with WndProc(..). But I fear that it will flicker. It's really a problem that .NET not supplies OnDrawItem and OnMeasureItem for TreeView; that's why I have problems to solve it. I cannot understand this. OwnerDraw is - as I mean - often used; so why these Microsoft Programmers didn't implement it for us? One question: to do TreeView OwnerDraw with OnPaint(...); how could I do this? It would be very usefull because I can set the DoubleBuffer Flag and paintings are without flicker. I've tried but there were unlogical things happening; just the first item was painted. The rest of the items were only drawn when I moved the mouse over the other items? Strange. Can you help me? Thanks Stefan

        A 1 Reply Last reply
        0
        • S STW

          Thank you very much for answer! I found now a Sample Solution which seams to be good. So I will try it with CustomDraw with WndProc(..). But I fear that it will flicker. It's really a problem that .NET not supplies OnDrawItem and OnMeasureItem for TreeView; that's why I have problems to solve it. I cannot understand this. OwnerDraw is - as I mean - often used; so why these Microsoft Programmers didn't implement it for us? One question: to do TreeView OwnerDraw with OnPaint(...); how could I do this? It would be very usefull because I can set the DoubleBuffer Flag and paintings are without flicker. I've tried but there were unlogical things happening; just the first item was painted. The rest of the items were only drawn when I moved the mouse over the other items? Strange. Can you help me? Thanks Stefan

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          I use "CustomDraw" on my sample article TreeView control and flickering is almost non existing due in part to some technique that I use to draw the node in a double buffer that I passed to the tree control itself. I don't know what you are looking for but my article show pretty well how to CustomDraw the items. Regards, Carlos.

          A 1 Reply Last reply
          0
          • A Anonymous

            I use "CustomDraw" on my sample article TreeView control and flickering is almost non existing due in part to some technique that I use to draw the node in a double buffer that I passed to the tree control itself. I don't know what you are looking for but my article show pretty well how to CustomDraw the items. Regards, Carlos.

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            I've downloaded your article. I had some problems to make it to draw as I like. I could not really understand the following code: // Set the text and background text color to the window bakcground // text so that we don't see the text being painted tvcd.clrText = ColorUtil.RGB(ForegroundColor); tvcd.clrTextBk = ColorUtil.RGB(BackgroundColor); But now it works. Thanks Carlos! Stefan

            S 1 Reply Last reply
            0
            • A Anonymous

              I've downloaded your article. I had some problems to make it to draw as I like. I could not really understand the following code: // Set the text and background text color to the window bakcground // text so that we don't see the text being painted tvcd.clrText = ColorUtil.RGB(ForegroundColor); tvcd.clrTextBk = ColorUtil.RGB(BackgroundColor); But now it works. Thanks Carlos! Stefan

              S Offline
              S Offline
              STW
              wrote on last edited by
              #6

              Little problem: I copied your code and made my own TreeNodePainting. When I startup my application I want to select the first node; the first node is selected but not painted in the Focused Colors. When I click into the TreeView (where no nodes are) then the first node is selected. Can you help me what that could be and how to resolve this problem? Thanks Stefan

              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