Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
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?
Sergey Alexandrovich Kryukov 14-Apr-13 1:11am    
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

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.
 
Share this answer
 
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!
Sergey Alexandrovich Kryukov 14-Apr-13 1:12am    
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)



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