6
Answers

print square of asterisks on the rich text box..

andy4442093

andy4442093

20y
7.1k
1
Hey , I am beginner at c#.. and was wondering as how to print square of asterix's when i enter say length fo side in the text box in the forms window .. I want the square of Asterix's of the side inputted by the user in the text box to be displayed in the rich text box which i have constructed in the windows form.. the way i am trying to do is static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { int side = Int32.Parse(textBox1.Text); int squareside= Square (side); richTextBox1.Text = "int side"+ squareside ; } public int Square (int side) { return side*side; } it does print outs the square of the number inputted in the text box to the rich text box but not the asterix's .. Please help!!! Cheers!! Andy
Answers (6)
0
sbugig

sbugig

NA 39 28.5k 20y
Hi; I also thought i missunderstood you, you were not very clear, anyway thanks cheers Sbugig
0
shimtanny

shimtanny

NA 440 0 20y
*g* i complete missunderstood you. Simon
0
andy4442093

andy4442093

NA 8 0 20y
Hey, Thanks very much. Thats the one i was looking for. Actually somehow i never got the idea as to apply a loop and get the solution.. Thanks for the solution but do feel sorry for myself as why i cant get a simple problem. Cheers Mate!!!!
0
sbugig

sbugig

NA 39 28.5k 20y
Hi: I guess i got you righ if you wanted to see something like the following:- side = 5 would produce - * * * * * * * * * * * * * * * * * * * * * * * * * I've just done the following helper static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { int side = Int32.Parse(textBox1.Text); printSquare(side, richTextBox1); } public void printSquare (int side, RichTextBox richTxtBx) { richTxtBx.Text = ""; for (int i = 0; i < side; i ++) { for (int j = 0; j < side; j++) { richTxtBx.Text += " *"; } richTxtBx.Text += "\n"; } } if it's not what you wanted to see get back to me, i'm also new to c#
0
shimtanny

shimtanny

NA 440 0 20y
Hi Do you need maybe the following: private string BuildSquareString(int side) { return side.ToString() + " * " + side.ToString(); } By the way, you can use System.Text.StringBuilder to build concatanted strings. Simon
0
shimtanny

shimtanny

NA 440 0 20y
Hi I'm not sure what you want to do... is it just to sepcify the side length and print out side * side as text? The operator * is used for multiplication, and if you do side*side (side is type of int) then it calculates the numbers by multiplying. Cheers Simon