DragDrop事件之后有事件吗? [英] Is there an event following the DragDrop Event?

查看:50
本文介绍了DragDrop事件之后有事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,很遗憾,我是一个菜鸟,而且我找不到在RichTextBox中放置文件后发生的事件.

当您将文件拖放到Rtb中时,图标的图像将复制到控件上(如果您下载了此控件(源自Richtextbox),则该控件有几种方法可以操纵RTF,例如AppendRtf(_rtf)).

现在,我想向您介绍一个可行的方案.
1)我将一个文件拖到Rtb中,检查是否是一个文件拖到控件上.如果为true,则渲染所有效果.

Hello, sadly I''m a noob, and I can''t manage to find an event that occurs after I drop a file in a RichTextBox.

When you drop a file into a Rtb the icon''s image is copied on to the control (if you downloaded this control which derives from richtextbox, this control has a few methods in which manipulate RTF such as AppendRtf(_rtf)).

Now I want to present you with a scenario wich works.
1) I drag a file into the Rtb, I check if it''s a file being dragged onto the control. If true, I render all effects.

void txt_send_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
    txt_send.Clear();
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
    {
        e.Effect = DragDropEffects.All;
    } 
}


2)我删除了文件,在这里,为此,我要做的就是更新一个布尔值,该值指示文件已被删除.


2) I drop the file, here for this secnario all I do is update a boolean value that indicates the file as been dropped.

void txt_send_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
    File_droped = true;           
}


此事件(2)之后,将图像插入Rtb.

3)最后,为了测试我上面提到的问题,我调用MouseUp事件,在该事件中复制该图像的RTF(富文本格式).

因此,现在我单击该控件,然后调度以下事件.

我只想澄清一下,我知道MouseUpDragDrop事件之后不会发生,我只添加了它来测试我想执行的操作以确保它可以正常工作.


After this event (2) an image is inserted into the Rtb.

3) Finally, in order to test the issue I presented above, I call the MouseUp event , where I copy that image''s RTF(Rich Text Format).

So now I click the control , and the following event is dispatched.

I just want to clarify, I''m aware that MouseUp does not occur after the DragDrop event, I only added it to test the operation I want to perform to ensure it works.

void txt_send_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (File_droped)
    {
        txt_main.AppendRtf(txt_send.Rtf); 
    } 
}


现在,文件的图标(图像)已复制到另一个RichTextBox(此工作).

现在,我要查找的是在DragDrop事件之后发生的实际事件,因为我希望在DragDrop结束后执行此事件.
如果我尝试从事件内部执行此操作,则该图像将不起作用,因为该图像仅在事件之后出现.


Now the file''s icon (Image) is copied to anouther RichTextBox (THIS WORKS).

Now again what I''m looking for is an actual event that occurs after the DragDrop event, becuase I want this to perform after DragDrop has ended.
If I attempt to do this from inside the event, it won''t work because the image only appears after the event .

txt_main.AppendRtf(txt_send.Rtf);

推荐答案

也许某些其他事件可以与某种标志一起使用表示这次需要做一些事情(否则可能会做您不想要的事情).我还没有测试过,但可以想象

Maybe some other event could be used with somesort of flag to indicate that there needs to be something done this time (otherwise it might do things you don''t want). I haven''t tested it but could imagine

Private Sub BindingContext_Changed(sender As Object, e As EventArgs)
   if(flag_append_rtf_after_drop) {
       txt_main.AppendRtf(txt_send.Rtf);
   }
End Sub


http://msdn.microsoft.com/en-us/library/system.windows.forms.control.bindingcontextchanged.aspx [ ^ ]

由于我实际上没有对此进行测试,所以也可能是另一件事,但是您可以看看并尝试其中的一些方法:
http://msdn.microsoft.com/en-us/library/system. windows.forms.richtextbox_events.aspx [ ^ ]

另外,我以为有一个DragEnd事件,但只能在某些控件中找到它.也许事件仍在引发,但根本没有实现或暴露为事件.也许可以通过覆盖RaiseDragEventOnNotifyMessage来实现,但还没有对其进行测试.但也可能是一个想法,

好吧,希望这会给您一些帮助.另一种方法可以简单地通过使用在拖放后启用并在其中执行的计时器来实现.行之间的拖放方法中的Application.DoEvents();可能也有帮助(在这种情况下甚至可以认为是有效的).但是除此之外,这些是处理它的不太优雅的方法,但也值得探索.

祝你好运!


http://msdn.microsoft.com/en-us/library/system.windows.forms.control.bindingcontextchanged.aspx[^]

Could also be another event since I didn''t actually test this, but you could have a look and try some of them:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox_events.aspx[^]

Also, I thought that there was a DragEnd event but could only find it for some controls. Maybe the event is still raised but simply not implemented or exposed as an event. Maybe it could be implemented by overriding the RaiseDragEvent or OnNotifyMessage but also haven''t tested it. But could also be an idea to have a look at,

Well, hopefully this gives you some help. Another way could be simply by using a timer that you enable after the dragdrop and do it there. Maybe an Application.DoEvents(); in the dragdrop method between the lines could maybe also help (maybe even considered valid in this case). But aside from that, these are the less elegant ways to handle it but could also be worth exploring.

Good luck!


我最终使用了text_changed事件,并带有一个标志,表明该文件已被删除..

私有void txt_send_TextChanged(对象发送者,EventArgs e)
{
如果(file_droped_flag)
{
current_content.userTextBox.AppendText("\ n \ n");

current_content.userTextBox.AppendRtf(txt_send.Rtf);
current_content.userTextBox.AppendText("\ n");
current_content.userTextBox.AppendTextAsRtf(发送文件请求",新字体(this.Font,FontStyle.Underline | FontStyle.Bold),RtfColor.Blue,RtfColor.Yellow);
current_content.userTextBox.AppendText("\ n \ n");
file_droped_flag = false;
txt_send.Clear();
}
}

问题是此事件频繁发生,是否还有一个标志来检查该事件是否被删除,是否仅在特定条件下引发该事件?
i ended up using the text_changed event with a flag that indiactes that a file was droped ..

private void txt_send_TextChanged(object sender, EventArgs e)
{
if (file_droped_flag)
{
current_content.userTextBox.AppendText("\n\n");

current_content.userTextBox.AppendRtf(txt_send.Rtf);
current_content.userTextBox.AppendText("\n");
current_content.userTextBox.AppendTextAsRtf("Sending file request",new Font(this.Font, FontStyle.Underline | FontStyle.Bold), RtfColor.Blue, RtfColor.Yellow);
current_content.userTextBox.AppendText("\n\n");
file_droped_flag = false;
txt_send.Clear();
}
}

the problem is that this event happends frequntly , is there a was other then a flag to check if the event was relavent , to raise an event only on certine conditions ?


这篇关于DragDrop事件之后有事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆