TextBox & Text

T

Tod Johnson

Hello,

have found that TextBox control always resets the vertical scrollbar
position to the beginning in the Multiline mode. When I try to call
"ScrollToCaret" there is really visible flickers. :( Are there
workaround? I'd like just to set text for the TextBox and stay on the
last position.


....
tbConsole.AcceptsReturn = true;
tbConsole.AcceptsTab = true;
tbConsole.Multiline = true;
....

void PutNewText(string t)
{
tbConsole.SelectionStart = tbConsole.Text.Length;
tbConsole.SelectionLength = t.Length;
tbConsole.SelectedText = t;
}


Thanks,
Tod
 
T

Tod Johnson

Maybe there are any examples how to write custom readonly TextBox with
the correct carret behaviour?

I have been trying to derive my custom class from the Control to
implement a TextBox behaviour, but it doesn't receive focus and doesn't
receive any keys... :(

Thanks in advance,
Tod
 
T

Tod Johnson

Have found that the hwnd gotten in the my custom control constructor
(derived from TextBox) is incorrect. But when I tried to get it
everytime before SendMessage call then everything is fine.

Can't find the explanation for this issue :(

Are any thoughts?
 
T

Tod Johnson

Wow! The issue is more strange than I thought. :(

public TextBoxEx()
{
AcceptsReturn = true;
AcceptsTab = true;
Multiline = true;
ScrollBars = ScrollBars.Vertical;

hWnd = GetHWND(); <-- correct handle
}

but

public TextBoxEx()
{
hWnd = GetHWND(); <-- incorrect handle

AcceptsReturn = true;
AcceptsTab = true;
Multiline = true;
ScrollBars = ScrollBars.Vertical;
}
 
A

Alex Feinman [MVP]

You cannot do it in constructor. The control is not created yet. Even if the
first one works.
What you want to do is to add a ParentChanged handler in the constructor and
retrieve hWnd in that handler.
 
T

Tod Johnson

Hm, that is really strange. Why does the second method work perfectly?
And also I've seen the implemention of TextBoxEx in the OpenNETCF where
the handle gets in the constructor also.

Anyway thanks, your suggestion seems to be logical!
 

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