|
guess wat.. it works!! thanks a lot sebastian..
|
|
|
|
|
Hi all,
I'm writing what is essentially a kind of terminal emulator (for various reasons I can't use a pre-existing one, as this needs some pretty specific features).
One thing I'm a bit stuck on is trying to figure out how to make a custom control for the output text box. I need something that looks and acts somewhat like a textbox (however "read-only" from the user's perspective, as they enter commands in a separate control (or commands will be fired programmatically), and this control is just to show the output from the server.
The problem is, the "history". RichTextBoxes (and TextBoxes of course) have a maximum amount of characters. This is fine, and of course completely acceptable. However, when the control reaches it's maximum, I want it to behave in such a way that the oldest lines disappear from the start and the new lines come in at the end. As I will set the maximum length to be very long, doing this by taking ALL the text in the box, cutting the first line and then rewriting the whole lot in the text box again would be absolutely terrible for both memory usage and speed (i.e. totally unacceptable user experience). Such controls seem to be quite common for terminal emulators, telnet clients, MUD clients, custom consoles, etc, so I assume there should be some pretty nice examples out there, but I really can't find anything (every example of these types of apps I've come across seems to forget about this issue and doesn't handle what happens when the text box maximum is reached!)
It should ideally be derived from RichTextBox since I need colour support, however if it supports colour and looks somewhat like a text box, I'm happy to work with anything as I'll probably be modifying it heavily anyway. I'd also love it if it was entirely .NET managed code rather than making Windows specific calls since I intend my application to work under mono as well as on Windows... however if that's asking too much, I'll accept native Windows calls if that's what you suggest and then will come up with different methods for other platforms.
Any ideas?
|
|
|
|
|
I think you are probably going to end up producing your own custom control. You are right, the user experience for continually removing a line of text from a TextBox or RichTextBox would probably be horrible (depending on how many lines of text you allow.
If you didn't need colour, then a ListBox would probably help, and it has an Items collection which supports Add and Remove / RemoveAt. But no colour.
The custom control shouldn't be a major problem, just provide your own paint and use Graphics.MeasureString to get the height of the line - you can them support the size you want, in the colours you want.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
The ListBox idea was one I considered (adding colour to that is actually pretty trivial), but then I'd have the problem that I do want the user to be able to select text and copy/paste it elsewhere, which is not really feasible with a ListBox.
For reference, I want to allow something like 20000 lines of "history" in the control (each line will be limited to 80 characters because of what I'm connecting to, so that's only approx 2MB of text even including the ANSI colour codes)
With regards to providing my own paint, I've always had performance issues with manually pasting strings on custom controls. Are there any hints around about doing this without severe performance degradation? And also, if I'm not using a TextBox as a base, how I might handle the select/copy/paste that a TextBox provides? It just seems like it might be quite a lot of work for something that ends up only very marginally different from a TextBox.
(of course if anyone else reading has a good idea for my original question, I probably don't need this part answered!)
|
|
|
|
|
Sorry, but I can't help you there - I assumed from your original post that "read-only from a users perspective" meant it did not include paste! As I have never tried to implement that you are better off getting help from someone who has.
Another option might be to look at existing Terminal emulators which it may be possible to modify to your needs (ie rip out the serial port bit) as these would include some colour control, probably via ANSI escape sequences. Never tried them, but I know they do exist in commercial and open source variants.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Yep, no problem. Thanks for your help anyway.
Just to note: I am not actually wanting to implement paste - just select and copy (over multiple lines or only parts of lines, as with a TextBox)... sorry if the mention of paste added confusion.
As mentioned, looking at existing Terminal Emulators, I can't find anyone that's even considered this. They tend to use a standard RichTextBox and there's nothing in there to handle what happens when it flows over the character limit (I assume that if they've even thought about it, they just think it's unlikely to ever happen - with a limit of 2147483647 chars, it works out to a few months at 10 lines per second with 100 chars per line (maybe I'm just being fussy by worrying about it?) (actually, I still don't know what behaviour to expect when it overflows... if you set a MaxLength manually, it's ignored for programmatic input - it only stops manual input after that amount))
Regarding ANSI colour - I've already written all that myself. The current version of my app uses a RichTextBox (as with everything else I've seen), so it's not holding up my development work - I just want to avoid possible future problems.
|
|
|
|
|
Woo! No-one is going to scroll back through 2Gb of text - it would take all week!
Why not just append it to a log file and show the last 200 lines or so? Then at least you are limited by just the disk space, rather then the virtual memory and the chars in a rich text box?
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Of course you're quite right noone will scroll back through that much. My plan is to limit it to approx 20000 lines though (200 is way too little for the kind of thing I'll be outputting).
Regardless, it doesn't change the need to elegantly handle dropping off the old data and displaying the new.
If I come up with an elegant solution, I'll be sure to post it here on CodeProject for others who have also spent their time looking for such a thing.
|
|
|
|
|
Hi All,
I want to create Service through my C# application. The service exe could be VC or C++ exe.
I dont want to use InstallUtil.exe to create service.
Thanking You,
Sunil G.
|
|
|
|
|
Sunil G wrote: I want to create Service through my C# application.
If you mean that you want to write a service in C# there are many articles around to help you.
Sunil G wrote: The service exe could be VC or C++ exe.
This makes no sense; please clarify.
Sunil G wrote: I dont want to use InstallUtil.exe to create service.
What do you want to use?
MVP 2010 - are they mad?
|
|
|
|
|
No i dont want to write.
I just want to install service.
|
|
|
|
|
Google finds lots of articles on this, including one here[^] on CodeProject.
MVP 2010 - are they mad?
|
|
|
|
|
You can use other installers for your service. I use Wix for mine.
|
|
|
|
|
How to get all c# Coding Error?
I wanna to translate the codes in my language and the call the translated error!
|
|
|
|
|
Just type asycroniously on your keyboard(without looking at it)
and you'll get all the Errors and Horros that you need
|
|
|
|
|
Not Use !
I wanna to get all "Exception " in C# ?
|
|
|
|
|
For error codes look here[^] and work your way through the links.
As for the different types of exceptions that can be thrown start here[^] and here[^] and as you work through the MSDN site you should be able to find more.
|
|
|
|
|
Get ALL Error Type in C#?
where in msdn?
|
|
|
|
|
I gave you three links to use as starting points, the first gives links to ALL system error codes and the other two give information on Runtime Exceptions and the other on Derived Classes of System.Exception show some initiative and look through the links I provided as well as searching the MSDN site for yourself.
|
|
|
|
|
There's probably more than 10,000 error messages possible in the .NET Framework. There is no method that will give you a list of all of those messages.
|
|
|
|
|
Hi!
I have an interesting problem. I have an application that contains two textboxes. The user enters his StartTime in one textbox and his EndTime in the other.
I have a calculation method that calculated the total Hours between these two variables. The problem I am having is that when the user inserts the starttime say 8:00 and finish time say 7:00 you will get a -1 hour.
How can I prevent users from entering negative values??
My method looks like this:
private void CalculateHoursWorked()
{
string startTime = Convert.ToDateTime(txtStartTime.Text).ToShortTimeString();
DateTime startDate = Convert.ToDateTime(startTime);
string endTime = Convert.ToDateTime(txtEndTime.Text).ToShortTimeString();
DateTime endDate = Convert.ToDateTime(endTime);
TimeSpan ts = endDate.Subtract(startDate);
HoursWorked = ts.Hours.ToString();
MinutesWorked = ts.Minutes.ToString();
}
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: How can I prevent users from entering negative values??
First: you should use dateTimePicker(s) instead of text boxes
(a masked textBox could do the job but => more work)
As for negative result create a function to swap dates. Something like:
private void SwapDates(){
if(start.CompareTo(end)<0)
{
DateTime tmp = start;
start=end;
end=tmp;
}
}
|
|
|
|
|
You should check if the time is negative. If so show an error that clearly explains that negative time is not allowed and why the time the user entererd was negative. Then highlight one of the times in red
|
|
|
|
|
Hello Sirs,
How to find the compression type of jpeg, when we give one sample input jpeg file the output result is this image contains (ex.) xxxx compression type. How to identify it .?
please replay
Failure is Success If we learn from it!!
|
|
|
|
|
I am very new to C# I have taken two classes on Java. But they were not the best classes. I am wanting to learn as much as I can about linking up Access Databases to Combo boxes in C#. I am wanting to create a database that I can select an item using a combo box then * a number input in a different text box and have it display in a different text box.
So for instance I would select in the combo box a food name. Then in my 1st text box I would put a number this would then * buy number of calories that is linked to the food name. And display the results in the last text box.
food Q total
Any suggestion on this or links that would give visual examples of how to get this to work?
|
|
|
|