Sam

Sam

  • NA
  • 166
  • 0

Novis question: Printing to a richTextBox

Sep 17 2009 2:40 AM

 
Hello,
I have a Win form application in which I get a key from a button and print the key name or text to a richTextBox.
When printing from the form class it prints OK.
When sending the key to another class and printing from there, it does not print.
The debugger shows that the data is passed OK, and the printing command has the data as it should, but it still does not print.
I suspect that the initialization of the text box clears the box immediately after printing, but I am (still) unable to fix the problem.
I know I do something wrong, but what???
Please help.
Attached is a minimal running snippet that shows it all.
Sam
 
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
WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Key_Click(object sender, EventArgs e)
{
OtherClass other = new OtherClass();
Button currentkey = (Button)sender;
string KeyText = currentkey.Text;
//Display(KeyText); //Prints OK from here.
other.GetTheKey(KeyText);
// send the key number to OtherClass.
}

public void Display(string text) //Will print OK with call from this class.
{
// will not print from another class call.

richTextBox1.AppendText(text);
}
}
class OtherClass
{
public OtherClass()
{
}
public void GetTheKey(string KeyText) //Called by the Form1 to transfer eack keystroke.
{
Form1 form1 = new Form1();
form1.Display(KeyText);
}
}
}

Answers (1)