cad.net PaletteSet侧边栏面板
侧边栏宽度
有很多人问过这个问题,所以特意在博客贴出.
大家设置界面的时候可以弄一个贴边控件,然后利用鼠标拖拽动态拉伸,动态设置这个值.
原文:
取自Acad官方的博客
我有一个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
侧边栏禁止停靠
将PaletteSet的Dock和DockEnabled属性,设置为DockSides.None
acad2014还需调用PaletteSet.RecalculateDockSiteLayout()方法.
摘录:
https://www.cnblogs.com/d1742647821/p/18230431
侧边栏没有停靠是为什么
paletteSet.DockEnabled = DockSides.Left;
paletteSet.Dock = DockSides.Left;
这样设置paletteSet停靠在左边,并没有停靠是什么原因?
答 : 需要 Visible = true;
if (PSet is null)
{
PSet = new PaletteSet(SystemName);
PSet.Visible = true;
ElementHost host = new();
host.Size = new System.Drawing.Size(900, 4000);
host.Dock = System.Windows.Forms.DockStyle.Fill;
host.Child = UIView;
PSet.Add(SystemName, host);
PSet.Dock = DockSides.Left;
PSet.KeepFocus = true;
}
if (!PSet.Visible)
{
PSet.Visible = true;
}
(完)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)