We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Tree navigator formatting

Hi,

I would like to format the Tree navigator menu items for the font color at the runtime, and apparently what I did is not working, aka setting the forecolor of the item. Additionally, I was able to format the backcolor of the items through a loop of the items, but only reached the first level of the collections, what should I do to reach the sub-levels? Thank you in advance! - Nicolas

7 Replies

NI Nicolas August 1, 2016 07:45 AM UTC

Update : I have implemented a class to render the TreeMenuItems as gradient, and it works as expected (maybe a great adder for a next version). However, the item.SelectedColor and the Item.ItemHoverColor are not working anymore (it was working perfectly before I implement this new class) while the Item.SelectedItemForeColor is still working. In order to reproduce the behavior, I piggybacked on the TreeMenuItemEx Class for the setting of images on the items, created a BackgroundGradient property as Syncfusion.Drawing.BrushInfo, and set a FillRectangle as follows:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        If Me.BackgroundGradient IsNot Nothing Then
            Dim g As Graphics = e.Graphics
            Syncfusion.Drawing.BrushPaint.FillRectangle(g, New Rectangle(0, 0, Me.Width, Me.Height), Me.BackgroundGradient)
        End If
        If Me.ItemImage IsNot Nothing Then
            Dim textSize As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)
            Dim textwidth As Integer = CInt(Fix(Math.Ceiling(textSize.Width)))
            'Draw the Menu item image
            e.Graphics.DrawImage(Me.ItemImage, New Rectangle(Me.Width - 70, 10, 30, 30))
        End If
        MyBase.OnPaint(e)
    End Sub

Should I include some additional code in the PaintEvent in order to "reset" these 2 properties?

Yes, I know, it is a third question in the same topic, but as it is all related to this control, I believe it belongs here, thanks again for the great support! - Nicolas



NI Nicolas August 1, 2016 08:33 AM UTC

Update2: I was finally able to reach the lower levels by performing a loop inside the first loop to get through all the collection - it was an easy one, the other 2 issues remains - Thanks - Nicolas


VR Venkateshwaran Ramdoss Syncfusion Team August 1, 2016 02:05 PM UTC

Hi Nicolas,

Thank you for contacting Syncfusion Support.

In your code example, you have override the TreeMenuItem control. So TreeMenuItem base properties functionalities defined in its paint event will be overrided by the new implementation. Hence this bahavior occurs. Could you please provide complete information about your exact requirement which helpful us to provide prompt solution?

Regards,
Venkateshwaran V.R.


NI Nicolas August 1, 2016 06:38 PM UTC

Hi Venkateshwaran, you are absolutely right, when I comment out the fill rectangle line, I recover the "item.SelectedColor" and the Item.ItemHoverColor" properties, but unfortunately loosing the "Item.BackgroundGradient" property. 

After thinking, I do not mind loosing the "item.SelectedColor", but would like to keep the "Item.ItemHoverColor" property. My guess is that we should write a few lines in the OnPaint Overide, between the FillRectangle and DrawImage (in order to keep the image, while completely repaint the rectangle on a "Hover" event (a new FillRectangle, using probably Me.ItemHoverColor - or a transformation of it as it is in Color format instead of Brush or BrushInfo). When the mouse moves, the OnPaint will be called again, and repaint the rectangles according to mouse new position, and behave like any other normal hover repaint. My guess is that coding shoud be like this, but need to be adapted for catching Hover ONLY 

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

        If Me.BackgroundGradient IsNot Nothing Then
            Dim g As Graphics = e.Graphics
            Syncfusion.Drawing.BrushPaint.FillRectangle(g, New Rectangle(0, 0, Me.Width, Me.Height), Me.BackgroundGradient) '(Me.Width, 10, 30, 30))
        End If
        If Not IsNothing(ItemHoverColorEx) Then 'HERE NEED TO ADD LIMITING FACTORS TO CATCH HOVER ONLY
            Dim br As New SolidBrush(ItemHoverColorEx)
            e.Graphics.FillRectangle(br, New Rectangle(0, 0, Me.Width, Me.Height))
        End If
        If Me.ItemImage IsNot Nothing Then
            Dim textSize As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)
            Dim textwidth As Integer = CInt(Fix(Math.Ceiling(textSize.Width)))
            'Draw the Menu item image
            e.Graphics.DrawImage(Me.ItemImage, New Rectangle(Me.Width - 70, 10, 30, 30))
        End If
        MyBase.OnPaint(e)
    End Sub

oo, do not forget about the Item.Forecolor that is simply not working

Thank you! - Nicolas


VR Vijayalakshmi Roopkumar Syncfusion Team August 2, 2016 03:06 PM UTC

Hi Nicolas, 
Thank you for your update. 
We have prepared a sample that tries to meet your requirement according to your update. Please download the same from the following: 
Sample:Sample_New 
Regards, 
Vijayalakshmi V.R. 



NI Nicolas August 2, 2016 04:29 PM UTC

Great work! Thank you! - Nicolas


VR Vijayalakshmi Roopkumar Syncfusion Team August 3, 2016 04:39 AM UTC

Hi Nicolas,

Thank you for your update.

Please let us know if you need any further assistance on this.

Regards,
Vijayalakshmi V.R.

Loader.
Live Chat Icon For mobile
Up arrow icon