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

How to implement imaginative view modes

This source code snippet requires TX Text Control ActiveX
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 Download [6.03 KB, 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.

  1. Private Sub AdjustPage()
  2. Const ScrollbarWidth = 300, TXMinZoom = 10, TXMaxZoom = 255,
  3. MinHeight = 720, MinWidth = 720
  4.  
  5. Dim nNewZoom As Integer, nWidth As Integer, nHeight As Integer
  6.  
  7. ' Autozoom
  8. If (mnuZoom.Checked) Then
  9. nNewZoom = 100 * (ScaleWidth - ScrollbarWidth) /
  10. (TXTextControl1.PageWidth - TXTextControl1.PageMarginL - TXTextControl1.PageMarginR)
  11.  
  12. ' Auto line break
  13. Else
  14. nNewZoom = 100
  15. If ScaleWidth > MinWidth Then
  16. TXTextControl1.PageWidth = ScaleWidth - ScrollbarWidth +
  17. TXTextControl1.PageMarginL + TXTextControl1.PageMarginR
  18. End If
  19. End If
  20.  
  21. If (nNewZoom < TXMinZoom) Then nNewZoom = TXMinZoom
  22. If (nNewZoom > TXMaxZoom) Then nNewZoom = TXMaxZoom
  23. TXTextControl1.ZoomFactor = nNewZoom
  24.  
  25. 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

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