Click here to Skip to main content
15,920,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !

I am designing a system in vb.net and I would like to make a more efficient way of coloring a panel that I have on my forms in my system. so currently I have this piece of code to get an exact hex color :

Panel1.BackColor = ColorTranslator.FromHtml("#0c7ac0") 'Providing Blue Panel

Is there anyway that I can create a function or sub whereby I just need to call to instead of rewritting this for every form

really appreciate any help :) !

What I have tried:

I tried making a public sub but it only works for that form
Posted
Updated 24-Nov-17 10:16am
Comments
CHill60 24-Nov-17 15:17pm    
Pass the control as a parameter

1 solution

You can subclass the Panel class, giving it the color you want. then use this custom panel subclass in all your forms.
VB.NET
Public Class CustomPanel Inherits Panel

   Public Sub New()
      Me.BackColor = ColorTranslator.FromHtml("#0c7ac0")
   End Sub

End Class
 
Share this answer
 
v4
Comments
Member 13539907 24-Nov-17 16:32pm    
I am new in programming so i am getting errors sorry to be a pain can you expand

Appreciate the help !!!
phil.o 24-Nov-17 17:41pm    
Member 13539907 24-Nov-17 18:14pm    
The link posted is great and has resolved the errors, really appreciate it !
phil.o 24-Nov-17 18:17pm    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900