<tfoot id='iYRwO'></tfoot>
    • <bdo id='iYRwO'></bdo><ul id='iYRwO'></ul>

    <legend id='iYRwO'><style id='iYRwO'><dir id='iYRwO'><q id='iYRwO'></q></dir></style></legend>

    <i id='iYRwO'><tr id='iYRwO'><dt id='iYRwO'><q id='iYRwO'><span id='iYRwO'><b id='iYRwO'><form id='iYRwO'><ins id='iYRwO'></ins><ul id='iYRwO'></ul><sub id='iYRwO'></sub></form><legend id='iYRwO'></legend><bdo id='iYRwO'><pre id='iYRwO'><center id='iYRwO'></center></pre></bdo></b><th id='iYRwO'></th></span></q></dt></tr></i><div id='iYRwO'><tfoot id='iYRwO'></tfoot><dl id='iYRwO'><fieldset id='iYRwO'></fieldset></dl></div>

      1. <small id='iYRwO'></small><noframes id='iYRwO'>

        如何处理 GetDataPresent 让它接受所有派生类型

        时间:2023-08-25

      2. <tfoot id='0AZK0'></tfoot>

          <tbody id='0AZK0'></tbody>
        • <bdo id='0AZK0'></bdo><ul id='0AZK0'></ul>
          <legend id='0AZK0'><style id='0AZK0'><dir id='0AZK0'><q id='0AZK0'></q></dir></style></legend>
        • <small id='0AZK0'></small><noframes id='0AZK0'>

          <i id='0AZK0'><tr id='0AZK0'><dt id='0AZK0'><q id='0AZK0'><span id='0AZK0'><b id='0AZK0'><form id='0AZK0'><ins id='0AZK0'></ins><ul id='0AZK0'></ul><sub id='0AZK0'></sub></form><legend id='0AZK0'></legend><bdo id='0AZK0'><pre id='0AZK0'><center id='0AZK0'></center></pre></bdo></b><th id='0AZK0'></th></span></q></dt></tr></i><div id='0AZK0'><tfoot id='0AZK0'></tfoot><dl id='0AZK0'><fieldset id='0AZK0'></fieldset></dl></div>
                1. 本文介绍了如何处理 GetDataPresent 让它接受所有派生类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 drgevent.Data.GetDataPresent 来确定是否拖动的组件是否可以接受.

                  I'm using drgevent.Data.GetDataPresent to determine whether the dragged component is acceptable or not.

                  我有一个问题,我想接受一个特定的类型,比如 SomeType 以及从它派生的所有类型.似乎 GetDataPresent 不支持这样的要求.

                  I've got a problem which is that I want to accept a specific type say SomeType and all the types that derived from it. Seems GetDataPresent doesn't support such requirement.

                  有什么想法吗?

                  推荐答案

                  只是不要使用 GetDataPresent(),它是样板文件,但您可以按照自己的方式进行操作.实际检索对象并检查您是否对它的类型感到满意:

                  Just don't use GetDataPresent(), it is boilerplate but you're free to do it your way. Actually retrieve the object and check if you're happy with its type:

                      protected override void OnDragEnter(DragEventArgs drgevent) {
                          var obj = drgevent.Data.GetData(drgevent.Data.GetFormats()[0]);
                          if (typeof(Base).IsAssignableFrom(obj.GetType())) {
                              drgevent.Effect = DragDropEffects.Copy;
                          }
                      }
                  

                  Base 是基类的名称.虽然 GetFormats() 的使用看起来很奇怪,但这种方法可以保证有效,因为拖动 .NET 对象只会产生 one 格式,即对象类型的显示名称.这也是 GetDataPresent 不能用于派生对象的原因.

                  Where Base is the name of the base class. While the use of GetFormats() looks odd, this approach is guaranteed to work because dragging a .NET object only ever produces one format, the display name of the type of the object. Which is also the reason that GetDataPresent can't work for derived objects.

                  这篇关于如何处理 GetDataPresent 让它接受所有派生类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在我的 .NET Windows 窗体上实现从 Chrome 拖放 下一篇:在 C# 托盘中拖放 NotifyIcon

                  相关文章

                  最新文章

                  1. <small id='F6SKe'></small><noframes id='F6SKe'>

                  2. <tfoot id='F6SKe'></tfoot>
                      <bdo id='F6SKe'></bdo><ul id='F6SKe'></ul>
                  3. <legend id='F6SKe'><style id='F6SKe'><dir id='F6SKe'><q id='F6SKe'></q></dir></style></legend>
                  4. <i id='F6SKe'><tr id='F6SKe'><dt id='F6SKe'><q id='F6SKe'><span id='F6SKe'><b id='F6SKe'><form id='F6SKe'><ins id='F6SKe'></ins><ul id='F6SKe'></ul><sub id='F6SKe'></sub></form><legend id='F6SKe'></legend><bdo id='F6SKe'><pre id='F6SKe'><center id='F6SKe'></center></pre></bdo></b><th id='F6SKe'></th></span></q></dt></tr></i><div id='F6SKe'><tfoot id='F6SKe'></tfoot><dl id='F6SKe'><fieldset id='F6SKe'></fieldset></dl></div>