I have the following:
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FarmKeeper.Forms
{
public partial class FarmLogs : Form
{
static string errorLogText = "";
public string changedText = "";
public FarmLogs()
{
InitializeComponent();
string txtLoginLogPath = @"../../Data/LoginLog.txt";
StreamReader readLogins = new StreamReader(txtLoginLogPath);
txtLoginLog.Text = readLogins.ReadToEnd();
readLogins.Close();
loadLogs();
changedText = errorLogText;
txtErrorLog.Text = changedText;
}
public static void loadLogs()
{
string txtErrorLogPath = @"../../Data/MainErrorLog.txt";
StreamReader readErrors = new StreamReader(txtErrorLogPath);
errorLogText = readErrors.ReadToEnd();
readErrors.Close();
}
}
}
Now, what I want to do is to check if the string, changedText, changed.
I know a little about custom events but I just cannot figure this out, neither the ones on the internet.
IF changedText changed, then set another textbox to that string.
Replace your field by a property, and check if the value changes in the setter. If it changes, raise an event. There is an interface for property changes notification called
INotifyPropertyChanged:Just attach an handler to the
PropertyChangedevent: