我已经在我的应用程序中实现了拖放操作,但是在确定被拖动对象的类型时遇到了一些困难.我有一个基类Indicator和几个派生自它的类.拖动的对象可以是任何这些类型.下面的代码片段似乎不够优雅,容易出现维护问题.每次我们添加一个新的派生类时,我们都要记得触摸这个代码.看起来我们应该能够以某种方式使用继承.
protected override void OnDragOver(DragEventArgs e)
{
base.OnDragOver(e);
e.Effect = DragDropEffects.None;
// If the drag data is an "Indicator" type
if (e.Data.GetDataPresent(typeof(Indicator)) ||
e.Data.GetDataPresent(typeof(IndicatorA)) ||
e.Data.GetDataPresent(typeof(IndicatorB)) ||
e.Data.GetDataPresent(typeof(IndicatorC)) ||
e.Data.GetDataPresent(typeof(IndicatorD)))
{
e.Effect = DragDropEffects.Move;
}
}
Run Code Online (Sandbox Code Playgroud)
同样,我们使用GetData实际获取拖动对象时遇到问题:
protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop(e);
// Get the dragged indicator from the DragEvent
Indicator indicator = (Indicator)e.Data.GetData(typeof(Indicator)) ??
(Indicator)e.Data.GetData(typeof(IndicatorA)) ??
(Indicator)e.Data.GetData(typeof(IndicatorB)) ??
(Indicator)e.Data.GetData(typeof(IndicatorC)) ??
(Indicator)e.Data.GetData(typeof(IndicatorD));
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
如何创建一个只包含一些数据文件且没有内置输出的项目文件(VS 2008)?
我可以创建一个空项目并将我的数据文件添加到它(它被复制到输出文件夹),但它在我进行构建后生成一个EmptyProject.dll.我只想要输出目录中的数据文件,而不是一些空的DLL或EXE.
我希望数据文件是这个项目中唯一的东西,因为项目将在几个解决方案中共享.
我们的应用程序是C#.我们所有的常规代码项目都是C#.
数据文件是模式(XSD).我希望这些模式位于输出文件夹中,但我不希望它们包含在现有项目中.我想要一个名为"Schemas"的项目,除了XSD文件之外什么都没有,除了将XSD文件复制到输出文件夹之外什么都不做.我想在项目文件中这样,以便可以在多个解决方案中引用相同的模式项目.
我从数据库中获取checkedListBox值.根据我的复选框选择它将执行一些操作.我必须编写已检查项目的代码.