Workaround for TextBox AppendText 32767 character limit

S

Steve

Hi

Ive seen plenty discussion about the textBox AppendText signed 16-bit
character limit and I presume that it has not been fixed as I am getting it
in a noddy project I am working at the moment. What I have not seen is a
suitable work around that is both efficient and simple enough for me to
grasp -- if there is one I would be grateful of the help.

Cheers
Steve
 
H

Herfried K. Wagner [MVP]

Steve said:
Ive seen plenty discussion about the textBox AppendText signed 16-bit
character limit and I presume that it has not been fixed as I am getting
it in a noddy project I am working at the moment. What I have not seen is
a suitable work around that is both efficient and simple enough for me to
grasp -- if there is one I would be grateful of the help.

Set the selection to the last character and assign the text to the control's
'SelectedText' property.
 
S

Steve

Herfried K. Wagner said:
Set the selection to the last character and assign the text to the
control's 'SelectedText' property.

Not sure I follow (sorry I'm new to VS.NET forms programming), what is the
sequence of events here? How do I set the selection to the last character
and how do assign the text to 'SelectedText'?
 
H

Herfried K. Wagner [MVP]

Steve said:
Not sure I follow (sorry I'm new to VS.NET forms programming), what is the
sequence of events here? How do I set the selection to the last character
and how do assign the text to 'SelectedText'?

\\\
With Me.TextBox1
.SelectionStart = .TextLength
.SelectedText = " bla foo goo"
End With
///
 
S

Steve

Herfried K. Wagner said:
\\\
With Me.TextBox1
.SelectionStart = .TextLength
.SelectedText = " bla foo goo"
End With
///

Thanks for spelling it out -- I got it to work and it is a neat alternative
to AppendText only trouble is this method also falls over at 32,767 bytes,
heres the code:

// dont use AppendText method it is limited to 16-bit
// this->textBoxOutput->AppendText(Convert::ToString(str));

// AppendText alternative
this->textBoxOutput->SelectionStart = this->textBoxOutput->TextLength;
this->textBoxOutput->SelectedText = Convert::ToString(str);

I have definately set MaxLength to 0 for the textBoxOutput in Form
Designer -> Properties -- is there anything else I have to do to get beyond
32,767 bytes

(I am running on WinXP Pro SP2 just in case that fact is relevant).
 
C

Claes Bergefall

Steve said:
Thanks for spelling it out -- I got it to work and it is a neat alternative
to AppendText only trouble is this method also falls over at 32,767 bytes,
heres the code:

// dont use AppendText method it is limited to 16-bit
// this->textBoxOutput->AppendText(Convert::ToString(str));

// AppendText alternative
this->textBoxOutput->SelectionStart = this->textBoxOutput->TextLength;
this->textBoxOutput->SelectedText = Convert::ToString(str);

I have definately set MaxLength to 0 for the textBoxOutput in Form
Designer -> Properties -- is there anything else I have to do to get beyond
32,767 bytes

(I am running on WinXP Pro SP2 just in case that fact is relevant).

Jepp, SelectedText does the same stupid thing internally as AppendText
does (i.e. temporarily sets the maxlength to 32767).
Try this (ignore the first paragraph):

http://groups.google.com/group/micr.../1b4f14c96ebace96?hl=sv&lr=&ie=UTF-8&oe=UTF-8

/claes
 
S

Steve

Claes Bergefall said:
Jepp, SelectedText does the same stupid thing internally as AppendText
does (i.e. temporarily sets the maxlength to 32767).
Try this (ignore the first paragraph):

http://groups.google.com/group/micr.../1b4f14c96ebace96?hl=sv&lr=&ie=UTF-8&oe=UTF-8

/claes

Cheers -- this works perfectly although I had a little trouble converting to
C++ .NET windows forms app syntax:

if (this->textBoxOutput->IsHandleCreated)
{
WPARAM iptr = -1;
this->textBoxOutput->Select(this->textBoxOutput->TextLength,
this->textBoxOutput->TextLength);
SendMessage(reinterpret_cast<HWND>(this->textBoxOutput->Handle.ToPointer()),
EM_REPLACESEL, iptr, (LPARAM) str);
iptr = 0;
SendMessage(reinterpret_cast<HWND>(this->textBoxOutput->Handle.ToPointer()),
EM_SETMODIFY, iptr, NULL);
}
else
this->textBoxOutput->AppendText(Convert::ToString(str));

I blindly copied some type conversion syntax that Ive seen previously
without any real understanding but it works nonetheless -- hopefully there
is no undesirable consequences from the conversions Im using, if anything is
obvious please let me know (also if there is a simpler way of doing this).
 
C

Claes Bergefall

Jepp, SelectedText does the same stupid thing internally as AppendText
Cheers -- this works perfectly although I had a little trouble converting to
C++ .NET windows forms app syntax:

if (this->textBoxOutput->IsHandleCreated)
{
WPARAM iptr = -1;
this->textBoxOutput->Select(this->textBoxOutput->TextLength,
this->textBoxOutput->TextLength);
SendMessage(reinterpret_cast said:
EM_REPLACESEL, iptr, (LPARAM) str);
iptr = 0;
SendMessage(reinterpret_cast said:
EM_SETMODIFY, iptr, NULL);
}
else
this->textBoxOutput->AppendText(Convert::ToString(str));

I blindly copied some type conversion syntax that Ive seen previously
without any real understanding but it works nonetheless -- hopefully there
is no undesirable consequences from the conversions Im using, if anything is
obvious please let me know (also if there is a simpler way of doing this).

Looks correct to me, athough the code I wrote passed 0 for both wparam and
lparam
in EM_SETMODIFY (doesn't really make a difference I guess)

/claes
 
S

Steve

Claes Bergefall said:
Looks correct to me, athough the code I wrote passed 0 for both wparam and
lparam
in EM_SETMODIFY (doesn't really make a difference I guess)

Thanks Claes
Ill check over the wparam lparam use in my code -- just glad its working.
Such a stupid issue with textBox Im surprised the fix was so hard to come by
(google etc). If it hadnt been for your earlier post I would still be
looking.

Cheers
Steve
 

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