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

| Author: | TX Text Control Support Department |
| Language: | Visual Basic |
| Version: | 1.1 |
| Released: | October 02, 2002 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control ActiveX with Visual Basic |
| Download code: | view_modes.zip |
This sample application originally appeared in the TX Text Control Newsletter - why not sign up today and receive sample code like this every week, directly to your Inbox.
As we are sure you can know: the days running up to a new version are always a bit on the stressful side. As a result, this week, we have only got a quick Top TX Tip.
Taking TX Text Control out of the box, it supports two different view modes. However, using a bit of imagination you can add a whole multitude of new ones.
How about 'Zoom-to-Page' mode? In this mode the zoom factor of the current TX Text Control is set so that the width of page is set to the window. As a result the entire width of the document can be seen.
What about 'Auto Line Break' mode? You can find such a mode in most e-mail programs. Take for example Netscape Messenger. Every time you pass a certain character - in most cases the 70th - the text is broken onto the next line. You can configure TX Text Control to break text at the edge of the window to create a very similar effect.
OK, sounds good. Tell me how I can perform such feats. To get us stared, we need the 'Simple' demonstration program shipped with TX Text Control. We are going to take this application as it is and add a few of these new view modes.
Out of the box, the 'Simple' sample program has two menu points, which allow us to switch between the various modes. The main change is in the AdjustPage method.
Private Sub AdjustPage() Const ScrollbarWidth = 300, TXMinZoom = 10, TXMaxZoom = 255, MinHeight = 720, MinWidth = 720 Dim nNewZoom As Integer, nWidth As Integer, nHeight As Integer ' Autozoom If (mnuZoom.Checked) Then nNewZoom = 100 * (ScaleWidth - ScrollbarWidth) / (TXTextControl1.PageWidth - TXTextControl1.PageMarginL - TXTextControl1.PageMarginR) ' Auto line break Else nNewZoom = 100 If ScaleWidth > MinWidth Then TXTextControl1.PageWidth = ScaleWidth - ScrollbarWidth + TXTextControl1.PageMarginL + TXTextControl1.PageMarginR End If End If If (nNewZoom < TXMinZoom) Then nNewZoom = TXMinZoom If (nNewZoom > TXMaxZoom) Then nNewZoom = TXMaxZoom TXTextControl1.ZoomFactor = nNewZoom End Sub
These methods are called from the Resize handler and changed to either the zoom factor of the TX Text Control or the page width - depending upon which mode is currently active.
In Autozoom mode we simply have to calculate the new zoom factor using the following rule of three:
100 % x %
------------- = --------------
Window width Document width
In the first case, we must not forget to subtract the scrollbar from the window width. Likewise, we have to subtract the margins from the document width, if they are not already 0. Finally, we have to check that the zoom factor is not outside the zoom factor that TX Text Control supports (10% to 255%). :-)
The auto line break mode is equally as easy to create. The zoom factor is simply set to 100%. If the ScaleWidth of the window is not smaller than the minimal width of the TX Text Control window, the PageWidth property is passed a new value. This is value is calculated with:
Window Width - Scrollbar - Width + Document Margins