textbox maxlength

G

Guest

Hi,

I looked everywhere for a reference to this, and I'm surprised that no one
else (apparently) has run into this problem.

I am using a textBox to collect/display messages as they are created in my
system. I append them to the current Text contents using the AppendText()
method. I never had problems with this until I moved to studio 2003 with
SP2. Now, no matter what I set my maxlength to (0, 500K, etc ...), the
AppendText() stops working once the buffer size reaches 32k. I'm sure it has
something to do with the SP2 patches related to overflowing buffers, but I
have no idea how to fix this (I definitely want to be able to put more than
32k into the textbox)

Any ideas ?

thanks,
mark
 
J

Jeff Gaines

Hi,

I looked everywhere for a reference to this, and I'm surprised that
no one else (apparently) has run into this problem.

I am using a textBox to collect/display messages as they are created
in my system. I append them to the current Text contents using the
AppendText() method. I never had problems with this until I moved to
studio 2003 with SP2. Now, no matter what I set my maxlength to (0,
500K, etc ...), the AppendText() stops working once the buffer size
reaches 32k. I'm sure it has something to do with the SP2 patches
related to overflowing buffers, but I have no idea how to fix this (I
definitely want to be able to put more than 32k into the textbox)

Any ideas ?

thanks,
mark

The TextBox has always had a 32K limit, you need to use a RichTextBox
if you need more room.
 
J

Jacky Kwok

Jeff said:
The TextBox has always had a 32K limit, you need to use a RichTextBox
if you need more room.


1. In Win32 OS, the TextBox has no 32K/64K limitation. It is just
default setting.

In Dotnet1.0, set the TextBox.MaxLength=0 can remove the limitation.

2. I had encountered this problem in Dotnet1.1 release, not only in
"studio 2003 with SP2" (in fact, I do not know what is "studio 2003 with
SP2". VS2003 using Dotnet1.1, Dotnet1.1 should have sp1 only).


In my case, I found that the problem is in the "TextBox.AppendText"
fucntion. It cannot add more text if the TextBox has contained 32K
characters even the TextBox.MaxLength=0.

I solve the problem by can the API

//for solve the dotnet1.1 bug of textbox cannot append text more than
32767 chars

[DllImport("User32.dll", EntryPoint="SendMessageW",CharSet=CharSet.Unicode)]
private static extern int SetSel(
IntPtr hWnd, //HWND hWnd,
uint Msg, //UINT Msg,
uint wParam, //WPARAM wParam,
int lParam //LPARAM lParam
);

[DllImport("user32.dll", EntryPoint="SendMessageW",CharSet=CharSet.Unicode)]
private static extern int ReplaceSel(
IntPtr hWnd, //HWND hWnd,
uint Msg, //UINT Msg,
uint wParam, //WPARAM wParam,
string lParam //LPARAM lParam
);

const uint EM_SETLIMITTEXT=0x00C5;
const uint EM_SETSEL=0x00B1;
const uint EM_REPLACESEL=0x00C2;

private void TextBoxAppendText(TextBox textbox,string message)
{
int pos=textbox.Text.Length;
SetSel(textbox.Handle,EM_SETSEL,(uint)pos,pos);//start pos ,end pos
ReplaceSel(textbox.Handle,EM_REPLACESEL,0,message);//not undo,
}


////
You can try can this method solve your problem.
 
J

Jeff Gaines

1. In Win32 OS, the TextBox has no 32K/64K limitation. It is just
default setting.

The help file for VS.NET says that you may enter up to 32KB of text in
a TextBox, is the help wrong?
 
G

Guest

Jeff - I was putting 500k of text in a text box with the 1.0 release, so 32k
is definitely a new limitation ..

based upon Claes' reply, I'm going to assume it's a new bug/feature ...

I'm going to try Jacky's solution to work around it

thanks for the replies!
 
J

Jeff Gaines

Jeff - I was putting 500k of text in a text box with the 1.0 release,
so 32k is definitely a new limitation ..

based upon Claes' reply, I'm going to assume it's a new bug/feature
...

I'm going to try Jacky's solution to work around it

thanks for the replies!

The Lord Bill giveth and the Lord Bill taketh away :)

There's always been a 32K limit since VB1 from memory, I would think
that V1 may be the aberration but who knows what the next version will
bring?
 
J

Jacky Kwok

Jeff said:
The help file for VS.NET says that you may enter up to 32KB of text in
a TextBox, is the help wrong?


The 64KB limitation is inherited from the old 16 bit windows because of
the 64KB segment limitation.

After the true 32 bit NT kernel windows (NT,2000,XP,2003), there is no
64KB limitation. The 32K(unicode)/64K(byte) limitation is just the
default behavior (it is no reason to allow a textbox to use all the memory).

Since Dotnet using Unicode, the default limitation of "length" in
textbox is 32K Unicode characters.

Change the TextBox.MaxLength of TextBox can change the limitation. From
the MSDN document, "TextBoxBase.MaxLength Property"

///
You can use this property to restrict the length of text entered in the
control for values such as postal codes and telephone numbers, or to
restrict the length of text entered when the data is to be entered in a
database. You can limit the text entered into the control to the maximum
length of the corresponding field in the database.

Note In code, you can set the value of the Text property to a value
that has a length greater than the value specified by the MaxLength
property. This property only affects text entered into the control at
run time.
Windows NT 4.0, Windows 2000, Windows Server 2003 family Platform Note:
For single line text box controls, if the MaxLength property is set to
0, the maximum number of characters the user can enter is 2147483646 or
an amount based on available memory, whichever is smaller. For multiline
text box controls, the maximum number of characters the user can enter
is 4294967295 or an amount based on available memory, whichever is smaller.

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium
Edition Platform Note: For single line text box controls, if the
MaxLength property is set to 0, the maximum number of characters the
user can enter is 32,766 or an amount based on available memory,
whichever is smaller. For multiline text box controls, the maximum
number of characters the user can enter is 65,535 or an amount based on
available memory, whichever is smaller.
/////

In Dotnet 1.1, the textbox still cannot contains more than 32K
chatacters after changes the MaxLength to 0 or other value > 32767.

Hence, it is bug in Dotnet 1.1.
I do not check the behavior in Dotnet1.1 sp1. Maybe someone check is the
bug fixed in Dotnet1.1 sp1.
 
C

Claes Bergefall

The help file for VS.NET says that you may enter up to 32KB of text in
a TextBox, is the help wrong?

Your help is wrong
In mine it says this:

[TextBoxBase.Text property]

Windows 98, Windows Millennium Edition Platform Note: The amount of text
that can be stored in the Text property is limited to 65KB of memory for the
TextBox control.

Windows NT 4.0, Windows 2000, Windows Server 2003 family Platform Note: The
amount of text that can be stored in the Text property is limited to the
amount available system memory.


[TextBoxBase.MaxLength property]

Windows NT 4.0, Windows 2000, Windows Server 2003 family Platform Note: For
single line text box controls, if the MaxLength property is set to 0, the
maximum number of characters the user can enter is 2147483646 or an amount
based on available memory, whichever is smaller. For multiline text box
controls, the maximum number of characters the user can enter is 4294967295
or an amount based on available memory, whichever is smaller.

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium
Edition Platform Note: For single line text box controls, if the MaxLength
property is set to 0, the maximum number of characters the user can enter is
32,766 or an amount based on available memory, whichever is smaller. For
multiline text box controls, the maximum number of characters the user can
enter is 65,535 or an amount based on available memory, whichever is
smaller.
--------------

And as I said before, it's a bug in AppendText that was introduced in
1.1. It works fine in 1.0. I haven't tried it with SP1

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top