473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox paint disable?

I want to append text to the end of a text box. If the cursor is currently
at the end I just want to append it and have the normal scrolling take place
if needed.

However, if the selection isn't at the end of the text box I want to append
the text but WITHOUT changing the selection or scrolling the text.

I can easily tell if the selection is at the end or not.

However, I haven't found away to prevent the scrolling when I AppendText.

Is this possible? Seems like I'd need to do something like:
- Grab the selection point
- Turn off updating
- Append the text
- Restore the selection point
- Turn on updating in such a way that if part of the view changed it will
show.

Thanks,
--
Grant Schenck
Nov 17 '05 #1
4 6971
Made some progress...

At this point I can write text to the end of my window without changing the
current selection or causing any scrolling IF the end of the file is not
visible on the screen. If the end of the file is visible then the cursor
jumps to the start.

This is the logic I'm using:

void Log(string str)
{
str += "\r\n";
int nLength = textBoxLog.Text Length;
int nSelectionStart = textBoxLog.Sele ctionStart;
int nSelectionLengt h = textBoxLog.Sele ctionLength;

if (nSelectionStar t >= nLength && nSelectionLengt h == 0)
// We are, write the text to the end and let it scroll (or make it
if need be)
textBoxLog.Appe ndText(str);
else
{
textBoxLog.Susp endLayout();

// Write the text
textBoxLog.Text += str;

// Restore the insertion point
textBoxLog.Sele ctionStart = nSelectionStart ;
textBoxLog.Sele ctionLength = nSelectionLengt h;
textBoxLog.Resu meLayout();
}
}
Any ideas?

Thanks, Grant Schenck
"Grant Schenck" <sc******@opton line.net> wrote in message
news:Om******** ******@TK2MSFTN GP09.phx.gbl...
I want to append text to the end of a text box. If the cursor is currently at the end I just want to append it and have the normal scrolling take place if needed.

However, if the selection isn't at the end of the text box I want to append the text but WITHOUT changing the selection or scrolling the text.

I can easily tell if the selection is at the end or not.

However, I haven't found away to prevent the scrolling when I AppendText.

Is this possible? Seems like I'd need to do something like:
- Grab the selection point
- Turn off updating
- Append the text
- Restore the selection point
- Turn on updating in such a way that if part of the view changed it will
show.

Thanks,
--
Grant Schenck

Nov 17 '05 #2
Actually, what is happening is when I add the text, it scroll the view to
the start. The selection seems to be correct.

So, how do I prevent it scrolling to the start when I add text as below?

Thanks, Grant Schenck

"Grant Schenck" <sc******@opton line.net> wrote in message
news:#u******** ******@TK2MSFTN GP12.phx.gbl...
Made some progress...

At this point I can write text to the end of my window without changing the current selection or causing any scrolling IF the end of the file is not
visible on the screen. If the end of the file is visible then the cursor
jumps to the start.

This is the logic I'm using:

void Log(string str)
{
str += "\r\n";
int nLength = textBoxLog.Text Length;
int nSelectionStart = textBoxLog.Sele ctionStart;
int nSelectionLengt h = textBoxLog.Sele ctionLength;

if (nSelectionStar t >= nLength && nSelectionLengt h == 0)
// We are, write the text to the end and let it scroll (or make it
if need be)
textBoxLog.Appe ndText(str);
else
{
textBoxLog.Susp endLayout();

// Write the text
textBoxLog.Text += str;

// Restore the insertion point
textBoxLog.Sele ctionStart = nSelectionStart ;
textBoxLog.Sele ctionLength = nSelectionLengt h;
textBoxLog.Resu meLayout();
}
}
Any ideas?

Thanks, Grant Schenck
"Grant Schenck" <sc******@opton line.net> wrote in message
news:Om******** ******@TK2MSFTN GP09.phx.gbl...
I want to append text to the end of a text box. If the cursor is

currently
at the end I just want to append it and have the normal scrolling take

place
if needed.

However, if the selection isn't at the end of the text box I want to

append
the text but WITHOUT changing the selection or scrolling the text.

I can easily tell if the selection is at the end or not.

However, I haven't found away to prevent the scrolling when I AppendText.
Is this possible? Seems like I'd need to do something like:
- Grab the selection point
- Turn off updating
- Append the text
- Restore the selection point
- Turn on updating in such a way that if part of the view changed it will show.

Thanks,
--
Grant Schenck


Nov 17 '05 #3
Hi Grant,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #4
Hi Grant,

Thanks for your post.

Yes, I see your concern. The code snippet in your second reply almost gets
the result you wanted. However, setting the TextBox.Text property will
always force the textbox focus(caret) go to the start, which you do not
want.

Currently, I can not find a perfect workaround for this issue, because many
methods of TextBox will do the automatic scrolling out of our control. For
example, AppendText will auto scroll to the end, set the Text property will
auto scroll to the start. However, TextBox.Select method does not do the
scrolling anymore.

Does the code snippet below meet your need? I just use
TextBox.ScrollT oCaret method to force the textbox to scroll to the caret,
which near where focus reside. For your information:
void Log(string str)
{
str += "\r\n";
int nLength = textBoxLog.Text Length;
int nSelectionStart = textBoxLog.Sele ctionStart;
int nSelectionLengt h = textBoxLog.Sele ctionLength;
if (nSelectionStar t >= nLength && nSelectionLengt h == 0)
{
textBoxLog.Appe ndText(str);
}
else
{
textBoxLog.Appe ndText(str);
this.textBoxLog .Select(nSelect ionStart, nSelectionLengt h);
this.textBoxLog .ScrollToCaret( );
}
}

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5

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

Similar topics

5
9579
by: christian ternek | last post by:
Hello ! I want to make a custom textbox and inherit a custom control from textbox. Now i want to change the looking of the textbox with the following code: protected override void OnPaint(PaintEventArgs e) {
2
2691
by: Andre Ranieri | last post by:
I'm retouching our corporate web site that, among other things, allows customers to log in and pay their invoices online. I noticed that on the checkout page, the credit card number textbox autofills with past entries for that textbox. My development workstation has the Google Toolbar installed; I'm not sure whether the autofill...
7
1678
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and inherit it in all my other forms, but a simple event link? if that is the right term would be easier? Thx.
0
2486
by: sunny076 | last post by:
Hi, I am having difficulties creating a derived class for DisabledDataGridViewTextBoxColumn and cell when the VisualStyle is not supported. Basically I am down to either using ControlPaint or Graphics to achieve this. But with Graphics, I am not sure how I can make them diabled. Below are my codes:
4
4885
by: Kürþat | last post by:
Hi all, I do some drawing in a form's paint event handler and I have a button on that form. Whenever the mouse enters or leaves the button Form's paint event occurs. Isn't that a strange behavior? Is it possible to prevent that? Thanks.
3
5401
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution I'd rather do it like Microsoft Dynamics does and use separate textbox and lookup button. What I have is, simply, is a C# winform, a textbox and a...
8
5065
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
13
3319
by: WALDO | last post by:
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...
14
13368
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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...
0
6287
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...
0
3657
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...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
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...

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.