ok, this is driving me mad, I don't have any C# experience, and I'm trying to convert a project of mine from VB.NET to C#, I have converted online most of my code, and fixed any conversion problems except the ones where I access objects of a form on another form.
This is very simple to do in VB.NET, as I just add FormX before MyObject, and it is fixed, but in C# it seems to work differently.
My Code is below, and when I try to call the NotifyIcon1 that belongs to Form1 on the code on my Form3 I would get the error "An object reference is required for the non-static field, method, or property" for which I googled about an hour before I gave up since I couldn't understand how to make it work, even though there were plenty of articles on this.
the errors are the same I guess, and I got some more on form1, but if anyone here could fix me one of them I think I shouldn't have problems fixing the rest.
This is very simple to do in VB.NET, as I just add FormX before MyObject, and it is fixed, but in C# it seems to work differently.
My Code is below, and when I try to call the NotifyIcon1 that belongs to Form1 on the code on my Form3 I would get the error "An object reference is required for the non-static field, method, or property" for which I googled about an hour before I gave up since I couldn't understand how to make it work, even though there were plenty of articles on this.
the errors are the same I guess, and I got some more on form1, but if anyone here could fix me one of them I think I shouldn't have problems fixing the rest.
using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Diagnostics; using System.Windows.Forms; using System.Linq; using System.Xml.Linq; using System.IO; namespace Converted_App { public partial class Form3 { internal Form3() { InitializeComponent(); } private void Form3_Load(object sender, System.EventArgs e) { string ProgramFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string Company = ProgramFiles + "\\Test Company"; string Product = Company + "\\Test Product"; StartupCheckBox.Checked = Properties.Settings.Default.AddToStartup; TrayIconBox.Checked = Properties.Settings.Default.ShowIconInTray; AlwaysOnTopCheckBox.Checked = Properties.Settings.Default.AlwaysOnTop; } private void StartupCheckBox_CheckedChanged(object sender, System.EventArgs e) { /*This code is just fine if (StartupCheckBox.Checked == true) { Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true).SetValue(Application.ProductName, Application.ExecutablePath); Properties.Settings.Default.AddToStartup = true; Properties.Settings.Default.Save(); } else { Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true).DeleteValue(Application.ProductName); Properties.Settings.Default.AddToStartup = false; Properties.Settings.Default.Save(); } } */ private void TrayIconBox_CheckedChanged(object sender, System.EventArgs e) { if (TrayIconBox.Checked == true) { Properties.Settings.Default.ShowIconInTray = true; Properties.Settings.Default.Save(); Form1.NotifyIcon1.Visible = true; // THIS BRINGS UP THE ERROR } else { Properties.Settings.Default.ShowIconInTray = false; Properties.Settings.Default.Save(); Form1.NotifyIcon1.Visible = false; // THIS BRINGS UP THE ERROR } } private void AlwaysOnTopCheckBox_CheckedChanged(object sender, System.EventArgs e) { if (AlwaysOnTopCheckBox.Checked == true) { Form1.TopMost = true; // THIS BRINGS UP THE ERROR Properties.Settings.Default.AlwaysOnTop = true; Properties.Settings.Default.Save(); } else { Form1.TopMost = false; // THIS BRINGS UP THE ERROR Properties.Settings.Default.AlwaysOnTop = false; Properties.Settings.Default.Save(); } } } } //end of root namespace