|
(Type your message here)
richTextBox rtb = new richTextBox();<br />
StringBuilder stb = new StringBuilder();<br />
stb.Append(rtb.Text);
In a foreach(char ch in stb.ToString()) statement I want to know if we have find end of line.
Any fast way to do this?
Could this be done without converting .ToString() by someway?
|
|
|
|
|
Does it have to be a StringBuilder and then running through all characters separately?
I guess using IndexOf() on rtb.Text might be faster...
mav
|
|
|
|
|
It's important for me to read the characters separately and insert or remove a specific number of continous spaces(not all) at the start of any line, rapidly.
|
|
|
|
|
Ok, in that case I'd second the String.Split/String.Merge suggestion, because if you insert characters in your string, the system has to move the rest of the string. So creating an array of lines, modifying each line separately and then combining them again should perform much better.
|
|
|
|
|
|
A newline is not just one character for windows, it's string representation = "\r\n", which can be found in System.Environment.NewLine.
You could try comparing the current Char ch to: Char newline = '\n';, but I'm not sure that'll work. Or make a variable that holds the last char compared like so:
<br />
Char last = '';<br />
<br />
foreach(char ch in stb.ToString())<br />
{<br />
if(ch == '\n' && last == '\r')<br />
{<br />
}<br />
last = ch;<br />
}<br />
|
|
|
|
|
I was thinking break will take me out of if() which was in the foreach() .
But it was taking me out of the foreach() .
So some parts of code was not executed. Instead of break I used continue .
So my problem was solved by this way:
foreach(char ch in <code>stb.ToString())
{
......................
if(ch.ToString()=="\n")
......................
}
The "\r" doesn't appear anywhere.
Performance is low for other reasons. I should think other solutions.
Thanks.
|
|
|
|
|
Hi
i am trying to make an formula on date
my problem is this .... i give a date like this = 2-4-2004
and i give another date that is 2-6-2005 and i want to get the difference between them .... it will count days, months, and years.... and one more thing that if you are giving solution of this put this in your mind that days may be 28, 31, and 30 .... ok TC.
bye
Mazhar Hussain.;)
|
|
|
|
|
Just look up the DateTime and TimeSpan classes in the framework.
They hold everything you need.
Regards,
mav
|
|
|
|
|
DateTime d1 = ...;
DateTime d2 = ...;
TimeSpan diff = d2 - d1;
now diff will give you hours, months, days... whatever you need.
|
|
|
|
|
Hi all:
I am recently thinking is it possible to serialize an assembly (I descover it in run-time) and transfer it to the remote client. Thus, the client can execute it? Bellow are more on my idea
Server:
Discover some assembly that the client may need the function that I already pre-compiled as a .dll file in server, then the server load it and send the assembly to the remote client.
Client:
This is a generic client it doesn't have much functionality by itself, but it can discover what assembly have on the server. If the function the client is needed, server will load the assembly dynamically and transfer to the client. So the client have the function to use.
By implementing this, the client can be compact and dynamic in the function.
The client even can write the source code and compile the source into an assembly which will be stored in the server. And let other client to discover and use this assembly too.
Regards,
Joel
|
|
|
|
|
Im not sure if I understand what you mean. Why dont you just send the assembly as binary data, save it on the client machine and load and execute it via reflection?
|
|
|
|
|
joelwu wrote:
By implementing this, the client can be compact and dynamic in the function.
The client even can write the source code and compile the source into an assembly which will be stored in the server. And let other client to discover and use this assembly too.
Your best bet might be to go with .NET Remoting. Read the following article : Microsoft .NET Remoting: A Technical Overview[^]
- Nick Parker My Blog | My Articles
|
|
|
|
|
I created a thread a little bit ago that has some code that demonstrates a problem that I have. Basicaly I'm trying to do double buffering and I "trick" windows.forms into painting the control onto a buffer, the problem is, is it also paints a black rectangle where the control is(I know it is also painting my control because I can scale the window and the control will go while the black box doesn't)... I also know it is the parent that is doing this and not the control since I have completely disabled the control's painting functions and still have the problem... It seems that either the form is excluding the region from being updated for painting by the form's OnPaint/OnPaintBackground("no need to paint behind a control") and painting it black, or that its trying to paint the control but there is some kinda "bug"...
I've overriden the forms wndproc and took out the WM_PAINT and it doesn't draw the black box, but does not render that area at all(which makes me believe that the form has excluded the controls region from being painted at all, I put painting the background on a timer, so the background is showing up... just not anything where that square is...)...
since I don't know much about how windows handles the control, I'm wondering if someone can help me out... I'm sure theres somethere where I can tell windows not to exclude region behind the controls from being updated... not sure if its in my PaintEventArgs or somewhere in the WinProc...
Anyways, thanks for any advice/help...
BTW, I do not have WS_CLIPCHILDREN set in my styles(override CreateParams)... which would seem to be the cause if I did.
|
|
|
|
|
My problem is ,
I want to make a secret form that I want to make it possible to see when key combination I defined pressed...
For Example :
when ( Shift + ALT + S ) pressed my secret form will be visible..
but I can only catch one key...
I tried something like ,
if(Control.ModifierKeys == Keys.LShiftKey && Control.ModifierKeys == Keys.LControlKey) Doesnt work && is invalid syntax for keys
then tried
if(Control.ModifierKeys == (Keys.LShiftKey + Keys.LControlKey))
no doesnt work...
if you could help me I would be glad..Thank you
|
|
|
|
|
Do the following:
Set the property "KeyPreview" of the form you want the key combination to be available in to "True", otherwise you won't get the keys if another control on your form receives and handles them before you do.
Then add an event handler for KeyUp to your visible form and add this code:
if (e.KeyCode == Keys.S &&
(e.Modifiers & Keys.Shift) == Keys.Shift &&
(e.Modifiers & Keys.Alt) == Keys.Alt)
{
MessageBox.Show("Secret combination pressed: Shift+Alt+S");
e.Handled = true;
}
else
{
e.Handled = false;
}
That's it.
Mav
|
|
|
|
|
Thanks for your help Mav, your code works very well , and that was what I need..Thanks again..have a nice day...
|
|
|
|
|
try
if ((Control.ModifierKeys & Keys.LShiftkey) == Keys.LShiftKey && (Control.ModifierKeys & Keys.LControlKey) == Keys.LControlKey))
{
}
Gary
"I invented the internet".
- Al Gore, former U.S. Vice President
|
|
|
|
|
I'm trying to build a Assembly that extract a compressed file when I start the Assembly. I have found samples that extracts the resources but no code to add resources programmaticly. Every sample I have read says something like this:
"The next step is to add the files you want as a resource to the project. To do this you right click on the project name, and select "Add Existing Items." This will bring up a dialog where you can select the files to add. This will cause VS.NET to copy the file into your project's directory if it is not already there. This file is now part of the project you previously..."
I have tried to use the System.Reflection.Emit.AssemblyBuilder class but when I try to build the project it's only saying that I can't use it due to it's protection level.
Please help me someone!
Sincerly, Richard
|
|
|
|
|
Is it possible to open two or more console windows from the same exe?
thanks
|
|
|
|
|
How many ways are there to pass values in windows forms.
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
Lots! Are you asking about a particular method? What exactly are you having problems with?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I want to open a new form and then retrieve a few values from the new form.
|
|
|
|
|
Dirty Method: Make all controls of the form public. Then you have complete access to everything.
Clean:
- Make public/internal properties/methods to read the values from the form.
- Let the form fire events when values are changed. These could be handled and evaluated.
If the new form ist shown modal you can also:
- Define a function in the new form which will show it modal and return the value you need. If you need more than one value you could insert some out/ref-parameters.
There will be thousands of possibilities to exchange values, but I think you should try it with properties (as mentioned above)
|
|
|
|
|
_Hacker wrote:
My brain is 2 small for all the knowledge that I need
What a curious thing to say.
It is commonly known that humans generally do not exceed 10% usage of their brain's capacity. Therefore it is more likely that you are not utilising the capacity you have efficiently.
If you search Amazon for the author "Tony Buzan" you should find some books on how to more effectively utilise your brain so that you retain and recall information more efficiently.
Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|