Click here to Skip to main content
15,911,896 members
Home / Discussions / C#
   

C#

 
AnswerRe: Indexer Question Pin
harold aptroot8-Jun-10 6:10
harold aptroot8-Jun-10 6:10 
AnswerRe: Indexer Question Pin
T M Gray8-Jun-10 10:45
T M Gray8-Jun-10 10:45 
GeneralRe: Indexer Question Pin
harold aptroot8-Jun-10 10:56
harold aptroot8-Jun-10 10:56 
AnswerRe: Indexer Question Pin
LookSharp8-Jun-10 17:15
LookSharp8-Jun-10 17:15 
Questionmaking a text box more efficient Pin
codie30078-Jun-10 5:43
codie30078-Jun-10 5:43 
AnswerRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 6:23
mveDave Kreskowiak8-Jun-10 6:23 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 9:21
protectorAspDotNetDev8-Jun-10 9:21 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 10:12
mveDave Kreskowiak8-Jun-10 10:12 
aspdotnetdev wrote:
A new string need not be created each time text is appended to a textbox. As Luc said, you can use AppendText to add to a textbox


...which creates a new string... AppendText merely takes into account the current values of the Selection properties of the TextBox and replaces that text or appends text to that selection. In any case, the selected string is replaced or text is appended to the String, resulting in a new string being created and parsed when the control needs to render itself. The longer that string gets, the more time it takes to parse it and render what's visible.


aspdotnetdev wrote:
Textbox probably stores the text as an array of strings


No, it doesn't. It uses a String field all the way back up it's inheritance chain.


aspdotnetdev wrote:
and likely has special getters and setters for the Text property (e.g., if a line was added via AppendText, then add that to the string returned from Text when the getter is called).


Nope. If you open Reflector and lok for yourself, it's quite easy to see.

Here's the code for the Text property of the TextBox class:
Public Overrides Property [Text] As String
    Get
        Return MyBase.Text
    End Get
    Set(ByVal value As String)
        MyBase.Text = value
        Me.selectionSet = False
    End Set
End Property

...and for AppendText (comes from TextBoxBase):
Public Sub AppendText(ByVal [text] As String)
    If ([text].Length > 0) Then
        Dim num As Integer
        Dim num2 As Integer
        Me.GetSelectionStartAndLength(num, num2)
        Try 
            Dim endPosition As Integer = Me.GetEndPosition
            Me.SelectInternal(endPosition, endPosition, endPosition)
            Me.SelectedText = [text]
        Finally
            If ((MyBase.Width = 0) OrElse (MyBase.Height = 0)) Then
                Me.Select(num, num2)
            End If
        End Try
    End If
End Sub


There's nothing special in there.

As for WordWrap, that may or may not be a viable option depending on requirements. TextBox works with monolithic strings no matter what you do. ListBox works with an array of Objects and can handle much more of and more varied content than a TextBox can.

A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




GeneralRe: making a text box more efficient Pin
Pete O'Hanlon8-Jun-10 10:42
mvePete O'Hanlon8-Jun-10 10:42 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 12:09
mveDave Kreskowiak8-Jun-10 12:09 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 10:47
protectorAspDotNetDev8-Jun-10 10:47 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 11:03
sitebuilderLuc Pattyn8-Jun-10 11:03 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 12:45
protectorAspDotNetDev8-Jun-10 12:45 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 12:59
sitebuilderLuc Pattyn8-Jun-10 12:59 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 13:19
protectorAspDotNetDev8-Jun-10 13:19 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 13:26
sitebuilderLuc Pattyn8-Jun-10 13:26 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 13:59
protectorAspDotNetDev8-Jun-10 13:59 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:06
sitebuilderLuc Pattyn8-Jun-10 14:06 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 14:16
protectorAspDotNetDev8-Jun-10 14:16 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:28
sitebuilderLuc Pattyn8-Jun-10 14:28 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 12:24
mveDave Kreskowiak8-Jun-10 12:24 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 12:57
protectorAspDotNetDev8-Jun-10 12:57 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 17:21
mveDave Kreskowiak8-Jun-10 17:21 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 17:34
protectorAspDotNetDev8-Jun-10 17:34 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak9-Jun-10 2:03
mveDave Kreskowiak9-Jun-10 2:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.