473,395 Members | 2,795 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,395 software developers and data experts.

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 6954
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.TextLength;
int nSelectionStart = textBoxLog.SelectionStart;
int nSelectionLength = textBoxLog.SelectionLength;

if (nSelectionStart >= nLength && nSelectionLength == 0)
// We are, write the text to the end and let it scroll (or make it
if need be)
textBoxLog.AppendText(str);
else
{
textBoxLog.SuspendLayout();

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

// Restore the insertion point
textBoxLog.SelectionStart = nSelectionStart;
textBoxLog.SelectionLength = nSelectionLength;
textBoxLog.ResumeLayout();
}
}
Any ideas?

Thanks, Grant Schenck
"Grant Schenck" <sc******@optonline.net> wrote in message
news:Om**************@TK2MSFTNGP09.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******@optonline.net> wrote in message
news:#u**************@TK2MSFTNGP12.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.TextLength;
int nSelectionStart = textBoxLog.SelectionStart;
int nSelectionLength = textBoxLog.SelectionLength;

if (nSelectionStart >= nLength && nSelectionLength == 0)
// We are, write the text to the end and let it scroll (or make it
if need be)
textBoxLog.AppendText(str);
else
{
textBoxLog.SuspendLayout();

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

// Restore the insertion point
textBoxLog.SelectionStart = nSelectionStart;
textBoxLog.SelectionLength = nSelectionLength;
textBoxLog.ResumeLayout();
}
}
Any ideas?

Thanks, Grant Schenck
"Grant Schenck" <sc******@optonline.net> wrote in message
news:Om**************@TK2MSFTNGP09.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.ScrollToCaret 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.TextLength;
int nSelectionStart = textBoxLog.SelectionStart;
int nSelectionLength = textBoxLog.SelectionLength;
if (nSelectionStart >= nLength && nSelectionLength == 0)
{
textBoxLog.AppendText(str);
}
else
{
textBoxLog.AppendText(str);
this.textBoxLog.Select(nSelectionStart, nSelectionLength);
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
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...
2
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...
7
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...
0
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...
4
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...
3
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...
8
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
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...
14
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.