| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic .NET |
| Version: | 1.0 |
| Released: | January 02, 2004 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Basic .NET |
| Download code: | tx_sample_dotnet_resize.zip |

In some applications, it is necessary to change the width of the table to fit the document width. In particular, if the document size is adjusted to the size of a form. Generally, the table will stay at its specified size, if the document width is changed.
This sample shows how to resize the table, so that it fits in to the new specified page size.
TX Text Control does not resize the table automatically, as the table layout should not be changed by changing the page size. If the width of the table is going to be changed, it is important to not change the relations of the table cell's width and height.
Therefore, it is necessary to calculate a ratio which is used to increase or decrease the table width. We use the difference between the whole table width and the new page size. This percentage ratio is used for every cell in every row to change the width.
Private Sub resizeTable(ByVal tableID As Integer) Dim columns As Integer = TextControl1.Tables.GetItem(tableID).Columns.Count Dim rows As Integer = TextControl1.Tables.GetItem(tableID).Rows.Count For i As Integer = 1 To rows Dim curWidth As Integer = 0 For e As Integer = 1 To columns curWidth += TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width() Next Dim txWidth As Integer = TextControl1.Width * 15 Dim percentageDelta As Double = (txWidth / curWidth) For e As Integer = 1 To columns TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width = _ TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width * percentageDelta Next Next End Sub
Try it yourself using the code example. Just start the applicaton and change the width of the form. The minimum requirements for this sample application are TX Text Control .NET trial version and Visual Studio .NET 2003.