- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在将文件拖放到 richTextBox 上时遇到问题,每次我将文本文件拖到它上面时,它都会变成文本文件的图片,并在其下方显示其名称。双击该文件,它会使用系统默认应用程序(即用于文本文件的记事本等)打开。基本上它在 richTextBox 中创建快捷方式,当我希望它读取文件中的文本时。
根据这段代码,文件中的文本应该提取到 richTextBox1 中
class DragDropRichTextBox : RichTextBox
{
public DragDropRichTextBox()
{
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(DragDropRichTextBox_DragDrop);
}
private void DragDropRichTextBox_DragDrop(object sender, DragEventArgs e)
{
string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileNames != null)
{
foreach (string name in fileNames)
{
try
{
this.AppendText(File.ReadAllText(name) + "\n");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
关于如何使这项工作有任何想法吗?
最佳答案
在读入文件之前,您需要检查被拖动的对象。试试下面的代码。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
richTextBox1.AllowDrop = true;
}
void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
object filename = e.Data.GetData("FileDrop");
if (filename != null)
{
var list = filename as string[];
if (list != null && !string.IsNullOrWhiteSpace(list[0]))
{
richTextBox1.Clear();
richTextBox1.LoadFile(list[0], RichTextBoxStreamType.PlainText);
}
}
}
关于c# - 将文件拖入富文本框以读取文件中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15333457/
我是 iOS 新手,我不知道该怎么做,我想实现类似个人资料编辑动画的 Tinder。 例如, 我可以将图像拖到其他 UIImageView 或 UICollectionView 中,并将 Collec
我在项目中使用gridster.net,但遇到了问题。 我试图让小部件仅在单击后按住鼠标一秒钟后才开始拖动。我正在使用下一个代码: $(".gridster .gs-w").on('mousedown
我想用 LibGDX 中的鼠标拖动一个Actor。我的代码: // overrides in the ClickListener @Override public bo
为什么当我将我的 gif 拖到单元格中时表格会变形?我该如何解决?当我将 gif 拖到单元格中时,我希望表格(和每个单元格)保持原来的大小。 这是我的情况的一个 jsfiddle: http://js
当设备转向横向时,一些控件离开 viewController,我无法将其拖到 viewController。 最佳答案 就像您在屏幕截图上看到的那样,您的约束无效,这可能是个问题。如果您使用 Stor
我在单击 JButton 时将 JPanel 添加到 JFrame。它将 JPanel 添加到框架中。该按钮将在点击事件中继续将 JPanel 添加到 JFrame。没有限制。单击按钮时,我也将 JP
我有一个 NSCollectionView 显示内部存储的图像(即不是文件)。集合显示正确。但是,当我开始拖动操作时,应用程序崩溃了。它在拖动离开 Collection View 之前崩溃。我正在返回
我正在尝试解决 iPhone 上拖放的基本问题。这是我的设置: 我有一个 UIScrollView,它有一个大的内容 subview (我可以滚动和缩放它) 内容 subview 有几个小块作为 su
我今天遇到了一个小问题,我想我可以试试堆栈溢出。我会简短而贴心(我删除了很多代码以明确这一点)。 我最近发现了 raphaeljs,我喜欢它。我制作了一些可拖动的圆圈,它像这样工作得很好: 工作脚本:
我是 iOS 开发的新手,想使用分组的 UITableView 和 UITabelCell 来创建一个简单的表单来布置表单的内容。我想在 XCode5 中以交互方式执行此操作。 我的问题是,在将 UI
您好,我是 iOS 编程的新手,想知道将 UIView 拖到 Storyboard 中并以编程方式创建它们之间有什么区别。我正在使用 iPad 进行开发。我有一个 UISplitView。在 Appd
A = 父 NSView;B = 子 NSView; B有一个小的NSTrackingArea;B是A的一个小 subview ; 如果在空白区域中移动、单击、拖动,A 会正确接收 mouseMove
我正在尝试实现自定义 QGraphicsScene,当我们按下左键时,它允许拖动一个项目,为此我使用 QDrag 并传递项目数据,然后覆盖 dropEvent 事件,我在其中获取元素和 dropEve
我是一名优秀的程序员,十分优秀!