I am a beginner in C#, and currently only know of the richTextBox.AppendText() method.
I have heard of a insert text method but am not sure how to use it. Could anyone please tell me of the insert text method and other methods of inserting text into a rich text box with an example of each.
Thanks in Advance.
Methods of inserting into a rich text Box
Page 1 of 14 Replies - 3104 Views - Last Post: 03 April 2011 - 05:02 AM
Replies To: Methods of inserting into a rich text Box
#2
Re: Methods of inserting into a rich text Box
Posted 02 April 2011 - 05:41 PM
I am a beginner in C# and am trying writing a program that generates a weekly pay, for pay rates $12 - $20 per hour, working from 5 - 20 hours. No user input is required, just to click a button and it should generate a table using for loops.
I've written the following code so far:
The output, when I run the program looks like this:
The last column containing the hrs/wk should be the first column from the left hand side not the last (kind of like a multiplication table), and when I can take it to the left hand side instead of looking like ":: 15hrs/wk" it will look like "15hrs/wk:". I cannot get it to go on the left had side as a vertical column without it messing up the whole table.
Any advice and help on how to get it there would be much appreciated.
Also is there a better way of inserting text into a rich text box than append text? If so could you give an example of how and explain?
Thanks is advance.
I've written the following code so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
richTextBox1.AppendText("\t" + "\t" + "\t" + "Pay Rate: Dollars Per Hour" + "\n" + "\n");
richTextBox1.AppendText("\t" + "12" + "\t" + "13" + "\t" + "14" + "\t" + "15" + "\t" + "16" + "\t" + "17" + "\t" + "18" + "\t" + "19" + "\t" + "20" + "\n" + "\n");
for (int hoursperweek = 5; hoursperweek <= 20; hoursperweek++)
{
for (int payrate = 12; payrate <= 20; payrate++)
{
if (hoursperweek == 4)
{
richTextBox1.AppendText("\t" + hoursperweek + "\n");
}
else
{
richTextBox1.AppendText("\t" + hoursperweek * payrate);
}
}
richTextBox1.AppendText("\t" + ":: " + hoursperweek + "hrs/wk" + "\t" + "\n");
}
The output, when I run the program looks like this:
The last column containing the hrs/wk should be the first column from the left hand side not the last (kind of like a multiplication table), and when I can take it to the left hand side instead of looking like ":: 15hrs/wk" it will look like "15hrs/wk:". I cannot get it to go on the left had side as a vertical column without it messing up the whole table.
Any advice and help on how to get it there would be much appreciated.
Also is there a better way of inserting text into a rich text box than append text? If so could you give an example of how and explain?
Thanks is advance.
This post has been edited by ashimashi619: 02 April 2011 - 05:44 PM
#3
Re: Methods of inserting into a rich text Box
Posted 02 April 2011 - 06:31 PM
#4
Re: Methods of inserting into a rich text Box
Posted 02 April 2011 - 06:41 PM
Why did you start a new thread for this?
You already have a thread for this homework assignment
http://www.dreaminco...1&#entry1299497
In that thread it was suggested you try to do this in console before trying it with the added complication of a WinForm RichTextBox. You don't seem to have taken that advice. SO if you aren't taking the advice from the people you are asking, why would those same people continue to give you advice you're most likely going to also ignore?
The text is going to look like what you tell it to look like. It is on the right because that is what you are coding.
You've voiced a complaint about what it looks like when it is wrong, but that isn't the code or screenshot you provided. So how can anyone here help you fix the wrong code you didn't provide?
NO.
Because this is your school homework. We cannot give you the answers. Especially when you have not shown us an effort to actually write code to solve your problem. YOu have shown us code that does something different than what you want. But you have NOT shown code that makes an effort to resolve your problem. For all we know you just copy/pasted that code from another student and have no idea whatsoever on how to do what you need. We need to see a good faith effort to actually solve the problem.
You already have a thread for this homework assignment
http://www.dreaminco...1&#entry1299497
In that thread it was suggested you try to do this in console before trying it with the added complication of a WinForm RichTextBox. You don't seem to have taken that advice. SO if you aren't taking the advice from the people you are asking, why would those same people continue to give you advice you're most likely going to also ignore?
Quote
when I can take it to the left hand side instead of looking like ":: 15hrs/wk" it will look like "15hrs/wk:"
The text is going to look like what you tell it to look like. It is on the right because that is what you are coding.
richTextBox1.AppendText("\t" + ":: " + hoursperweek + "hrs/wk" + "\t" + "\n");
You've voiced a complaint about what it looks like when it is wrong, but that isn't the code or screenshot you provided. So how can anyone here help you fix the wrong code you didn't provide?
Quote
Also is there a better way of inserting text into a rich text box than append text? If so could you give an example of how and explain?
NO.
Because this is your school homework. We cannot give you the answers. Especially when you have not shown us an effort to actually write code to solve your problem. YOu have shown us code that does something different than what you want. But you have NOT shown code that makes an effort to resolve your problem. For all we know you just copy/pasted that code from another student and have no idea whatsoever on how to do what you need. We need to see a good faith effort to actually solve the problem.
#5
Re: Methods of inserting into a rich text Box
Posted 03 April 2011 - 05:02 AM
Merged duplicate topics. Please do not open a new topic on the same subject when you already have one.
Suggestion: use a StringBuilder to create the string as you want it, then insert it into the RichTextBox.
Suggestion: use a StringBuilder to create the string as you want it, then insert it into the RichTextBox.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|