473,609 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.AppendTex t(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 3324
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.publi c.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*******@yaho ogroups.comwrot e in message
news:Og******** ******@TK2MSFTN GP04.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.publi c.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.publi c.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.publi c.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.publi c.dotnet.langua ges.VB.

Cor

"WALDO" <NO****@NOSPAM. comschreef in bericht
news:OA******** ******@TK2MSFTN GP03.phx.gbl...
It is posted to microsoft.publi c.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*******@yaho ogroups.comwrot e in message
news:Og******** ******@TK2MSFTN GP04.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.publi c.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 "SendMessag eA" (ByVal
hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam
As Int32) As Int32

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Dim i1 As Integer = TextBox1.Select ionStart
Dim i2 As Integer = TextBox1.Select ionLength
Dim b1 As Boolean = (i1 < TextBox1.Text.L ength)
If b1 Then SendMessage(Tex tBox1.Handle, WM_SETREDRAW, 0, 0)
TextBox1.Append Text(Now & vbCrLf)
If b1 Then
TextBox1.Select ionStart = i1
TextBox1.Select ionLength = i2
SendMessage(Tex tBox1.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 "DoubleBuff er/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:

"AlphaBlendText Box - 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.publi c.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.winap i newsgroup? That would only make sense...

Oct 13 '06 #9
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:Oz******** ******@TK2MSFTN GP02.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

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

Similar topics

12
8356
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 image will be inserted into a textbox which is actually a text area. If the cursor is in the textbox/textarea then the characters are to be inserted at the cursor location. This means if the cursor is between some text then the characters need to...
2
4249
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 the end. Private Sub txtCapability_GotFocus() ‘ Placed either behind the OnEnter or GotFocus Event of a control named, ' in this case, txtCapability, on a form ensures that when the control is
0
1637
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 default language will be english. I asked here and the answer i got was that the best way to do so, is by getting the Hebrew Letter and Change it to it's parallel English letter on the keyboard. i didn't such a function (with switch and case) but i'm...
3
4010
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 selects the text from where the cursor is to where I want the cursor to be. All I want is to move the position of the cursor based on a X and Y values, not select the text. The code to recreate the issue.
0
1290
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 blinking vetical line-segment character). I need to either make this invisible or be able to control and read its position. How can I do this? Alternately, is there a way to force a TextBox to manage typing in a fractional number on its own so that...
1
9725
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('" + ctrl.ID + "').focus()</SCRIPT>"; RegisterStartupScript("focus", s); }
22
4495
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 that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and not on line 1. Anybody has any ideas?
3
11959
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 override the OnPaint()-method, however I have no clue what to do next. I want to be able to switch the blinking cursor to a solid, non-blinking, cursor and preferable have it with a color. So, how should I do that?
0
1686
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 does not show that the text can be dragged 2. When pressing the mouse button to start a drag the selected text changes - I know this is cause the code does not initiate the dodragdrop until the mouse leaves the control but if I change this then you...
0
8559
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6987
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5506
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4010
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1378
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.