OwnerDraw TreeView: OnPaint(...)
-
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?
-
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?
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
-
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
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
-
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
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.
-
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.
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
-
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
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