cad.net 设置边栏面板最小宽度

有很多人问过这个问题,所以特意在博客贴出..
取自Acad官方的博客 https://adndevblog.typepad.com/autocad/2012/06/paletteset-minimum-docked-width.html

原文:

我有一个PaletteSet,它包含一个工具栏,其宽度设置为40像素。这在AutoCAD 2008中很好,但在AutoCAD 2011中,当PaletteSet停靠时,我不能使宽度小于150像素。
在AutoCAD 2009中,包括PaletteSets在内的可停靠窗口的最小停靠宽度已从40像素更改为150像素,在AutoCAD 2011中也是如此。
然而,在AutoCAD 2012中,引入了一个新的ARX函数,它可以覆盖此值:

代码

public class CommandsTestMyPalette
{
    /*
#if AC2009
    [DllImport("adui18.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?AdUiSetDockBarMinWidth@@YA_NH@Z")]
    public static extern bool AdUiSetDockBarMinWidth(int width);
#elif AC2014
    [DllImport("adui19.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?AdUiSetDockBarMinWidth@@YA_NH@Z")]
    public static extern bool AdUiSetDockBarMinWidth(int width);
#endif
    */

    //委托,调用函数指针用
    delegate bool DelegateAdUiSetDockBarMinWidth(int width);
    /// <summary>
    /// 设置边栏面板最小宽度
    /// </summary>
    public static bool AdUiSetDockBarMinWidth(int width)
    {
        var dllName = AcDllHelper.AcVerDll("adui");
        var hModule = GetModuleHandle(dllName);
        if (hModule == IntPtr.Zero)
            throw new System.Exception(nameof(AdUiSetDockBarMinWidth) + "找不到模块:" + dllName);

        string funcName = "?AdUiSetDockBarMinWidth@@YA_NH@Z";

        //函数指针
        var funcAdress = GetProcAddress(hModule, funcName);
        if (funcAdress == IntPtr.Zero)
            throw new System.Exception(nameof(AdUiSetDockBarMinWidth) + "没有找到这个函数的入口点:" + funcAdress);

        //利用委托调用函数指针,从而实现对方法的调用
        var delega = Marshal.GetDelegateForFunctionPointer(funcAdress,
                             typeof(DelegateAdUiSetDockBarMinWidth)) as DelegateAdUiSetDockBarMinWidth;
        return delega(width);
    }



    static PaletteSet ps;

    /// <summary>
    /// 设置边栏面板最小宽度
    /// </summary>
    /// https://adndevblog.typepad.com/autocad/2012/06/paletteset-minimum-docked-width.html
    [CommandMethod("CmdTest_MyPalette")]
    public void CmdTest_MyPalette()
    {
        AdUiSetDockBarMinWidth(40);
        if (ps == null)
        {
            ps = new PaletteSet("My Palette 1")
            {
                MinimumSize = new System.Drawing.Size(30, 300),
                Dock        = DockSides.Top
            };
            //var myCtrl = new MyControl1();
            //myCtrl.Dock = System.Windows.Forms.DockStyle.Fill;
            //ps.Add("test", myCtrl);
        }
        if (ps != null)
            ps.Visible = true;
    }
}

相关阅读

动态修改"18"这个数字已达动态加载的目的,见动态调用dll
(完)

posted @ 2021-02-04 16:04  惊惊  阅读(853)  评论(1编辑  收藏  举报