Change TabControl Background to Gradient


Author
Message
Gary Smith
Gary Smith
Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)
Group: Forum Members
Posts: 39, Visits: 1
How would one go about changing the background color of the tabbed pages of a TabControl to the Gradient found on the other controls when using the NUIManagerController to define the look and feel of the application?  Buttons, panels etc appear with a Gradient but the pages of the TabControl are solid.


Angel Chorbadzhiev
Angel Chorbadzhiev
Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)
Group: Forum Members
Posts: 139, Visits: 184

Hi Gary,

I can think of 2 solutions:

1. You can drop on NUIPanel on the tab page and set its Dock property to Fill.

2. You can create your tab page class that inherits NTabPage and override OnPaintBackground method to fill itself with a gradient. Then instead of adding the NTabPage into the NTabControl.TabPages collection add instance of this new class.

Here is an implementation of this class:

Imports System.Drawing

Imports System.Drawing.Drawing2D

Imports Nevron.UI.WinForm.Controls

Public Class MyNTabPage

    Inherits NTabPage

    Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)

        Dim g As Graphics = e.Graphics

        Dim r As Rectangle = ClientRectangle

        Dim c1 As Color = Palette.ControlLight

        Dim c2 As Color = Palette.ControlDark

        Using brush As LinearGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)

            g.FillRectangle(brush, r)

        End Using

    End Sub

End Class

 

Regards,

Angel.


Gary Smith
Gary Smith
Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)
Group: Forum Members
Posts: 39, Visits: 1

Thanks for the help Angel. I can get it to work, but then the labels I add dynamically at run time dont have transparent backgrounds so it didnt work quite like I wanted, no fault of you or Nevrons controls...

Thanks

 


Angel Chorbadzhiev
Angel Chorbadzhiev
Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)
Group: Forum Members
Posts: 139, Visits: 184

Gary,

If these labels are standard .NET labels you can setup their back color to be transparent:

label1.BackColor = Color.Transparent


Gary Smith
Gary Smith
Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)
Group: Forum Members
Posts: 39, Visits: 1

Yes I tried that, but it didnt seem to make a difference. Then I read where the parent property must be set to the control its placed else it will be transparent to the form background color. so....

I'm adding labels in a loop dynamically at runtime to the NTabControl, so for each page of the NTabControl I do:

Dim nPanel As New NUIPanel
nPanel.Name =
"nPanel" & y.ToString
nPanel.Dock = DockStyle.Fill
nPanel.Parent = myDataPage(y)
myDataPage(y).Controls.Add(nPanel)
nPanel.SendToBack()

then in the inner loop that addes the labels to each page I do:

Dim
qLabel As New Label
myDataPage(y).Controls.Add(qLabel)
qLabel.Parent = nPanel
qLabel.BackColor = Color.Transparent
qLabel.BringToFront()

And this worked....weird...but it works....

Thanks for your help!


 


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic
1 active, 1 guest, 0 members, 0 anonymous
No members currently viewing this topic!

Login

Explore
Messages
Mentions
Search