Windows Develop Bookmark and Share   
 index > Windows Forms General > Howto reduce long text to view region in the textbox with the finalize "..."
 

Howto reduce long text to view region in the textbox with the finalize "..."

I need reduce long text to view region in the textbox with the finalize "..."

Sample:

Source text: "Intel(R) 82801EB USB Universal Host Controller - 24D2"
Showed: "Intel(R) 82801EB USB Universal Host Contr"
Need: "Intel(R) 82801EB USB Universal Host Con..." and show tooltips over control with full source text.

How I can do it with use MS VB.NET?
a_Aleksey_  Thursday, October 04, 2007 12:19 PM

_Aleksey_,

How about next solution.
- draw formatted text on label/panel subclass(with tooltip) Having a reference toinput text box You can use itsstyles.
- use textbox for input(without any changes).
- when textbox loses focus - it is send backwards(ZOrder) or simply made hidden.
- label/panel subclass must have input textbox reference to ensure appropriate visualization.
- when label/panel subclass is hit using mouse it is send backwards(ZOrder) or made hidden.Or when textbox acquires focus(pressing Tab or explicitly) the same it will be change its visibility with label/panel subclass or they will change their position accoringto ZOrder.

Both controls could be added to UserControl and all focus changing logic could be incapsulated there.


Hope this helps.
Regards,
Oleh.

Oleh Svintsitskyy  Monday, October 08, 2007 1:15 PM

Hi _Alexey_,

You will have to control text box redering by inheriting it and overiding OnPaint().

In order to show trailing spaces use StringFormat classand updateTrimming propertyto Your needs along with FormatFlags property.Use DrawString overload which accepts StringFormat.

Regards,

Oleh.

Oleh Svintsitskyy  Friday, October 05, 2007 5:51 AM

Good day.

I am define own class:

Public Class clsOwnTextBox

Inherits System.Windows.Forms.TextBox

Public Sub New()

MyBase.New()

Dim l_ControlStyles As ControlStyles

Dim l_bBool As Boolean = MyBase.GetStyle(l_ControlStyles)

SetStyle(l_ControlStyles Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)

End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

MyBase.OnPaint(e)

Dim l_TextFormat As New StringFormat

l_TextFormat.Trimming = StringTrimming.EllipsisWord

e.Graphics.DrawString(Me.Text, Me.Font, Brushes.Black, Me.ClientRectangle, l_TextFormat)

End Sub

End Class

But, when control got focus, string is displayed in another font. What can I do to fix this?
a_Aleksey_  Monday, October 08, 2007 3:43 AM

Hi _Aleksey_,

Looks like TextBox is a shell control wrapper.
It does not invalidate itself(no WM_PAINT message) when selection changes or text changes.

Even whenIfiltered needed messages and invalidated textbox
- ellipsises were not draw where they should be.
- caret was not in correct place.
- selection rendering must be controlled also.

May it would be better to use text box for input only and draw its content on a label or panel subclass.

Regards,

Oleh.

Oleh Svintsitskyy  Monday, October 08, 2007 6:56 AM
Good day.

I have a task to display text in the control in the specified way:
- show formated string and tooltips with full string, when control is not in focus;
- show full string and allow to select/copy it, when control is focused.

Regards,
Aleksey
a_Aleksey_  Monday, October 08, 2007 8:37 AM

_Aleksey_,

How about next solution.
- draw formatted text on label/panel subclass(with tooltip) Having a reference toinput text box You can use itsstyles.
- use textbox for input(without any changes).
- when textbox loses focus - it is send backwards(ZOrder) or simply made hidden.
- label/panel subclass must have input textbox reference to ensure appropriate visualization.
- when label/panel subclass is hit using mouse it is send backwards(ZOrder) or made hidden.Or when textbox acquires focus(pressing Tab or explicitly) the same it will be change its visibility with label/panel subclass or they will change their position accoringto ZOrder.

Both controls could be added to UserControl and all focus changing logic could be incapsulated there.


Hope this helps.
Regards,
Oleh.

Oleh Svintsitskyy  Monday, October 08, 2007 1:15 PM

You can use google to search for other answers

Custom Search

More Threads

• Enable Back option in web browser's context menu
• VS.NET 2005 BETA2 vs VS.NET 2005 BETA1
• I can't expose Text property from my custom control to Properties window
• Using MS Office to do a mail merge
• ToolStripControlHost Serious Bug related to Docking
• Possible Bug: ContextMenuStrip Close Disables MouseMove Events in UserControl
• Object Disposed Exception when using Form's X button
• inherited user control class
• Transfering files over internet using Windows Form
• difference between as and =