• 使用RibbonPanelBreak创建Slide-Out Panel遇到的问题


    Win7 简体中文版

    Autocad civil 3d 2018简体中文版

    Visual studio 2015社区版

    C#语言

    如下图,

    使用RibbonPanelBreak分隔,

    创建Slide-Out Panel(我不知道这个描述是否准确)。

     
     

    按钮能够正常创建,

    命令也能正常发送。

    上图中的按钮“图形清理1”工作一切正常。

    问题出在点击Slide-Out Panel部分的按钮时,

    例如上图中的“图形清理2”(调用的map 3d的命令mapclean),

    对话框弹出后,

    如果此时autocad失去焦点,

    比如切换到其他程序或者这桌面点击鼠标等,

    弹出的对话框会“消失”,

    从而造成AutoCAD被卡死。

    我注意到AutoCAD自带的Ribbon,

    其Slide-Out部分在鼠标点击后,

    会慢慢消失,

    而我创建的ribbon中的Slide-Out部分在鼠标点击并弹出对话框后,

    它一直在那里(如下图),

    直到对话框关闭,

    最初发现此问题是我自己设计的对话框工作不正常,

    以为自己的对话框语有问题,

    折腾了很长时间,

    后来对其他对话框进行测试,

    发现位于Slide-Out部分的按钮弹出的对话框有问题,

    才意识到问题不是出在对话框本身,

    而是我创建的ribbon有问题。

    我不清楚应该怎样修改我的代码,

    麻烦指点一下。

    谢谢!

    下面是我的代码。

    // (C) Copyright 2019 by  
    //
    using System;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.EditorInput;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Collections;
    using System.Runtime.CompilerServices;
    using Autodesk.Civil.DatabaseServices;
    using Autodesk.Windows;
    
    // This line is not mandatory, but improves loading performances
    //[assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in1.MyCommands))]
    
    namespace AutoCAD_CSharp_plug_in1
    {
    
        // This class is instantiated by AutoCAD for each document when
        // a command is called by the user the first time in the context
        // of a given document. In other words, non static data in this class
        // is implicitly per-document!
        public class MyCommands
        {
            // The CommandMethod attribute can be applied to any public  member 
            // function of any public class.
            // The function should take no arguments and return nothing.
            // If the method is an intance member then the enclosing class is 
            // intantiated for each document. If the member is a static member then
            // the enclosing class is NOT intantiated.
            //
            // NOTE: CommandMethod has overloads where you can provide helpid and
            // context menu.
    
            
    
            /// <summary>
            /// 2020年9月22日 UserName:Line
            /// 
            /// </summary>
            [CommandMethod("RibbonTest", "RibbonTest", "RibbonTest", CommandFlags.Modal, null, "RibbonTest", "IDH_RibbonTest")]
            public void C_RibbonTest()
            {
                RibbonControl ribbon = ComponentManager.Ribbon;
                if (ribbon != null)
                {
                    RibbonTab rtab = ribbon.FindTab("测试");
                    if (rtab != null)
                    {
                        ribbon.Tabs.Remove(rtab);
                    }
                    rtab = new RibbonTab();
                    rtab.Title = "测试";
                    rtab.Id = "测试ing";
                    //Add the Tab
                    ribbon.Tabs.Add(rtab);
                    addContent(rtab);
    
                }
            }
    
            private void addContent(RibbonTab rtab)
            {
                rtab.Panels.Add(AddOnePanel());
            }
    
            private RibbonPanel AddOnePanel()
            {
                RibbonButton rb;
                RibbonPanelSource rps = new RibbonPanelSource();
                rps.Title = "测试1";
                RibbonPanel rp = new RibbonPanel();
                rp.Source = rps;
                
    
    
                rb = new RibbonButton();
                rb.Name = "图形清理1";
                rb.ShowText = true;
                rb.Text = "图形清理1";
                rb.CommandHandler= new RibbonbtnCmdHandle();
                rb.CommandParameter = "_.MapClean ";
    
                rps.Items.Add(rb);
                rps.Items.Add(new RibbonPanelBreak());
    
                RibbonRowPanel rrp = new RibbonRowPanel();
                rps.Items.Add(rrp);
    
                rb = new RibbonButton();
                rb.Name = "图形清理2";
                rb.ShowText = true;
                rb.Text = "图形清理2";
                rb.CommandHandler = new RibbonbtnCmdHandle();
                rb.CommandParameter = "_.MapClean ";
    
                rrp.Items.Add(rb);
    
                return rp;
            }
            class RibbonbtnCmdHandle : System.Windows.Input.ICommand
            {
                public event EventHandler CanExecuteChanged;
                public bool CanExecute(object parameter)
                {
                    return true;
                }
                public void Execute(object parameter)
                {
                    if (parameter is RibbonButton)
                    {
                        RibbonButton rb = parameter as RibbonButton;
                        Application.DocumentManager.MdiActiveDocument.SendStringToExecute(
                            (string)rb.CommandParameter, true, false, false);
                    }
                }
            }
        }
    }
    

    经过网友edata的测试,

    我被搞的更晕了,

    感觉问题远比想象的复杂。

    增加两个autocad的命令进行测试,

    style和insert,

    发现style命令没有问题,

    对话框弹出后,

    滑出面板会消失,

    对话框能正常工作,

    但insert命令仍存在问题,

    对话框弹出后,

    滑出面板不消失,

    autocad失去焦点后对话框消失,

    autocad卡死。

    下面是我增加button的代码:

     rrp.Items.Add(new RibbonRowBreak());
     rb = new RibbonButton();
     rb.Name = "样式";
     rb.ShowText = true;
     rb.Text = "样式";
     rb.CommandHandler = new RibbonbtnCmdHandle();
     rb.CommandParameter ="_.style ";
    
     rrp.Items.Add(rb);
    
     rrp.Items.Add(new RibbonRowBreak());
    
     rb = new RibbonButton();
     rb.Name = "插入";
     rb.ShowText = true;
     rb.Text = "插入";
     rb.CommandHandler = new RibbonbtnCmdHandle();
     rb.CommandParameter ="_.insert ";
    
     rrp.Items.Add(rb);
    

    补充:

    如果把滑出面板钉住,

    对话框就不会消失。

    网友edata帮我解决了问题,

    切换了一下焦点,

    问题解决!

    在此向edata表示感谢!

    5 条消息(共 6 条)
     
     
     

    You probably already know: for recent versions of AutoCAD (Acad2014, or 2015 and later), You can simply call

    Application.MainWindow.Focus()

    instead of Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView() (I guess Autodesk just added this functionality from Internal namespace to Application class).

    原贴地址在此

  • 相关阅读:
    NYOJ 32(组合数)
    NYOJ 289(01背包)
    批量修改文件(图片)名称
    解决IIS7虚拟目录出现HTTP 错误 500.19(由于权限不足而无法读取配置文件)的问题
    MPP(最下正周期)
    wcf学习网站
    winform中用户输入查询与拼音首字母的结合,提高用户的操作体验 (转)
    通过SvcUtil.exe生成客户端代码和配置(转)
    WinMail 搭建邮件服务器。
    quick easy ftp server软件在机子上架设了个服务器
  • 原文地址:https://www.cnblogs.com/myzw/p/13744497.html
Copyright © 2020-2023  润新知