AutoCAD 通过COM调用Preference设置背景颜色

简介:


AutoCAD中访问系统设定Preference,需要调用COM API,添加 Autodesk.AutoCAD.Interop的引用:

 

直接上代码: 

 

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;

using System.Drawing;
 

 

        [CommandMethod("GetBkClr")]

        public void GetBkGndColor()

        {

            // Access the Preferences object

            AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

    

            uint clr = acPrefComObj.Display.GraphicsWinLayoutBackgrndColor ;

            ed.WriteMessage(UIntToColor(clr).ToString());

        }

 

        [CommandMethod("SetBKClr"CommandFlags.Session)]

        public void SetBkGroundColor()

        {

            // Access the Preferences object

            AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

 

            // Use the CursorSize property to set the size of the crosshairs

            acPrefComObj.Display.CursorSize = 100;

 

            System.Drawing.Color bkClr = Color.FromArgb(0, 255, 255, 255);//white, do not use known color, use Argb instead.

 

            //acPrefComObj.Display.GraphicsWinLayoutBackgrndColor = ColorToUInt(bkClr);

            acPrefComObj.Display.GraphicsWinModelBackgrndColor = ColorToUInt(bkClr);

 

        }

 

        private uint ColorToUInt(Color color)

        {

            return (uint)((color.A << 24) | (color.R << 16) |

                          (color.G << 8) | (color.B << 0));

        }

 

        private System.Drawing.Color UIntToColor(uint color)

        {

            byte a = (byte)(color >> 24);

            byte r = (byte)(color >> 16);

            byte g = (byte)(color >> 8);

            byte b = (byte)(color >> 0);

            return Color.FromArgb(a, r, g, b);

        }

 

 

其中,转换函数来自 http://www.daniweb.com/software-development/csharp/code/217202 

 

作者: 峻祁连
邮箱:junqilian@163.com 
出处: http://junqilian.cnblogs.com 
转载请保留此信息。



本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/archive/2012/02/02/2335861.html ,如需转载请自行联系原作者
目录
打赏
0
0
0
0
23
分享
相关文章
Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。
【6月更文挑战第26天】Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。要更改主题,首先在该文件中创建新主题,如`MyAppTheme`,覆盖所需属性。然后,在`AndroidManifest.xml`中应用主题至应用或特定Activity。运行时切换主题可通过重新设置并重启Activity实现,或使用`setTheme`和`recreate()`方法。这允许开发者定制界面并与品牌指南匹配,或提供多主题选项。
134 6
Android UI中的Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等。要更改主题
【6月更文挑战第25天】Android UI中的Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等。要更改主题,首先在`styles.xml`中定义新主题,如`MyAppTheme`,然后在`AndroidManifest.xml`中设置`android:theme`。可应用于全局或特定Activity。运行时切换主题需重置Activity,如通过`setTheme()`和`recreate()`方法。这允许开发者定制界面以匹配品牌或用户偏好。
91 2
Android | 通过WindowInsetsController设置系统栏颜色、Behavior、显示隐藏等
两种方式可以引入`WindowInsetsController`,一种直接通过`API`的`val controller = window.decorView.windowInsetsController`获取,注意该方法在`API30`及以上才有
1138 0
iOS开发 - 设置tabbar上各选项颜色
iOS开发 - 设置tabbar上各选项颜色
245 0
MFC应用程序——标签控件_IP控件_时间控件_List Control控件_Tree Control控件_命令按钮_列表框_组合框_图片_滚动控件(上)
MFC应用程序——标签控件_IP控件_时间控件_List Control控件_Tree Control控件_命令按钮_列表框_组合框_图片_滚动控件
223 0
MFC应用程序——标签控件_IP控件_时间控件_List Control控件_Tree Control控件_命令按钮_列表框_组合框_图片_滚动控件(上)
MFC应用程序——标签控件_IP控件_时间控件_List Control控件_Tree Control控件_命令按钮_列表框_组合框_图片_滚动控件(下)
MFC应用程序——标签控件_IP控件_时间控件_List Control控件_Tree Control控件_命令按钮_列表框_组合框_图片_滚动控件
188 0
[uwp]自定义Behavior之随意拖动
原文:[uwp]自定义Behavior之随意拖动   由于最近有需求,所以自定义了一个随意拖动元素的Behavior.   当然在使用这个自定义的Behavior时,有个小假设:拖动元素必须是Canvas容器的子元素。
845 0
tablayout支持改变选中文字大小,支持左右滑动,支持viewpager,支持三角可移动指示器
TabLayout [简书地址] (https://www.jianshu.com/p/2c3f868266e8) 基于大神的FlycoTabLayout 传送地址和基本用法 用法和属性和这个库一样 效果图如下 Gif_20180828_142709.
2507 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等