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.
Unfortunately, activation email could not send to your email. Please try again.

Tree navigator formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

125213 Jul 31,2016 04:39 AM Aug 3,2016 12:39 AM Windows Forms 7
loading
Tags: TreeNavigator
Nicolas
Asked On July 31, 2016 04:39 AM

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

Nicolas
Replied On August 1, 2016 03:45 AM

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


Nicolas
Replied On August 1, 2016 04:33 AM

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

Venkateshwaran Ramdoss [Syncfusion]
Replied On August 1, 2016 10:05 AM

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.

Nicolas
Replied On August 1, 2016 02:38 PM

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

Vijayalakshmi Roopkumar [Syncfusion]
Replied On August 2, 2016 11:06 AM

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. 


Nicolas
Replied On August 2, 2016 12:29 PM

Great work! Thank you! - Nicolas

Vijayalakshmi Roopkumar [Syncfusion]
Replied On August 3, 2016 12:39 AM

Hi Nicolas,

Thank you for your update.

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

Regards,
Vijayalakshmi V.R.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;