Created
May 16, 2024 13:03
-
-
Save bjoerntx/2391a3fa1dabf3f12794b7adb18a6ef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void FormatSelectedTableCells(TableCellFormat cellFormat) | |
{ | |
Table table = textControl1.Tables.GetItem(); | |
if (table == null) | |
return; | |
Selection curSelection = new Selection( | |
textControl1.Selection.Start, | |
textControl1.Selection.Length); | |
// Clear the current selection | |
textControl1.Selection.Length = 0; | |
// Determine the starting row and column | |
TableCell tableCellStart = table.Cells.GetItem(); | |
int startRow = tableCellStart.Row; | |
int startCol = tableCellStart.Column; | |
// Set the selection to the last cell in the selected range | |
textControl1.Selection.Start = curSelection.Start + curSelection.Length - 1; | |
// Determine the ending row and column | |
TableCell tableCellEnd = table.Cells.GetItem(); | |
int endRow = tableCellEnd.Row; | |
int endCol = tableCellEnd.Column; | |
// Loop through the selected range and apply formatting | |
for (int row = startRow; row <= endRow; row++) | |
{ | |
for (int col = startCol; col <= endCol; col++) | |
{ | |
TableCell cell = table.Cells.GetItem(row, col); | |
cell.CellFormat = cellFormat; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment