2

Is there a way to add picturebox in between cells (or on top of borders). I've tried using single picturebox on top of the table and bring it to front draw over it and then send it to back, but it is no longer visible at that point.

This is table I'm using, it changes size on runtime

Terry BRETT
  • 319
  • 2
  • 11
  • No. It would probably help if you explained to us what you are trying to do. Are you trying to highlight a cell? – LarsTech Jan 30 '17 at 15:06
  • What you call *table* is `TableLayoutPanel`. Have you tried to set [`Control.BackgroundImage`](https://msdn.microsoft.com/en-us/library/system.windows.forms.control.backgroundimage(v=vs.110).aspx) of it? Also see [this](http://stackoverflow.com/q/4463363/1997232). – Sinatr Jan 30 '17 at 15:08
  • Yes I have. I'm trying to do a drag drop design form, where each cell represents a room, and I want to add doors between those rooms. – Terry BRETT Jan 30 '17 at 15:09
  • You can add additional cells for doors (empty/collapsing if no door). – Sinatr Jan 30 '17 at 15:12
  • So add smaller cells inbetween? Good idea, how would I collapse those? Is it possible to have like +/- kind of collapse? – Terry BRETT Jan 30 '17 at 15:14
  • Not related - but in your case suggest to consider WPF instead of Winforms. At least you can create WPF usercontrol and use it in Winforms if you want stay with winforms for rest of application. – Fabio Jan 30 '17 at 15:18
  • Each 'cell' can only hold __one__ control. Setting up the grid in a way to include walls seems the natural solution. – TaW Jan 30 '17 at 15:41
  • TLP is a container. So if you move a control onto it it gets added to the nearest cell. Is that what happend? Di you write any code ? – TaW Jan 30 '17 at 21:32
  • It adds control to the cell I'm dropping the control onto – Terry BRETT Feb 02 '17 at 09:01

1 Answers1

1

If you want to customise the appearance of your cells, you can write code in response to the CellPaint event. In Visual Studio:

  1. Click on your layout panel in the form designer
  2. Select the Events section in the Properties panel (the lightning bolt icon)
  3. Go down to CellPaint in the Appearance section and double-click on the right-hand side

Your handler is passed a TableLayoutCellPaintEventArgs argument which provides you with information about which cell needs painting (Row and Column), the dimensions (CellBounds), and also provides a graphics context in which to do your work (Graphics). This lets you fully customise whatever painting you want to do, whether it's images, lines or text, and you can overlay the existing contents.

There's more information here:

https://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.oncellpaint(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutcellpainteventargs(v=vs.110).aspx

You could also add narrow border cells in between your 'room' cells, depending on your graphics requirements, but you're not going to be able to overlap them with their neighbours' contents.

Dave R.
  • 7,206
  • 3
  • 30
  • 52