codecompleting codecompleting - 1 year ago 48
HTML Question

HtmlDocument in a winforms application, how to tell if text is overflowing?

I have a HtmlDocument object loaded in a winforms application (from a Web browser object).

I am referencing a specific html table in the html document.

Is there any way for me to know if the text from within that table is overflowing? (height or width).


If I know my html table has a hight of 200 pixels, would it be possible to count the lines of text and font size to come up with a pixel height count of the required height the content neads?

Answer Source

If you specify the Width and Height of Cells in your HTML Table (eg 200px), then you could use jquery to tell you if the cell size has changed indicating overflow. Copy this into an HTML file and give it a go:

  <script src=""></script>

<table border="1">
    <td width="50px">foo00000000000000000000</td>
    <td width="100px">bar</td>

Row: <input type="text" value="0">
Column: <input type="text" value="0">
Width of first cell: <span id="columnWidth">?</span><br>

<script type="text/javascript">
  $(function() {
var row = $('input:first').val();
var column = $('input:eq(1)').val();
var columnWidth = $('table tr:eq('+row+') td:eq('+column+')').width();

The foo000000000 cell is specified as 50px, but with all the zero's it overflows to 180px.