C# 如何在windows窗体应用程序和用户控件dll文件中使用变量类?
在windows窗体项目中,我创建了一个新类:C# 如何在windows窗体应用程序和用户控件dll文件中使用变量类?,c#,.net,winforms,dll,C#,.net,Winforms,Dll,在windows窗体项目中,我创建了一个新类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FTP_ProgressBar { class FtpConfig { public static string txtHost; public st
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FTP_ProgressBar
{
class FtpConfig
{
public static string txtHost;
public static string txtUsername;
public static string txtPassword;
public static string txtDir;
public static string txtUploadFile;
public static string txtPort;
public static System.Windows.Forms.CheckBox chkPassive;
public static FtpSettings f;
}
}
在form1中,我有一个单击按钮,在这里我调用一个具有以下设置的方法:
private void btnUpload_Click(object sender, EventArgs e)
{
FtpSettings();
}
然后:
问题是,在我的form1 designer中有一个控件,我在将dll文件添加到工具箱后将其拖到该控件上,该控件类似于带有treeView1和listView1的windows资源管理器:
左边是浏览器窗口,C节点树已展开
问题是,在这种情况下,我需要调用/使用form1中的FtpSettings()方法和dll库类:
void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Upload")
{
List<String> selected = new List<String>();
string dir = treeView1.SelectedNode.FullPath;
dir = dir + "\\";
foreach (ListViewItem lvi in listView1.SelectedItems)
{
string g = Path.Combine(dir, lvi.Text);
selected.Add(g);
}
AllFiles = selected.ToArray();
FilesFromExplorerOrManual = false;
Bgw.RunWorkerAsync();
}
}
此行后:FtpSettings()
但首先,在将事件拖到form1设计器后,我无法访问它。
其次,我可能需要在此dll中的其他事件中调用FtpSettings()
我在form1 designer中拖动它后尝试了,然后我有一个变量:explorerTree1,所以我尝试在form1构造函数中执行以下操作:
explorerTree1.MouseUp += explorerTree1_MouseUp;
然后:
我使用了断点,但它从未停止/到达此事件。它也不是我需要访问的dll文件中的同一事件。您应该查看拖放事件。由于主题相当广泛,请复习
if (e.ClickedItem.Text == "Upload")
explorerTree1.MouseUp += explorerTree1_MouseUp;
void explorerTree1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
FtpSettings();
}
}