Sorry for the Double Post i accidently posted this in the Wrong section.
Hi, i have my mainform referenced in my dll proj. I am wondering how i can call the dll file to read a text file and send the text to a textbox on the mainform:
On the mainfrm it isn't giving me the option to add the delegate "TextSender". Once i get that i should be fine with the app part of it. What i would want to put here is textReader.TextSender = ProcessText;
public partial class mainfrm : Form
{
public mainfrm()
{
InitializeComponent();
}
private void rfButton_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "Select A Text File";
open.InitialDirectory = @"C:\";
open.Filter = "Supported Files|*.txt";
open.Multiselect = false;
open.ReadOnlyChecked = false;
if (open.ShowDialog() == DialogResult.OK)
{
foreach (string filename in open.FileNames)
{
textRead.ReadText(open.FileName);
}
}
}
private void ProcessText(string text)
{
textBox1.Text = text;
textBox1.Invalidate();
}
}
The compiler complains when i try to add this.TextSender(sr.ReadLine()) giving the message below. But I need to have that method static so i can call it from the mainfrm (as shown above).
public class textRead
{
public delegate void AddText(string text);
public AddText TextSender
{
get
{
return TextSender;
}
set
{
TextSender = value;
}
}
public static void ReadText(string source)
{
using (StreamReader sr = new StreamReader(source))
{
this.TextSender(sr.ReadLine());
//^Keyword 'this' is not valid in a static property, static method, or static field initializer
}
}
}
Thanks again for your help!
Don't be overcome by evil, but overcome evil with good

Dll Help
Paul2006
I made a few changes and i have everything fixed okay accept this last error:
public class textRead
{
public delegate void AddText(string text);
public AddText TextSender;
public static void ReadText(string source)
{
using (StreamReader sr = new StreamReader(source))
{
textRead tr = new textRead(); // -- Reference
tr.TextSender(sr.ReadLine());
//^ Object reference isn't initialized (isn't the exact error verbatum)
}
}
}
I dunno what the issue could be. It acually compiles at runtime however when i use the function it throws this error
Carol Pahl
Why don't you just create a new instance of the textRead class and use that Then the members don't have to be static.
This will cause recursion until you're out of stack space.