Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Adjusting tables in relation to the page size

This source code snippet requires TX Text Control .NET
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 Download [9.04 KB, ZIP]
Click to enlarge

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.

  1. Private Sub resizeTable(ByVal tableID As Integer)
  2. Dim columns As Integer = TextControl1.Tables.GetItem(tableID).Columns.Count
  3. Dim rows As Integer = TextControl1.Tables.GetItem(tableID).Rows.Count
  4.  
  5. For i As Integer = 1 To rows
  6. Dim curWidth As Integer = 0
  7.  
  8. For e As Integer = 1 To columns
  9. curWidth += TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width()
  10. Next
  11.  
  12. Dim txWidth As Integer = TextControl1.Width * 15
  13. Dim percentageDelta As Double = (txWidth / curWidth)
  14.  
  15. For e As Integer = 1 To columns
  16. TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width = _
  17. TextControl1.Tables.GetItem(tableID).Cells.GetItem(i, e).Width * percentageDelta
  18. Next
  19. Next
  20. 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.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place