Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Highlight a column in tableLayoutPanel after a button click
 

Highlight a column in tableLayoutPanel after a button click

Hello fellow programmers!

I am new to events and delegates, so any help with the following problem would be greatly appreciated.
I need to update a column of a tableLayoutPanel after clicking a different button in the UI. I have started with the code from another post (thanks to Bob zhu - MSFT):

void Form122_Load(object sender, EventArgs e)

this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);

void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)

if (e.Row == 0 || e.Row == 2)

Graphics g = e.Graphics;

Rectangle r = e.CellBounds;

new SolidBrush(Color.Blue), r);


Now, instead of using

Form_Load(object sender, EventArgs e)

I need to use

Button1_Click(object sender, EventArgs e)


So, I think the problem is that the sender is different in both cases, and so are the EventArgs. How can this be overcome?


Thank you so much for your help

-Dave

David Vanderburgh  Friday, May 30, 2008 5:11 PM
You can try something like this

Code Snippet

void button1_Click(object sender, EventArgs e)

{

this.highlight = true;

this.tableLayoutPanel1.Invalidate();

}

private bool highlight = false;

void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)

{

//highlight the second column

if (highlight)

{

if (e.Column == 1)

{

e.Graphics.FillRectangle(Brushes.Coral, e.CellBounds);

}

}

}

Well, I found a workaround that is not exactly clean. I use

this.Refresh();

in order to redraw the GUI, but that looks choppy and shows some artifacts.
Hopefully you PROgrammers can find a more elegant solution.


Thanks in advance
-Dave

David Vanderburgh  Friday, May 30, 2008 11:40 PM
You can try something like this

Code Snippet

void button1_Click(object sender, EventArgs e)

{

this.highlight = true;

this.tableLayoutPanel1.Invalidate();

}

private bool highlight = false;

void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)

{

//highlight the second column

if (highlight)

{

if (e.Column == 1)

{

e.Graphics.FillRectangle(Brushes.Coral, e.CellBounds);

}

}

}

Thanks for the help! This works great Smile

-Dave

David Vanderburgh  Monday, June 02, 2008 3:00 PM

You can use google to search for other answers

Custom Search

More Threads

• How to add a button to datagrid column
• Change Location at design time problem
• Something happened to replace .aspx files with .resx and .designer.vb files
• different form height shown in the screen of notebook and desktop?
• Can you get to the open project or solution files while in a Designer in Design mode
• Multiple controls in a single DataGridView cell
• Error-Bug BindingSource in Designer :DataSource gives System.OutOfMemoryException
• trackbar with log scale
• screen.width
• Collection Property