I have a class derived from a TableLayoutPanel and if I have more than 3 rows or columns I don't show them directly, I add(I let the object add) scrollbars so I can reach the other cells.
I have code that works perfectly,but...
public void CalculateSize()
{
const int cMaxCol = 3;
const int cMaxRow = 3;
const int cGap = 9;
int ColScr = 16; //size of scrollbar
int RowScr = 16; //size of scrollbar
int CC = 0;
int RC = 0;
if (ColumnCount > cMaxCol || RowCount > cMaxRow)
{
this.AutoScroll = true;
if (ColumnCount > cMaxCol)
{
CC = cMaxCol;
RC = this.RowCount;
ColScr = 0;
}
else
{
CC = this.ColumnCount;
RC = cMaxRow;
RowScr = 0;
}
}
else
{
this.AutoScroll = false;
CC = this.ColumnCount;
RC = this.RowCount;
}
this.Size = new Size((cCellWidth + cGap) * CC + ColScr, (cCellHeigth + cGap) * RC + RowScr);
}
Question : Why do I have to use if (ColumnCount > cMaxCol)twice? Can this be done more elegantly?
Googled for it but all I got was or-operator explanations ad nauseam.
Anyone any ideas?