Click here to Skip to main content
12,075,783 members (33,931 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET VS2012
Hi, I have made a simple drawing program and would like to have a palette of the WebSafe colors to choose from. Is there a simple way to add the colors to a TableLayoutPanel? I was thinking something like:

For Each color in WebSafe Colors 'Would it be System.Drawing.WebSafeColors?
TableLayoutPanel.cells.add(color)
Next

I was also wondering if the TableLayoutPanel's cells, rows and columns are created the same as a DataGridView? Would I be able to click on a cell to choose it's color, or do I have to add controls to the cell? I basically just need to display a simple color swatch in a 15X15px square, that I can click to switch pen colors. Please help.
Posted 13-Apr-13 16:19pm
Comments
Sergey Alexandrovich Kryukov 13-Apr-13 21:51pm
   
Yes, you would be able to. However, if you are asking, I'm not sure about you, it depends on some skills you need to have.
Any problem?
—SA
7774tlas 13-Apr-13 22:25pm
   
Do the TableLayoutPanel's cells have a backcolor property? Would you give a short example of how to access a cell's properties/values? Also, can they be clicked, or do I have to write a click event?
   
This is simple: it's not about TableLayoutPanel, "painting" it in any colors makes no sense at all. You need to define the colors of the panel's children.
—SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You're not understanding what the TableLayoutPanel is or how it works. It really doesn't have any "cells". It's sole purpose in life is to control layout and sizing of controls placed within. There are no properties like you would find in a DataGridView or other visual control.

To get what you want, you'd have to put something like labels in those "cells" and set the backcolor of each label to the color you want.
  Permalink  
Comments
7774tlas 13-Apr-13 23:56pm
   
Thanks for the info. So the TLP is basically a grid for controls. I would need 168 controls, one for each color. Would that affect performance? If so, I believe I'm gonna use a button for the swatch and a combobox to list the colors - ( button.backcolor = combobox.text ). If not, I'd like to use a TLP for quick-select purposes. Using For Each I could just add a button to each cell, set it's dock property to fill, then add the color info to the button (backcolor & text), right? I hate to keep bothering you, but if you would be so gracious as to answer that question about the performance, I'd greatly appreciate it. Thanks again for your time and help!
Dave Kreskowiak 14-Apr-13 0:20am
   
Would that effect performance? Yes! The more controls you put on the form, the slower it is to redraw.

Forget using the TLP. It's not anywhere close to being a grid control. All it is is a shell to wrap around constituant controls and to control their size, location based on their anchoring and docking properties. That's all.

I'd use a custom drawn combo or listview for this.
7774tlas 14-Apr-13 0:57am
   
I was just checking out some of the custom comboboxes here on the site. I'll try to modify one to my needs. Thanks again!
   
Strong words, my respect; my 5.
—SA

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 13 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100