Click here to Skip to main content
15,920,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: control on non client area of form Pin
James_Zhang25-Dec-08 18:02
James_Zhang25-Dec-08 18:02 
Question[Visual Studio | C#] richtextbox problem Pin
lucas moretti25-Dec-08 14:31
lucas moretti25-Dec-08 14:31 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
Luc Pattyn25-Dec-08 14:47
sitebuilderLuc Pattyn25-Dec-08 14:47 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
lucas moretti25-Dec-08 14:59
lucas moretti25-Dec-08 14:59 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
Christian Graus25-Dec-08 15:24
protectorChristian Graus25-Dec-08 15:24 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
lucas moretti25-Dec-08 15:35
lucas moretti25-Dec-08 15:35 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
Luc Pattyn25-Dec-08 15:41
sitebuilderLuc Pattyn25-Dec-08 15:41 
AnswerRe: [Visual Studio | C#] richtextbox problem Pin
N a v a n e e t h25-Dec-08 15:39
N a v a n e e t h25-Dec-08 15:39 
lucas moretti wrote:
public void button1_Click(object sender, EventArgs e)
{
Form1 Form1 = new Form1();
Form1.richTextBox1.AppendText("-Attachment-");
}


Above code will create Form1 instance each time when you press button. This is the problem you are facing.

lucas moretti wrote:
Form1.richTextBox1.AppendText("-Attachment-");


For the above code to work, you have to make richTextBox1 expose to outside of class which is not at all recommended.

To solve the problem, you can use either delegates or create a public method in the form1 and call it to update the richtextBox. Something like
public partial class Form2 : Form
{
    public void UpdateTextBox(string text)
    {
        richTextBox1.AppendText(text);
    }

    public void button1_Click(object sender, EventArgs e)
    {
        Form Form2 = new Form2(this);
        Form2.Show();
    }
}

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    Form1 form1 = null;
    public Form2(Form1 form1) : this()
    {
        this.form1 = form1;
    } 

    public void button1_Click(object sender, EventArgs e)
    {
        form1.UpdateTextBox("-Attachment-");
    }
}
Same code can be written using delegates. You declare a delegate in Form2, and when showing the form2, form1 subcribe on this and will get notified when the text changes.

Hope this helps. Merry X'Mas. Smile | :)


GeneralRe: [Visual Studio | C#] richtextbox problem Pin
lucas moretti25-Dec-08 15:44
lucas moretti25-Dec-08 15:44 
GeneralRe: [Visual Studio | C#] richtextbox problem Pin
Christian Graus25-Dec-08 16:19
protectorChristian Graus25-Dec-08 16:19 
Questionhow to invoke events of dynamically created controls Pin
DEEPNORTH25-Dec-08 11:41
DEEPNORTH25-Dec-08 11:41 
AnswerRe: how to invoke events of dynamically created controls Pin
Not Active25-Dec-08 12:17
mentorNot Active25-Dec-08 12:17 
AnswerRe: how to invoke events of dynamically created controls Pin
User 665825-Dec-08 13:04
User 665825-Dec-08 13:04 
GeneralRe: how to invoke events of dynamically created controls Pin
DEEPNORTH25-Dec-08 16:08
DEEPNORTH25-Dec-08 16:08 
GeneralRe: how to invoke events of dynamically created controls Pin
Luc Pattyn25-Dec-08 14:50
sitebuilderLuc Pattyn25-Dec-08 14:50 
Questiongridview problem Pin
bhatted25-Dec-08 4:28
bhatted25-Dec-08 4:28 
AnswerRe: gridview problem Pin
Lev Danielyan25-Dec-08 4:45
Lev Danielyan25-Dec-08 4:45 
GeneralRe: gridview problem Pin
bhatted25-Dec-08 11:09
bhatted25-Dec-08 11:09 
GeneralRe: gridview problem Pin
bhatted25-Dec-08 11:40
bhatted25-Dec-08 11:40 
QuestionStarting a process using Windows service in Vista Pin
queries36525-Dec-08 2:04
queries36525-Dec-08 2:04 
AnswerRe: Starting a process using Windows service in Vista Pin
Abhijit Jana25-Dec-08 3:27
professionalAbhijit Jana25-Dec-08 3:27 
GeneralRe: Starting a process using Windows service in Vista Pin
queries36525-Dec-08 19:24
queries36525-Dec-08 19:24 
GeneralRe: Starting a process using Windows service in Vista Pin
#realJSOP25-Dec-08 23:54
professional#realJSOP25-Dec-08 23:54 
GeneralRe: Starting a process using Windows service in Vista Pin
DaveyM6926-Dec-08 0:03
professionalDaveyM6926-Dec-08 0:03 
AnswerRe: Starting a process using Windows service in Vista Pin
I Believe In GOD25-Dec-08 9:35
I Believe In GOD25-Dec-08 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.