|
Judah Himango wrote: Also, if you're just trying to simulate the KeyPressed event, couldn't you just code up method that calls OnKeyPressed override (which will fire the KeyPressed event)?
That is what I am asking. I am not sure how to go about doing it.
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
Simply calling the OnKeyPress protected method inside the TextBox derivative control will fire the KeyPress event in the underlying control. So, to raise the KeyPress event:
public void ManuallyRaiseKeyPress(...)
{
base.OnKeyPress(...);
}
myTextBoxDerivative.ManuallyRaiseKeyPress(...);
Keep in mind that this will NOT insert text into the control. The KeyPress event responds to a key being pressed on the keyboard. The text box does not insert text into the control when it receives the KeyPress event; on the contrary, the KeyPress event responds to text being inserted via the keyboard. If you're still sure that's what you want, the above solution should work for you.
Now, if you're trying to insert text into the textbox programmatically, and textBox.Text = ... won't work for you, then you're going to need to use either SendKeys or SendMessage (win32) to the textbox. SendKeys should work so long as the actual textbox is focused (in your original code posting, you were focusing the user control, not the textbox).
|
|
|
|
|
Does anyone know why MS hasn't implemented these and do they plan to?
Also does anyone know of a way to parse C# code into a CodeCompileUnit, or is the only option to use this not implemented method?
BTW, I don't particularly want to have to write a complete parser for C# or VB.NET!
Regards Ed
|
|
|
|
|
Hi everybody!
Does anyone know how to monitor lan activity in .NET using C#? I thought PerformanceCounter was the right way but now I'm not sure. I need something like Task Manager. Thank you!
|
|
|
|
|
That's probably not a job for the .NET framework. AFAIK, you're going to need to make lots of Win32 calls to make that work; you might as well be writing in a native language or C++/CLI.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking
Judah Himango
|
|
|
|
|
I know that i cannot read lets say 80mb big file into a textbox, first i takes too long and second it would take alot of memory.
I need to find a approach to read sections from file to textbox and when user scrolls down or push page down it read another section...
Is that a good approach to problem or do anyone have another approach to read large textfiles fast...
<Im really impressed what Christan Ghisler done with his lister, its really fast.>)
Im open for ideas how to solve this problem...
-- modified at 12:13 Tuesday 7th March, 2006
|
|
|
|
|
I have created a simple program that does something similar. It will read a file in chunks using a reader and provides forward only navigation.
If you send me an email I can send you the source code (C# vs2005)
andrew at pmall dot com
|
|
|
|
|
Sent you a mail
|
|
|
|
|
You basically have two options:
1. Open the file as a textfile, but then you can only read it sequentially.
2. Open the file as a binary file, then you have to detect the line breaks yourself, and convert the bytes to text using the Encoding class, but you can read from any part of the file.
---
b { font-weight: normal; }
|
|
|
|
|
I dont quite get what you are saying here..
In this case it would be possible to read chunks from whereever you like in file...or did i dont understand what you saying?
<code>
FileStream fs=new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite,
FileShare.None, 8192 ); //we use the default buffer
StringBuilder result=new StringBuilder(8192);
byte[] buffer=new byte[8192];
int count=fs.Read(buffer,0,8192); //reading a block from the file, here we could start for example on 2000 instead of pos 0 //(fs.Read(buffer,2000,8192))
ASCIIEncoding encoding=new ASCIIEncoding();
while (count!=0) //stop when Read returns 0
{
result.Append(encoding.GetString(buffer));
count=fs.Read(buffer,0,8192);
}
fs.Seek(0, SeekOrigin.Begin);
</code>
|
|
|
|
|
Yes, you can use the Seek method to go to any position in the file.
Note: There is an error in this comment in the code:
//reading a block from the file, here we could start for example on 2000 instead of pos 0 //(fs.Read(buffer,2000,8192))
Using that call would result in an error message. As the size of the array is 8192 bytes, you can't read 8192 bytes and put them in the array from index 2000. Between index 2000 and the end of the array there is only room for 6192 bytes.
---
b { font-weight: normal; }
|
|
|
|
|
You are so right, little mistake from my side
|
|
|
|
|
System.IO.File in .Net 2.0 is really fast and has some new methods like ReadAllText() and ReadAllLines(). Why not some custom methods for your app?
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
How do you mean you should do then?
|
|
|
|
|
I was thinking of using ReadAllText() within an asynchronous method. Just read chunks of the 80mb from a temp file using ReadAllText(), when the user nears the end point create, then read another chunk into the textbox.AppendText(tempfile.ReadAllText()).
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
ReadAllText() is synchronous method, when you try to read a large text file, your application will hang or slow down ... better to use asynchronous medthod !!!
|
|
|
|
|
hackerhcm wrote: ReadAllText() is synchronous method, when you try to read a large text file, your application will hang or slow down ... better to use asynchronous medthod !!!
Of course, I was thinking of using ReadAllText() within the asynchronous medthod. Just read chunks of the 80mb from a temp file or something using ReadAllText(), when the user nears the end point create then read another chunk.
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
How to get the real Length of UTF8 String?
Thanks
Nothing
-- modified at 11:58 Tuesday 7th March, 2006
|
|
|
|
|
String.Length?
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
The length of an UTF8 string can be interpreted in two ways:
1. The number of bytes that the encoded data uses.
2. The number of character that the decoded data contains.
The Encoding class has the GetByteCount to calculate the first one, and GetCharCount to calculate the second one.
---
b { font-weight: normal; }
|
|
|
|
|
|
Hi. I'm trying to measure one line string with the space character at the end. For example "Testing string ".
The problem is that the size that I get is the same size measured without the space at the end. Anybody knows how to make MeasureString() take the space character at the end into consideration?
|
|
|
|
|
Make sure you pass StringFormat with MeasureTrainingSpaces:
StringFormat format = new StringFormat(StringFormatFlags.MeasureTrailingSpaces);
g.MeasureString(..., format);
|
|
|
|
|
Hi,
I need to desigen an OSK.
Does anybody know hoe do i keep the OSK out of focus even when i click it's buttons while keeping any other form (the target form) in focus so the cgharacters i'm sending from the OSK (Sendkyes) will reach thier destination?
tnx
--roy
|
|
|
|
|
I would imagine you'd send keyboard messages to the window in question.
Christian Graus - Microsoft MVP - C++
|
|
|
|