473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Set Text on Textbox w/o changing cursor pos

I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20
lines of text per second. I use the AppendText() method to accomplish this.
This is a great substitute for taking the Text property and concatenating
it...

Me.tb.Text &= newText
' Instead use
Me.tb.AppendText(newText)

....ultimately setting the SelectionStart to the end of TextBox, the
SelectionLength to the length of the new text and replacing the SelectedText
(via the SendMessage API function, determined by using Lutz Roeder's
Reflector).

This keeps the cursor at the end of the TextBox as text is appended to it
without flicker. I wish to perform this same function, but keep the cursor
position where it is (if it is not at the end of the TextBox). If I persist
the selection position and length before I append the text and restore them
aftrer, it creates AWFUL flicker.

Is there a message I can send, maybe using the SendMessage API, that will
append text but not change the position or the selection?

Picture the Output Window in Visual Studio as you are debugging and calling
Debug.WriteLine(newText) at the same rate. If your cursor is set at the end
of the TextBox, it stays at the end as lines are written. If you select some
text, your selection stays where it is, but text is still appended. That's
exactly what I'm trying to do.

Dim i As Integer
For i = 0 To 10000
Debug.WriteLine("I am writing line " & i)
Next

Any help is appreciated.
Thanks in advance.

WALDO
Oct 12 '06 #1
13 3294
WALDO wrote:
I have a .Net TextBox
Good for you.
But please do not post about it in any of the classic VB newsgroups.

If it doesn't say "dotnet" (or "vsnet") then it isn't for dotnet.
thanks,
Bob
MS MVP - VB, 2000-2006
--
Oct 12 '06 #2
It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.

Doesn't it expend less energy to help if you you have an answer or shut the
hell up if you don't than to just be an ass? Isn't it exhausting, Bob?

--

Any help is appreciated.
Thanks in advance.

WALDO

"Bob O`Bob" <fi*******@yahoogroups.comwrote in message
news:Og**************@TK2MSFTNGP04.phx.gbl...
WALDO wrote:
>I have a .Net TextBox

Good for you.
But please do not post about it in any of the classic VB newsgroups.

If it doesn't say "dotnet" (or "vsnet") then it isn't for dotnet.
thanks,
Bob
MS MVP - VB, 2000-2006
--

Oct 12 '06 #3
WALDO <NO****@NOSPAM.comschrieb im Beitrag
<OA**************@TK2MSFTNGP03.phx.gbl>...
It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.
Why then don't you ask your question in a C(++) group as well where people
do know a lot about SendMessage? Right, because C(++) and VB.NET are
different languages. Know, let us ensure you that VB.NET and VB are
different languages as well.
Doesn't it expend less energy to help if you you have an answer or shut
the
hell up if you don't than to just be an ass? Isn't it exhausting, Bob?
This for the future qualifies questions of yours as to be ignored. Good
bye!

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------

Oct 12 '06 #4
It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.

Doesn't it expend less energy to help if you you have an answer or shut
the hell up if you don't than to just be an ass? Isn't it exhausting, Bob?
The thing that you don't seem to realize is that almost everything in your
original post is meaningless to those who visit and/or answer questions here
in the microsoft.public.vb.winapi newsgroup which is what made it
inappropriate for this newsgroup. To list just a few of these... we have no
idea what a TextBoxBase (really) is; our TextBox'es do not have an
AppendText method, so while that may be a great substitute for you, it has
nothing to do with how we would be able to approach the problem; we have to
guess that your &= operator(?) means to concatenate newText onto Me.tb.Text
(that is a correct guess, right?); our TextBox'es do not have SelectionStart
and SelectionLength properties (although I would guess our SelStart and
SelLength properties would be equivalent); and another guess we have to make
is that your Debug.WriteLine(newText) statement is equivalent to a
Debug.Print newText statement in our world (although I have no idea if
WriteLine is perfectly equivalent to Print). Oh! And we have no idea who
Lutz Roeder is nor what his Reflector is or does (whatever it is, I'm
guessing it won't work with VB6 or earlier code). So, given we have to guess
at, or we outright don't know, what most of your post was about, it amounted
to nothing but noise here in this non VB.NET newsgroup. That was pretty much
the point of Bob's response to you.

Rick
Oct 12 '06 #5
Waldo,

Why do you want to use a VB6 method in VB.Net.

To set the position for a Textbox is just methods.
http://msdn.microsoft.com/library/de...mberstopic.asp

AFAIK can you use the selection start.

In addition to the others, it is mostly better to describe what you want to
achieve than what you are doing, and than of course to the proper newsgroup.
The farmost largest newsgroup for VB is
microsoft.public.dotnet.languages.VB.

Cor

"WALDO" <NO****@NOSPAM.comschreef in bericht
news:OA**************@TK2MSFTNGP03.phx.gbl...
It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.

Doesn't it expend less energy to help if you you have an answer or shut
the hell up if you don't than to just be an ass? Isn't it exhausting, Bob?

--

Any help is appreciated.
Thanks in advance.

WALDO

"Bob O`Bob" <fi*******@yahoogroups.comwrote in message
news:Og**************@TK2MSFTNGP04.phx.gbl...
>WALDO wrote:
>>I have a .Net TextBox

Good for you.
But please do not post about it in any of the classic VB newsgroups.

If it doesn't say "dotnet" (or "vsnet") then it isn't for dotnet.
thanks,
Bob
MS MVP - VB, 2000-2006
--


Oct 13 '06 #6
On Thu, 12 Oct 2006 09:47:45 -0400, "WALDO" <NO****@NOSPAM.comwrote:
>It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.
>Doesn't it expend less energy to help if you you have an answer or shut the
hell up if you don't than to just be an ass? Isn't it exhausting, Bob?
Actually he /was/ being helpful

We would have given you misleading answers

Also Bob saved the rest of us pointing you to where you can get real
help.
Oct 13 '06 #7
Waldo,

I found this question interesting. It seems that many people have
asked, and no one has ever provided a workable answer other than to use
a 3rd-party control.

So I looked into it myself, and spent several hours researching and
experimenting, as this is something I can use also.

Here is the best I was able to manage with the stock textbox. I used a
multiline textbox with vertical scrollbar, a timer set to 50ms, and
this code:

Const WM_SETREDRAW = &HB
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam
As Int32) As Int32

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim i1 As Integer = TextBox1.SelectionStart
Dim i2 As Integer = TextBox1.SelectionLength
Dim b1 As Boolean = (i1 < TextBox1.Text.Length)
If b1 Then SendMessage(TextBox1.Handle, WM_SETREDRAW, 0, 0)
TextBox1.AppendText(Now & vbCrLf)
If b1 Then
TextBox1.SelectionStart = i1
TextBox1.SelectionLength = i2
SendMessage(TextBox1.Handle, WM_SETREDRAW, -1, 0)
End If
End Sub

Turning off redraw for the control while maintaining the cursor
position prevents any unwanted scrolling from occurring - a definite
improvement in behavior and flicker. However, it still flickers due to
the sometimes visible delay between the textbox's painting of the
background followed by the text.

Setting DoubleBuffer = True on the form means all painting is done in a
separate graphics buffer before being copied to the screen, which
should eliminate the flicker. However, it has no effect on the
textbox!

After exhausting quite a few ideas with no success, I determined that
the only feasible method was to create my own "DoubleBuffer/UserDraw"
scheme:
1) Suppress repainting of the textbox to the screen after the
..AppendText.
2) Paint to a bitmap instead.
3) Paint the bitmap onto the textbox.

I got it working, except:
1) The cursor flickered terribly during appends, as it wasn't painted
to the bitmap.
2) The scrollbars didn't paint properly either.

At this point, I decided getting this method to work properly was
non-trivial. Fortunately, someone else has already perfected it:

"AlphaBlendTextBox - A transparent/translucent textbox for .NET"
http://www.codeproject.com/cs/miscct...endtextbox.asp

It's flicker-free, works great when used with the code above, and
provides some extra graphic options. Which can be turned off if you
don't need them.

There's still one small issue that I'm not sure how to solve - try
selecting text *in reverse*. Maybe you can figure it out. :)

Oct 13 '06 #8
Bob O`Bob wrote:
Good for you.
But please do not post about it in any of the classic VB newsgroups.

If it doesn't say "dotnet" (or "vsnet") then it isn't for dotnet.
That's interesting.

This is microsoft.public.VB.winapi. Not VB4, 5, or 6; just VB. Isn't
VB.NET is a version of VB?

But seriously, I understand what you're saying. This question should
go to a dotnet.winapi or vsnet.winapi newsgroup. Oh wait, *there isn't
one*.

So basically, the situation is this: if someone has a question
specifically about using the API in VB, and they *naturally* take it to
the ONLY Microsoft newsgroup that has API and VB in the name, you're
going to get cranky on them. Gotcha. Nice MVP.

If you don't want to have these questions here, why not redirect some
of that energy from being rude, into getting MS to set up a more
appropriate dotnet.vb.winapi newsgroup? That would only make sense...

Oct 13 '06 #9
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:Oz**************@TK2MSFTNGP02.phx.gbl...
Waldo,

Why do you want to use a VB6 method in VB.Net.
He obviously doesn't know what he wants (except non-standard behavior from a
control that's worked the same for decades)... and will probably never see
your answer because now, he's pouting. Can't expect too much from someone
that calls people an ass in a public group, then ends the post with 'any
help is appreciated'... obvously a lie, in itself.

--
Ken Halter - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Oct 13 '06 #10
Waldo,

Without words,

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim ar As New System.Text.StringBuilder("")
For i As Integer = 0 To 100
ar.Append("who state something without reading the replys first,
and is even accesing the UI direct while he can use a stringBuilder")
Next
TextBox1.Text &= ar.ToString
TextBox1.SelectionStart = 13
TextBox1.SelectionLength = 0
TextBox1.Focus()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "It is a fool, "
TextBox1.Multiline = True
End Sub

Cor

<te******@hotmail.comschreef in bericht
news:11*********************@h48g2000cwc.googlegro ups.com...
Waldo,

I found this question interesting. It seems that many people have
asked, and no one has ever provided a workable answer other than to use
a 3rd-party control.

So I looked into it myself, and spent several hours researching and
experimenting, as this is something I can use also.

Here is the best I was able to manage with the stock textbox. I used a
multiline textbox with vertical scrollbar, a timer set to 50ms, and
this code:

Const WM_SETREDRAW = &HB
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam
As Int32) As Int32

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim i1 As Integer = TextBox1.SelectionStart
Dim i2 As Integer = TextBox1.SelectionLength
Dim b1 As Boolean = (i1 < TextBox1.Text.Length)
If b1 Then SendMessage(TextBox1.Handle, WM_SETREDRAW, 0, 0)
TextBox1.AppendText(Now & vbCrLf)
If b1 Then
TextBox1.SelectionStart = i1
TextBox1.SelectionLength = i2
SendMessage(TextBox1.Handle, WM_SETREDRAW, -1, 0)
End If
End Sub

Turning off redraw for the control while maintaining the cursor
position prevents any unwanted scrolling from occurring - a definite
improvement in behavior and flicker. However, it still flickers due to
the sometimes visible delay between the textbox's painting of the
background followed by the text.

Setting DoubleBuffer = True on the form means all painting is done in a
separate graphics buffer before being copied to the screen, which
should eliminate the flicker. However, it has no effect on the
textbox!

After exhausting quite a few ideas with no success, I determined that
the only feasible method was to create my own "DoubleBuffer/UserDraw"
scheme:
1) Suppress repainting of the textbox to the screen after the
.AppendText.
2) Paint to a bitmap instead.
3) Paint the bitmap onto the textbox.

I got it working, except:
1) The cursor flickered terribly during appends, as it wasn't painted
to the bitmap.
2) The scrollbars didn't paint properly either.

At this point, I decided getting this method to work properly was
non-trivial. Fortunately, someone else has already perfected it:

"AlphaBlendTextBox - A transparent/translucent textbox for .NET"
http://www.codeproject.com/cs/miscct...endtextbox.asp

It's flicker-free, works great when used with the code above, and
provides some extra graphic options. Which can be turned off if you
don't need them.

There's still one small issue that I'm not sure how to solve - try
selecting text *in reverse*. Maybe you can figure it out. :)

Oct 13 '06 #11
Cor Ligthert [MVP] wrote:
Waldo,
Without words,
I'm laughing my arse off right now.

Not only is that the most clever way to insult someone I've seen in a
long time, I tried it out and it doesn't address Waldo's problem at
all. :)

Oct 13 '06 #12
I don't care about the language. What you guys fail to realize is that I'm
not looking for a VB answer. I'm looking for a message I can send via
SendMessage, which last I checked was part of the Windows API, is it not? I
happen to be using VB.Net and a VB.Net textbox and explaining that so anyone
who DOES know may follow along.

You couldn't possibly tell me that my question is meaningless in the WinAPI
group because that's exactly what I'm looking for.

My point is that it took five additional posts for nobody to tell me
anything useful. So it was really a waste of both your and my times. If you
don't have anything to say that helps, don't reply. As for Thorsten, at
least he (I'm guessing it's a he) said something that helps, which was that
people in a C++ group might know more about SendMessage than in the generic
winapi group.

"Rick Rothstein (MVP - VB)" <ri************@NOSPAMcomcast.netwrote in
message news:ed**************@TK2MSFTNGP05.phx.gbl...
>It is posted to microsoft.public.vb.winapi because I am looking for a
SendMessage message. I think that qualifies.

Doesn't it expend less energy to help if you you have an answer or shut
the hell up if you don't than to just be an ass? Isn't it exhausting,
Bob?

The thing that you don't seem to realize is that almost everything in your
original post is meaningless to those who visit and/or answer questions
here in the microsoft.public.vb.winapi newsgroup which is what made it
inappropriate for this newsgroup. To list just a few of these... we have
no idea what a TextBoxBase (really) is; our TextBox'es do not have an
AppendText method, so while that may be a great substitute for you, it has
nothing to do with how we would be able to approach the problem; we have
to guess that your &= operator(?) means to concatenate newText onto
Me.tb.Text (that is a correct guess, right?); our TextBox'es do not have
SelectionStart and SelectionLength properties (although I would guess our
SelStart and SelLength properties would be equivalent); and another guess
we have to make is that your Debug.WriteLine(newText) statement is
equivalent to a Debug.Print newText statement in our world (although I
have no idea if WriteLine is perfectly equivalent to Print). Oh! And we
have no idea who Lutz Roeder is nor what his Reflector is or does
(whatever it is, I'm guessing it won't work with VB6 or earlier code). So,
given we have to guess at, or we outright don't know, what most of your
post was about, it amounted to nothing but noise here in this non VB.NET
newsgroup. That was pretty much the point of Bob's response to you.

Rick

Oct 28 '06 #13
I don't care about the language. What you guys fail to realize
is that I'm not looking for a VB answer.
It might be the case (I've seen it way too often) that the question you
asked may have been the wrong one. It is possible that VB.NET provides a
method that you are not aware of that would allow you to do what you asked.
We here (well, at least 99.9% of us) in the "vb" newsgroups would not know.
It is best to first ask your question in a VB.NET newsgroup and, if you
don't get an answer there, then post to other newsgroups which might
possibly be able to help (but if you do, mention that you first posted in to
the VB.NET community and they were not able to answer your question).
I'm looking for a message I can send via SendMessage, which
last I checked was part of the Windows API, is it not?
To the best of my knowledge, no such message exists to do what you asked
for.
I happen to be using VB.Net and a VB.Net textbox and
explaining that so anyone who DOES know may follow along.
The point of the majority of the responses you have gotten is that those
examples are, for the most part, meaningless to those in the "vb"
newsgroups. If you have a generic question about SendMessage, and you want
advice from those in the "vb.winapi" newsgroup, just pose the question with
a general description and leave out all the VB.NET mumbo-jumbo.
You couldn't possibly tell me that my question is meaningless
in the WinAPI group because that's exactly what I'm looking for.
Most of us will not read a VB.NET question in detail (we don't know the
language and it is different enough from the classic version of VB that we
are unlikely to be able to provide an answer, so we do not even waste our
time trying). See the last sentence of my first comment above as to a better
way to approach the "vb" newsgroups.
My point is that it took five additional posts for nobody
to tell me anything useful.
The type of responses that you have gotten might have something to do with
the tone of your initial response to Bob
So it was really a waste of both your and my times.
You think they are unhelpful; to us, they were just trying to keep down the
VB.NET postings here (to us, they are nothing but noise).
If you don't have anything to say that helps, don't reply.
From our standpoint, trying to educate VB.NET posters that their questions
are off topic in newsgroups with "vb" in their name is saying something that
helps.
As for Thorsten, at least he (I'm guessing it's a he) said
something that helps, which was that people in a C++ group
might know more about SendMessage than in the generic winapi group.
Just so we are completely clear, the microsoft.public.vb.winapi newsgroup is
**not** a generic winapi newsgroup.

Rick

Oh, by the way, here is how I would do what you originally asked for (note,
it is VB6 code and does not use any API functions)...

Dim i As Long
Dim Cursor As Long
With Text1
.Visible = False
Cursor = .SelStart
For i = 0 To 10000
.SelText = "I am writing line " & vbNewLine
Next
.SelStart = Cursor
.Visible = True
.SetFocus
End With

What the code does is first turn off the visibility of the TextBox, memorize
the cursor position, add the text using the SelText property (this looks
like it is mostly equivalent to VB.NET's AppendText method in
functionality), return the cursor to its initial location and then restore
the visibility of the TextBox. The TextBox will not actually disappear from
the screen; this will simply stop the system from trying to continually
update the screen.
Oct 28 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: who be dat? | last post by:
I'm trying to make a webpage do the following: I want a user to be able to click on a given image (there will be more than one image). Upon clicking a given image, characters specific to that...
2
by: NewBob | last post by:
Since Access automatically highlights all of the text in a text control (I use it to hold data from a memo field) when the control is activated, I've added the following code to put the cursor at...
0
by: Gidi | last post by:
Hi, i'm writing this question again, since i didn't get an answer in the reply i wrote, i hope it's ok. My user default language is hebrew and in some specific TextBoxs i want that the...
3
by: bitwxtadpl | last post by:
I want to programmatically set the position of a cursor in a textbox that has focus based on a X and Y value. However, when I send a WM_RBUTTONDOWN and a WM_RBUTTONUP message to the textbox it...
0
by: Peteroid | last post by:
I'm doing a managed C++.NET (2003) application where I use a Control::TextBox. When typing in text there is a cursor indicating the position of where typed in text will go next (typically, a...
1
by: Olav Tollefsen | last post by:
I use this code to set focus to a textbox when I load a page: private void SetFocus(System.Web.UI.Control ctrl) { string s = "<SCRIPT language=\"javascript\">document.getElementById('" +...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: fbergroth | last post by:
Hi, I'm quite new to C# allthough I've been programming in other languages for quite a while. I'd like to change the blinking cursor inside a TextBox, I guess I must derive the class and...
0
by: andytsummers | last post by:
Hi I have tried to implement drag and drop by using the following code but I have several problems. 1. When you put your mouse over selected text the cursor is still the i-beam and therefore...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.