C# Class SIL.FieldWorks.Common.Widgets.FwTextBox

FwTextBox is a simulation of a regular Windows.Forms.TextBox. It has much the same interface, though not all events and properties are yet supported. There are two main differences: (1) It is implemented using FieldWorks Views, and hence can render Graphite fonts properly. (2) You can read and write the contents as an ITsString, using the Tss property, allowing formatting to vary based on the properties of string runs. Although there is not yet any support for the user to alter run properties while inside the FwTextBox, it is possible to paste text from elsewhere in an FW application complete with style information. You must also pass your writing system factory to the FwTextBox (set the WritingSystemFactory property). Otherwise, the combo box will not be able to interpret the writing systems of any TsStrings it is asked to display. It will improve performance to do this even if you are not using TsString data.
Inheritance: System.Windows.Forms.UserControl, IFWDisposable, IVwNotifyChange, ISupportInitialize
Mostrar archivo Open project: sillsdev/FieldWorks Class Usage Examples

Private Properties

Property Type Description
CreateRenderer System.Windows.Forms.VisualStyles.VisualStyleRenderer
GetDympMaxHeight int
HandleKeyDown void
OnInnerTextBoxLostFocus void
SetPadding void
m_innerFwTextBox_GotFocus void
m_innerFwTextBox_MouseEnter void
m_innerFwTextBox_MouseLeave void

Public Methods

Method Description
AdjustForStyleSheet ( Form parent, Control grower, IVwStylesheet stylesheet ) : void

Assumes the control is part of a form and should use a stylesheet. This becomes the stylesheet of the text box. If, as a result, the preferred height of this becomes greater than its actual height, the height of this is adjusted to suit. In addition, if grower is not null (grower is typically a containing panel), the height of grower is increased by the same amount. Also, the height of the indicated form is increased, and any top level controls which need it are adjusted appropriately.

AdjustForStyleSheet ( Form parent, Control grower, XCore mediator ) : void

Adjust, figuring the stylesheet based on the main window of the mediator.

AdjustForStyleSheet ( IVwStylesheet ss ) : void

Adjust the height of the text box appropriately for the given stylesheet. This version moves any controls below the text box, but does not adjust the size of the parent control.

ApplyStyle ( string sStyle ) : void

Applies the specified style to the current selection of the Tss string

ApplyWS ( int hvoWs ) : void

Applies the specified writing system to the current selection

BeginInit ( ) : void

Required to implement ISupportInitialize.

CheckDisposed ( ) : void

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.

CreateBitmapOfText ( Padding margins, Rectangle content ) : Bitmap

Creates a bitmap and renders the text in this FwTextBox in the bitmap.

EndInit ( ) : void

When all properties have been initialized, this will be called.

FwTextBox ( ) : System

Default Constructor

PropChanged ( int hvo, int tag, int ivMin, int cvIns, int cvDel ) : void

RemoveSelection ( ) : void

Remove any selection from the text box.

ScrollSelectionIntoView ( ) : void

Scrolls the current selection into view.

Select ( int start, int length ) : void

Selects a range of text in the text box.

If you want to set the start position to the first character in the control's text, set the start parameter to 0. You can use this method to select a substring of text, such as when searching through the text of the control and replacing information. Note: You can programmatically move the caret within the text box by setting the start parameter to the position within the text box where you want the caret to move to and set the length parameter to a value of zero (0). The text box must have focus in order for the caret to be moved.

SelectAll ( ) : void

Selects all text in the text box.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Executes in two distinct scenarios. 1. If disposing is true, the method has been called directly or indirectly by a user's code via the Dispose method. Both managed and unmanaged resources can be disposed. 2. If disposing is false, the method has been called by the runtime from inside the finalizer and you should not reference (access) other managed objects, as they already have been garbage collected. Only unmanaged resources can be disposed.

If any exceptions are thrown, that is fine. If the method is being done in a finalizer, it will be ignored. If it is thrown by client code calling Dispose, it needs to be handled by fixing the bug. If subclasses override this method, they should call the base implementation.

OnPaint ( PaintEventArgs e ) : void

ScaleControl ( SizeF factor, BoundsSpecified specified ) : void

Scales a control's location, size, padding and margin.

Select ( bool directed, bool forward ) : void

Activates a child control.

Private Methods

Method Description
CreateRenderer ( TextBoxState state, bool focused, bool hasBorder ) : System.Windows.Forms.VisualStyles.VisualStyleRenderer
GetDympMaxHeight ( Control control ) : int

calculate the height of the edit boxes in millipoints.

HandleKeyDown ( KeyEventArgs e ) : void

Handles the key down.

OnInnerTextBoxLostFocus ( object sender, EventArgs e ) : void

When the inner fw text box loses focus, fire InnerTextBoxLostFocus.

SetPadding ( ) : void
m_innerFwTextBox_GotFocus ( object sender, EventArgs e ) : void

Handles the GotFocus event of the m_innerFwTextBox control.

m_innerFwTextBox_MouseEnter ( object sender, EventArgs e ) : void
m_innerFwTextBox_MouseLeave ( object sender, EventArgs e ) : void

Method Details

AdjustForStyleSheet() public method

Assumes the control is part of a form and should use a stylesheet. This becomes the stylesheet of the text box. If, as a result, the preferred height of this becomes greater than its actual height, the height of this is adjusted to suit. In addition, if grower is not null (grower is typically a containing panel), the height of grower is increased by the same amount. Also, the height of the indicated form is increased, and any top level controls which need it are adjusted appropriately.
public AdjustForStyleSheet ( Form parent, Control grower, IVwStylesheet stylesheet ) : void
parent System.Windows.Forms.Form The parent.
grower System.Windows.Forms.Control The grower.
stylesheet IVwStylesheet The stylesheet.
return void

AdjustForStyleSheet() public method

Adjust, figuring the stylesheet based on the main window of the mediator.
public AdjustForStyleSheet ( Form parent, Control grower, XCore mediator ) : void
parent System.Windows.Forms.Form
grower System.Windows.Forms.Control
mediator XCore
return void

AdjustForStyleSheet() public method

Adjust the height of the text box appropriately for the given stylesheet. This version moves any controls below the text box, but does not adjust the size of the parent control.
public AdjustForStyleSheet ( IVwStylesheet ss ) : void
ss IVwStylesheet
return void

ApplyStyle() public method

Applies the specified style to the current selection of the Tss string
public ApplyStyle ( string sStyle ) : void
sStyle string The name of the style to apply
return void

ApplyWS() public method

Applies the specified writing system to the current selection
public ApplyWS ( int hvoWs ) : void
hvoWs int The ID of the writing system to apply
return void

BeginInit() public method

Required to implement ISupportInitialize.
public BeginInit ( ) : void
return void

CheckDisposed() public method

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.
public CheckDisposed ( ) : void
return void

CreateBitmapOfText() public method

Creates a bitmap and renders the text in this FwTextBox in the bitmap.
public CreateBitmapOfText ( Padding margins, Rectangle content ) : Bitmap
margins Padding Rectangle with the margins.
content System.Drawing.Rectangle The rectangle that specifies the width and height of the content. ///
return System.Drawing.Bitmap

Dispose() protected method

Executes in two distinct scenarios. 1. If disposing is true, the method has been called directly or indirectly by a user's code via the Dispose method. Both managed and unmanaged resources can be disposed. 2. If disposing is false, the method has been called by the runtime from inside the finalizer and you should not reference (access) other managed objects, as they already have been garbage collected. Only unmanaged resources can be disposed.
If any exceptions are thrown, that is fine. If the method is being done in a finalizer, it will be ignored. If it is thrown by client code calling Dispose, it needs to be handled by fixing the bug. If subclasses override this method, they should call the base implementation.
protected Dispose ( bool disposing ) : void
disposing bool
return void

EndInit() public method

When all properties have been initialized, this will be called.
public EndInit ( ) : void
return void

FwTextBox() public method

Default Constructor
public FwTextBox ( ) : System
return System

OnPaint() protected method

protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs
return void

PropChanged() public method

public PropChanged ( int hvo, int tag, int ivMin, int cvIns, int cvDel ) : void
hvo int
tag int
ivMin int
cvIns int
cvDel int
return void

RemoveSelection() public method

Remove any selection from the text box.
public RemoveSelection ( ) : void
return void

ScaleControl() protected method

Scales a control's location, size, padding and margin.
protected ScaleControl ( SizeF factor, BoundsSpecified specified ) : void
factor SizeF The factor by which the height and width of the control will be /// scaled.
specified BoundsSpecified A value /// that specifies the bounds of the control to use when defining its size and position. ///
return void

ScrollSelectionIntoView() public method

Scrolls the current selection into view.
public ScrollSelectionIntoView ( ) : void
return void

Select() protected method

Activates a child control.
protected Select ( bool directed, bool forward ) : void
directed bool true to specify the direction of the control to select; otherwise, false.
forward bool true to move forward in the tab order; false to move backward in the tab order.
return void

Select() public method

Selects a range of text in the text box.
If you want to set the start position to the first character in the control's text, set the start parameter to 0. You can use this method to select a substring of text, such as when searching through the text of the control and replacing information. Note: You can programmatically move the caret within the text box by setting the start parameter to the position within the text box where you want the caret to move to and set the length parameter to a value of zero (0). The text box must have focus in order for the caret to be moved.
public Select ( int start, int length ) : void
start int The position of the first character in the current text selection /// within the text box.
length int The number of characters to select.
return void

SelectAll() public method

Selects all text in the text box.
public SelectAll ( ) : void
return void