Post: Need Help With This
08-10-2015, 06:51 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Alright so pretty much I have 2 forms.

In form1 i have a richTextBox

and in form2 i have a button that will create & open up a .txt

the problem is that the button won't load the file on form1.

I tried adding a richtextbox to form2 and it loaded normally but i want it to load on form1.

Button Code On FORM 2

    
string pathUser69 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pathCombiner = Path.Combine(pathUser69 + @"\text editor\projects\");
string pathCompile = Path.Combine(pathCombiner + textEdit1.Text);
string path = pathCompile + @"\text.txt";
Directory.CreateDirectory(pathCombiner + textEdit1.Text);
if (!File.Exists(path))
{
File.Create(path).Dispose();
private Form1 f1 = new Form1();
f1.richTextBox1.LoadFile(path, RichTextBoxStreamType.PlainText);
}
else if (File.Exists(path))
{
XtraMessageBox.Show("There is already a file with that name", title);
}
(adsbygoogle = window.adsbygoogle || []).push({});
08-10-2015, 08:33 AM #2
Code
Banned
Originally posted by xMrMods View Post
Alright so pretty much I have 2 forms.

In form1 i have a richTextBox

and in form2 i have a button that will create & open up a .txt

the problem is that the button won't load the file on form1.

I tried adding a richtextbox to form2 and it loaded normally but i want it to load on form1.

Button Code On FORM 2

    
string pathUser69 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pathCombiner = Path.Combine(pathUser69 + @"\text editor\projects\");
string pathCompile = Path.Combine(pathCombiner + textEdit1.Text);
string path = pathCompile + @"\text.txt";
Directory.CreateDirectory(pathCombiner + textEdit1.Text);
if (!File.Exists(path))
{
File.Create(path).Dispose();
private Form1 f1 = new Form1();
f1.richTextBox1.LoadFile(path, RichTextBoxStreamType.PlainText);
}
else if (File.Exists(path))
{
XtraMessageBox.Show("There is already a file with that name", title);
}


this is the reason-
    Private Form1 f1 = new Form1(); 

youre basically setting a new instance of form1, so the textbox will always return the default value (blank), do this-

    
Form1 f1 = new Form1();

f1 = (Form1)Application.OpenForms["Form1"];


so this basically creates a new instance of form1, then fills it with the original forms content. Smile

The following user thanked Code for this useful post:

Chen Madhala
08-10-2015, 09:04 AM #3
Originally posted by Alpaca View Post
this is the reason-
    Private Form1 f1 = new Form1(); 

youre basically setting a new instance of form1, so the textbox will always return the default value (blank), do this-

    
Form1 f1 = new Form1();

f1 = (Form1)Application.OpenForms["Form1"];


so this basically creates a new instance of form1, then fills it with the original forms content. Smile


Alright so it works but this happens:
You must login or register to view this content.
08-10-2015, 09:06 AM #4
Code
Banned
Originally posted by xMrMods View Post
Alright so it works but this happens:
You must login or register to view this content.


i cant really understand whats happening i that gif, could you describe whats happening please :p
08-10-2015, 09:08 AM #5
Originally posted by Alpaca View Post
i cant really understand whats happening i that gif, could you describe whats happening please :p


So pretty much the text shows up for 1 second then it disappears
08-10-2015, 09:10 AM #6
Code
Banned
Originally posted by xMrMods View Post
So pretty the text shows up for 1 second then it disappears


hmm, could you upload a source / example project with what youre trying to do? finding it hard to understand what youre doing :p
08-10-2015, 09:13 AM #7
Originally posted by Alpaca View Post
hmm, could you upload a source / example project with what youre trying to do? finding it hard to understand what youre doing :p


I'll pm you the download link for the source bc i dont want anyone grabbing it.

    
Form1 f2 = new Form1();
f2 = (Form1)Application.OpenForms["Form1"];
f2.richTextBox1.LoadFile(path, RichTextBoxStreamType.PlainText);

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo