

The latest beta implementation of Microsoft Word introduces a new formatting bar that is displayed where it is required. If a part of the text is selected, a small button bar with the most important formatting features, such as bold or italic, is displayed.
This sample shows how to implement such a context formatting bar, complete with fading effects. The formatting bar fades in when the mouse moves over the selected text.
Implementing such functionality is easy with TX Text Control: We simply use the TX Text Control button bar, remove some buttons and display it on a transparent form. The opacity value is dependent upon the distance between the mouse cursor and the selection.
We do not need to worry about the formatting itself, as this is completely encapsulated in the ButtonBar class. The only complicated part of this algorithm is the positioning of the button bar at the current selection. We use the InputPosition class to get the current input location. Additionally, the current scroll location and the position of the parent form must be included in the calculation.
The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial version and Visual Studio .NET 2003.