|
I can't really understand your question? Can you give a short sample program that demonstrates it?
And doesn't textbox.Text += "'" work?
Regards
Senthil
My Blog
|
|
|
|
|
oops, yeah, "'" works. I meant how to insert the " symbol.
int current = 1;<br />
int lines = richTextBox1.Lines.GetLength(0);<br />
if (lines < 3)<br />
{<br />
MessageBox.Show("You need to have atleast three lines, otherwise this application is useless", "Useless he he ;)", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);<br />
}<br />
else<br />
{<br />
richTextBox2.Text = '"' + richTextBox1.Lines[0] + '"' + " " + '+' + " " + '"' + @"\r\n" + '"' + " " + '+' + " ";<br />
while (lines > 2)<br />
{<br />
richTextBox2.Text += '"' + richTextBox1.Lines[current] + '"' + " " + '+' + " " + '"' + @"\r\n" + '"' + " " + '+' + " ";<br />
current ++;<br />
lines --;<br />
}<br />
if (lines > 1)<br />
{<br />
richTextBox2.Text += '"' + richTextBox1.Lines[current] + '"';<br />
}<br />
}
what happens is, the user inputs text into the richTextBox1, and when the user clicks a button to run the above code, the code is sent to the richTextBox2. the problem is, all the code must be on one line, formatted properly on that line, and display the formatting (text) necessary for the outputted code to be useable in another application where there could potentiall be hundreds of lines of text, without manuall writing all the "\r\n"'s to format it. the problem is, what if the person puts in "\r\n" into the input richTextBox1? or what if they put in a " symbol or a ; symbol. the contents of richTextBox1 are formatted in the code above, but the problem is, where you see "richTextBox1.Lines[current]", the symbols that user inputted as described above, screw up the formatting when ouputting the text to richTextBox2.
like for instance, say I put the " symbol in richTextBox2. it will then think it has reached the end of the string to be formatted, when that is not the correct " symbol to stop at.
please help, this would be a very helpful application to people I think, atleast for me when I want to format many paragraphs so I can just paste the code for an application that needs text formatted to a textbox in such a way.
the current code I have works like a dream, except it messes up as described above when these symbols are inserted:
;
'
"
+
and possibly a couple others.
if there is no easy way you can think of, my idea was to use a regular expression, and select and replace all those symbols with "'", etc.
the problem with this is, """ doesn't work to place the " symbol to a string or insert it into a text box as text. same with the ; and other symbols. how do I do this?
hilf mir!!!,
Danke schoen,
Stephen
|
|
|
|
|
|
see the problem is, that I need to escape the contents of the variable, not the variable itself. so escaping it would place the variable into the text, rather than its contents. also, as earlier, the " symbol would stop the escape before the correct " symbol is reached. this would mess things all up.
|
|
|
|
|
Question #1: ASCII Collating Sequence:
I would like my application to utilize some keyboard shortcuts like the UP ARROW, DOWN ARROW, LEFT ARROW, RIGHT ARROW, TAB KEY, and SHIFT KEY. I would like to implement them into a KEYPRESS event at the form level but I do not know what the ASCII collating sequence is to represent them in the KEYPRESS event.
Here is my code so far:
<br />
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);<br />
<br />
public Form1_KeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
if (e.KeyChar == (char)13)<br />
{<br />
statusBar.Hide()<br />
e.Handled;<br />
}<br />
else<br />
{<br />
statusBar.Show();<br />
e.Handled;<br />
} <br />
}<br />
I looked throught the VS.NET help files and through the internet but could not find the aforementioned ASCII code numbers nor how to specifically represent them at the form level so that they would be triggered by their respective key press events. Would appreciate some assistance at examining this issue in more detail.
Question #2: Form Container:
I would like my application to have the forms incorporated inside the main form and not as separate forms all over the screen. When the main form moves, I would like the children forms to be moved as well, and when the main form minimizes, I would like the child form to be minimized INSIDE of the main form rather than inside of the windows minimization bar at the bottom of the screen. I looked through all of my C# books, and have not encountered this mentioned in any of my classroom studies. Could somebody kindly point me in the right direction? I would really appreciate the input. Thanks
|
|
|
|
|
Question 1: You must listen for the KeyDown event, IIRC, arrow keys don't trigger KeyPress. And the KeyDownEventArgs has a enumeration that lists all arrow keys..
Question 2 : You are looking for MDI (Multiple Document Interface) forms. Look for the MDIParent property of the Form class.
Regards
Senthil
My Blog
|
|
|
|
|
S. Senthil Kumar:
I have found the MDIParent property in the Form class as you had suggested, but I am uncertain how to implement it. Puzzling thing is though, why isn't the MDIParent property available in the Properties window, is it an abstract class or something? Do I implement it in the child class like this in the onLoad event like so:
frmMainForm frm = new frmMainForm();
this.MDIParent = frm;
and should I select isMDIParent in the Main Form first? Trouble is, when I do select isMDIParent to true, the background color shifts for some reason to a light gray. An alternative optional guess of how to implement the MDIParent property would be to put
frmChildForm frmChild = new frmChildForm();
this.MDIChild = frmChild;
into either the form designer section with all of the variable assignments, or into the onLoad button for the frmMainForm form. What IS the PROPER way to implement an MDI form in C#?
Also, with regard to the implementation of the KeyDown event, how would I implement a KeyDown event trap for the UP and DOWN arrows for example?
|
|
|
|
|
new_phoenix wrote:
I would like my application to utilize some keyboard shortcuts like the UP ARROW, DOWN ARROW, LEFT ARROW, RIGHT ARROW, TAB KEY, and SHIFT KEY. I would like to implement them into a KEYPRESS event at the form level but I do not know what the ASCII collating sequence is to represent them in the KEYPRESS event.
Not all of the keys you mentioned have a corresponding ASCII Character Code[^]. Therefore I suggest you use the Control.KeyDown Event[^] instead. You can find out which key has been pressed by checking the KeyEventArgs.KeyCode Property[^]. For example:
private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.PageUp)
MessageBox.Show("PageUp pressed");
}
new_phoenix wrote:
I would like my application to have the forms incorporated inside the main form and not as separate forms all over the screen. When the main form moves, I would like the children forms to be moved as well, and when the main form minimizes, I would like the child form to be minimized INSIDE of the main form rather than inside of the windows minimization bar at the bottom of the screen.
This is called MDI application (see Multiple document interface[^]). You can find a lot of information about how to create MDI applications on MSDN (see Multiple-Document Interface (MDI) Applications[^]).
Best regards
Dennis
|
|
|
|
|
Dennis C. Dietrich:
I have found the MDIParent property in the Form class as you had suggested, but I am uncertain how to implement it. Puzzling thing is though, why isn't the MDIParent property available in the Properties window, is it an abstract class or something? Do I implement it in the child class like this in the onLoad event like so:
frmMainForm frm = new frmMainForm();
this.MDIParent = frm;
and should I select isMDIParent in the Main Form first? Trouble is, when I do select isMDIParent to true, the background color shifts (for some reason) to a light gray, even when I change the background color back to the preferred designated color. An alternative optional guess of how to implement the MDIParent property would be to put:
frmChildForm frmChild = new frmChildForm();
this.MDIChild = frmChild;
into either the form designer section with all of the variable assignments, or into the onLoad button for the frmMainForm form. What IS the PROPER way to implement an MDI form in C#?
Also, with regard to the implementation of the KeyDown event, could I implement a KeyDown event at the form level? How would I implement a KeyDown event trap for the UP and DOWN arrows for example? Using your code as an example, could you kindly assist me in correcting this revised code, and please explain to me why the code is not being triggered by pressing the TAB button:
<br />
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmSolitaireMainForm_KeyDown);<br />
<br />
private void frmSolitaireMainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{ <br />
if (e.KeyCode == Keys.Tab)<br />
{<br />
if (statusBar.Visible == true)<br />
{<br />
statusBar.Hide();<br />
e.Handled=true;<br />
}<br />
else<br />
{<br />
statusBar.Show();<br />
e.Handled=true;<br />
}<br />
}<br />
}<br />
|
|
|
|
|
new_phoenix wrote:
I have found the MDIParent property in the Form class as you had suggested, but I am uncertain how to implement it.
I didn't suggest that. That was Senthil.
new_phoenix wrote:
Puzzling thing is though, why isn't the MDIParent property available in the Properties window, is it an abstract class or something?
This makes perfectly sense. The Form.MdiParent Property[^] is of the type Form[^]. Accordingly you need to assign an instance of that class and that of course is only possible at runtime.
new_phoenix wrote:
Do I implement it in the child class like this in the onload event like so:
I'm wondering if you actually read the information on MSDN I mentioned. It's all explained there including working code samples. So, again please check out Multiple-Document Interface (MDI) Applications[^] (especially Creating MDI Child Forms[^]).
new_phoenix wrote:
and should I select isMDIParent in the Main Form first?
If you don't set the Form.IsMdiContainer Property[^] to true you'll get an exception when trying to show a MDI Child.
new_phoenix wrote:
Also, with regard to the implementation of the KeyDown event, how would I implement a KeyDown event trap for the UP and DOWN arrows for example?
There isn't anything like an "event trap". I suggest you read some paragraphs about event handling and delegates (see Events Tutorial[^] and Delegates Tutorial[^]). The code I posted in my previous message is an example for an event handler for the Control.KeyDown Event[^]. As the type of the KeyEventArgs.KeyCode Property[^] is Keys[^] and Keys is an enumeration[^] you don't have to define the key codes yourself.
Best regards
Dennis
|
|
|
|
|
Dennis:
Thanks! The resources you had provided will be very helpful. I was just reading through it and it will take some time to digest. This is a new concept to me and I have not implemented it before - not covered in school very well. I appreciate the direction toward more information about the implementation of events and delegates as the textbooks that I have read do not cover it very well.
Thanks again!
New_Phoenix
|
|
|
|
|
Did you try setting the form's KeyPreview property to true?
Regards
Senthil
My Blog
|
|
|
|
|
How can i get to the registry files and add keys and stuff using C#?
|
|
|
|
|
|
Hello,
How do I make an add-in that when someone right clicks on any selected text, that in a context menu that appears an option appears that I have made(don't know how to do) does executes a bit of code..
Thanks in advance..
modified 19-Aug-21 21:01pm.
|
|
|
|
|
hi,
I know how to format a paragraph programmatically, using "\r" to return to the next line in a rich text box, and continue adding text to the next line. but there are a couple problems I've run into doing this. first, I hate putting a giant paragraph on a single line, cause it makes the (i think it's called) buffer really wide, kinda like not turning on word wrap. Secondly, my main problem is, it takes a long time to insert all the + "\r" + "text "\r", etc. is there an easier way to do this? if not, someone should make a tutorial with an app. I thought about trying to do this myself, but I don't know how to use regular expressions very well, which seems the best way to go about making an app that could do this. that could automatically reveal formatting. Keep in mind, I would like to insert this text at the current cursor position. thanks for the help,
Stephen
|
|
|
|
|
A "buffer" is a block of memory that holds data. The text buffer (a char[] array, actually) will be even larger if you insert return codes because you'll be including 1-2 extract characters every so often. How the buffer is displayed is a user interface.
If you want to insert a return code you must use the correct return code for the underlying platform. The Environment.NewLine property abstracts this detail away from you, since - on Windows - the actual new line constant is "\r\n". For console output you can use simply "\n" which gets translated appropriately, but for most text you should use Environment.NewLine . For example:
string value = string.Format("This is a{0}broken line.{0}This is a separate line.", Environment.NewLine);
label1.Text = value;
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
thanks for the help. I was wandering though,is there a way to actually reveal formatting. like, insert text into one richTextBox and then ouput the text with the formatting symbols ("\r\n"), or the thing you showed me in a second richTextBox? This would be very very helpful to me. thanks again.
|
|
|
|
|
ok I think I figured it out. one thing though, how do I insert the text "\r\n" as text, without using it as actual formatting.
|
|
|
|
|
You can escape them like "\\r\\n" or use the verbatim modifier @"\r\n".
Regards
Senthil
My Blog
|
|
|
|
|
I am writing a prog that will process data every 15 mins to 1 hour.
I have looked at System.Timer and Window Timer but they seem to be conern about millisecond timing and I presume that the amount of resources (processer and RAM) that it requires might be wasted since I only require accuracy of a minute.
I was wondering if you guys actually use Timers with elapse time of 15 mins - an hour or is there a better solution for this.
|
|
|
|
|
A timer uses very little resources because it works with your system clock which is essential to making your computer work. Your CPU and system clock work together. Any computer engineering book you could pick up will help you understand this better.
Note that there are actually 3 timers in the .NET BCLSystem.Threading.Timers System.Timers.Timer - System.Windows.Forms.Timer
Each have a resolution of 1 millisecond but work different ways, like requiring a callback or exposing an event (to which you add a handler, or callback).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I have a tabcontrol with 4 tabpages.
Each tabpage contains a richtextbox.
I do not have anyproblem running my application and viewing all the tabs when the system font is set to small font. When the font is set to large font, all the tab pages become gray and the richtextboxes are not shown at all!
Does anyone know of a solution to this problem?
(setting the AutoSize property of the RichTextBoxes to true does not help )
Thanks.
avivhal
|
|
|
|
|
How exactly do you mean? The system fonts are set to large while your application is running and the TabControl shown, or even when the fonts are set to large before your application is running? The latter should not cause problems, but the former situation can. Handling the SystemEvents.UserPreferenceChanged event may help so that you can react accordingly, often times call Control.Update on controls that having trouble updating their drawing surface themselves.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The system font is set to large before the application is running. This causes the tabs not to appear. If the font is set to small the problem is gone and all tabs are shown.
I have actually only seen this behavior on windows 2000 systems. On XP the problem does not exist. Does this make any difference?
Could it be a .NET CLR issue?
Thanks.
avivhal
|
|
|
|
|