오토캐드(AutoCAD) 팔레트(Palette) 배경색상 설정
AutoCAD의 특성 팔레트와 같은 배경색의 팔레트를 C#으로 구현하려면, AutoCAD의 특성 팔레트와 동일한 색상을 가져와서 PaletteSet에 적용해야 합니다. AutoCAD는 내부적으로 특정 색상 테마를 사용하기 때문에, 특성 팔레트의 배경색을 직접 가져오는 API는 제공되지 않지만, AutoCAD의 다크 및 라이트 테마에 따라 팔레트 배경색을 설정할 수 있습니다.
다음은 AutoCAD 테마에 맞게 팔레트 배경 색상을 설정하는 예제 코드입니다.
using System;
using System.Drawing;
using Systehttp://m.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
[assembly: CommandClass(typeof(AutoCADPaletteExample.PaletteCommands))]
namespace AutoCADPaletteExample
{
public class PaletteCommands
{
private PaletteSet _paletteSet;
[CommandMethod("ShowPaletteWithTheme")]
public void ShowPaletteWithTheme()
{
if (_paletteSet == null)
{
// PaletteSet 생성
_paletteSet = new PaletteSet("My Themed Palette")
{
Style = PaletteSetStyles.ShowPropertiesMenu |
PaletteSetStyles.ShowCloseButton
};
// 사용자 컨트롤 생성
var userControl = new UserControl();
// AutoCAD 테마에 맞는 배경색 설정
Color backgroundColor = GetAutoCADThemeBackgroundColor();
userControl.BackColor = backgroundColor;
// Label 추가
var label = new Label
{
Text = "AutoCAD 테마와 동일한 배경색을 가진 팔레트입니다.",
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter,
BackColor = backgroundColor
};
userControl.Controls.Add(label);
// 팔레트에 사용자 컨트롤 추가
_paletteSet.Add("My Themed Palette Page", userControl);
}
// 팔레트 표시
_paletteSet.Visible = true;
}
private Color GetAutoCADThemeBackgroundColor()
{
// AutoCAD의 현재 테마를 확인하여 색상을 설정
bool isDarkTheme = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("COLORTHEME").ToString() == "1";
return isDarkTheme ? Color.FromArgb(51, 51, 51) : Color.FromArgb(238, 238, 238); // 다크 테마: 어두운 회색, 라이트 테마: 밝은 회색
}
}
}
1. AutoCAD 테마 확인: COLORTHEME 시스템 변수를 사용해 현재 AutoCAD의 테마가 다크인지 라이트인지 확인합니다. 다크 테마일 경우 값이 1이고, 라이트 테마일 경우 0입니다.
2. 테마에 맞는 색상 설정: GetAutoCADThemeBackgroundColor 메서드를 통해 다크 테마일 경우 다크 회색 (#333333), 라이트 테마일 경우 밝은 회색 (#EEEEEE)으로 배경 색상을 설정합니다.
3. 사용자 컨트롤에 색상 적용: UserControl의 BackColor에 테마에 맞는 배경색을 적용하여 특성 팔레트와 비슷한 느낌의 팔레트를 생성합니다.
위 코드를 사용하면 AutoCAD의 특성 팔레트와 유사한 배경색을 가진 커스텀 팔레트를 만들 수 있습니다.