我想编写一个快速程序,并且当我将Properties.Settings分配给变量s时出现错误。 我想将它分配给这个变量,因为我的很多文本框需要分配一个设置的值,也因为有很多需要保存的设置。与Properties.Settings不兼容的可访问性?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SharpDock
{
public partial class SettingsWindow : Form
{
public Properties.Settings s = new Properties.Settings(); // This is the error.
public SettingsWindow()
{
InitializeComponent();
}
private void Settings_Load(object sender, EventArgs e)
{
app1.Text = s.app1;
app2.Text = s.app2;
app3.Text = s.app3;
app4.Text = s.app4;
app5.Text = s.app5;
app6.Text = s.app6;
ico1.Text = s.ico1;
ico2.Text = s.ico2;
ico3.Text = s.ico3;
ico4.Text = s.ico4;
ico5.Text = s.ico5;
ico6.Text = s.ico6;
}
private void abutton1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app1.Text = ofd.FileName;
s.app1 = ofd.FileName;
}
}
private void Accept_Click(object sender, EventArgs e)
{
s.Save();
MessageBox.Show("SharpDock", "You must restart the program for the changes to take effect.", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void abutton2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app2.Text = ofd.FileName;
s.app2 = ofd.FileName;
}
}
private void abutton3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app3.Text = ofd.FileName;
s.app3 = ofd.FileName;
}
}
private void abutton4_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app4.Text = ofd.FileName;
s.app4 = ofd.FileName;
}
}
private void abutton5_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app5.Text = ofd.FileName;
s.app5 = ofd.FileName;
}
}
private void abutton6_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe) | *.exe";
ofd.Title = "Which executable would you like to launch?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
app6.Text = ofd.FileName;
s.app6 = ofd.FileName;
}
}
private void ibutton1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico1.Text = ofd.FileName;
s.ico1 = ofd.FileName;
}
}
private void ibutton2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico2.Text = ofd.FileName;
s.ico2 = ofd.FileName;
}
}
private void ibutton3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico3.Text = ofd.FileName;
s.ico3 = ofd.FileName;
}
}
private void ibutton4_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico4.Text = ofd.FileName;
s.ico4 = ofd.FileName;
}
}
private void ibutton5_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico5.Text = ofd.FileName;
s.ico5 = ofd.FileName;
}
}
private void ibutton6_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files (*.png) | *.png";
ofd.Title = "Which icon would you like?";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
ico6.Text = ofd.FileName;
s.ico6 = ofd.FileName;
}
}
}
}
和错误是:
Error 1 Inconsistent accessibility: field type 'SharpDock.Properties.Settings' is less accessible than field 'SharpDock.SettingsWindow.s' C:\Users\Lewis\Documents\Visual Studio 2013\Projects\SharpDock\SharpDock\SettingsWindow.cs 14 36 SharpDock
请帮帮忙!我被这个错误困住了。
〜刘易斯
请勿张贴所有的代码只有导致错误的部分。你也可以将很多这些方法压缩成1或2种方法。 – deathismyfriend
尝试将's'声明为'private'或'internal' – MrPaulch