6 Replies - 226 Views - Last Post: 24 November 2017 - 04:14 PM Rate Topic: -----

#1 WizWazard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 24-November 17

Panel color sub or function

Posted 24 November 2017 - 01:10 PM

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 :) !

Is This A Good Question/Topic? 0
  • +

Replies To: Panel color sub or function

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: Panel color sub or function

Posted 24 November 2017 - 01:36 PM

I don't quite understand what you mean. Do you mean you have a Panel on each Form and you have several Forms in your Application Project?

How do you put these Panels on the Form(s), are you adding the panels in the designer window of the Form(s) or do you create the panels and add them to the Form(s) dynamically using code?

Do you want them all set to the same color?
Was This Post Helpful? 1
  • +
  • -

#3 WizWazard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 24-November 17

Re: Panel color sub or function

Posted 24 November 2017 - 02:26 PM

Yes I have the same panel on each form of my system and its set to 0c7ac0. I just copy and paste the panel from one form to another. Is there code which will stop me from copying and pasting the same code 6 times (as there are 6 forms in my system) so that it will set the color for the whole system.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: Panel color sub or function

Posted 24 November 2017 - 03:20 PM

If you copied and pasted the blue colored panel to each form in the designer (the easy way), then why would you want to do it in code? The panels on any forms you open would already be blue. Is it that you want to change the BackColor of the panels to different colors at different times throughout your code at runtime (while your app is running)?
Was This Post Helpful? 0
  • +
  • -

#5 WizWazard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 24-November 17

Re: Panel color sub or function

Posted 24 November 2017 - 03:27 PM

No because it is not a color specified by visual basic so i have to import it using Fromhmtl. But whenever i copy and paste it just gives the background color set to that panel
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,808
  • Joined: 01-February 13

Re: Panel color sub or function

Posted 24 November 2017 - 04:10 PM

You would not have to do it in code, you can specify any color in the Panel's BackColor property. However, it will not take an Html string for the color value though. Instead you would enter the Red, Green, and Blue channel values as integer values from 0 to 255 which in hex would be "00" to "FF". All the html string is specifying is the Red, Green, and Blue channel values of the color in a Hexadecimal string format. For an example, using your color 0c7ac0, it would be broke down as (Red="0c", Green="7a", and Blue="c0"). The integer value of each of those hexadecimal values would be ("0c" = 12), ("7a" = 122), and ("c0" = 192).

To set this color in the designer window BackColor property, do this... click on the panel's BackColor property in the designer window. Click the button on the right hand side in the BackColor property. That opens the tabbed window where you choose the color. Select the (Custom) tab and then right click on one of the blank colors at the bottom. That will open a color dialog where you can enter the red, green, and blue channel values as shown below. Then just click the (Add Color) button to use your custom color.

I suppose they did not give an option for setting the color using a hexadecimal string because, it is not used much in windows forms applications. It is more common to use 3 integer or byte values of 0 to 255.

Posted Image
Was This Post Helpful? 1
  • +
  • -

#7 WizWazard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 24-November 17

Re: Panel color sub or function

Posted 24 November 2017 - 04:14 PM

That is great you have resolve the problem ! thank you a lot !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1