- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-6-7 03:10:11
|
显示全部楼层
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcAs = Autodesk.AutoCAD.ApplicationServices;
namespace OsnapPalette
{
public partial class OsmodeControl : UserControl
{
private Dictionary<int, CheckBox> modes = new Dictionary<int, CheckBox>();
public OsmodeControl()
{
InitializeComponent();
modes.Add(1, this.chkEnd);
modes.Add(2, this.chkMid);
modes.Add(4, this.chkCen);
modes.Add(8, this.chkNod);
modes.Add(16, this.chkQua);
modes.Add(32, this.chkInt);
modes.Add(64, this.chkIns);
modes.Add(128, this.chkPer);
modes.Add(256, this.chkTan);
modes.Add(512, this.chkNea);
modes.Add(2048, this.chkPrj);
modes.Add(4096, this.chkExt);
modes.Add(8192, this.chkPar);
InitCheckBoxes();
AcAp.SystemVariableChanged +=
new AcAs.SystemVariableChangedEventHandler(AcAp_SysvarChanged);
}
void AcAp_SysvarChanged(object sender, AcAs.SystemVariableChangedEventArgs e)
{
if (e.Name == "OSMODE" || e.Name == "AUTOSNAP")
InitCheckBoxes();
}
private void InitCheckBoxes()
{
short osmode = (short)AcAp.GetSystemVariable("OSMODE");
foreach (KeyValuePair<int, CheckBox> pair in modes)
{
pair.Value.Checked = (osmode & pair.Key) == pair.Key;
}
this.chkF3.Checked = (osmode & 16384) == 0;
this.chkF11.Checked = (((short)AcAp.GetSystemVariable("AUTOSNAP")) & 16) == 16;
}
private void cmdAll_Click(object sender, EventArgs e)
{
foreach (KeyValuePair<int,CheckBox> pair in modes)
{
pair.Value.Checked = true;
}
}
private void cmdNone_Click(object sender, EventArgs e)
{
foreach (KeyValuePair<int, CheckBox> pair in modes)
{
pair.Value.Checked = false;
}
}
private void OsmodeControl_MouseLeave(object sender, EventArgs e)
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
int autosnap = (short)AcAp.GetSystemVariable("AUTOSNAP");
autosnap = chkF11.Checked ? autosnap | 16 : autosnap - (autosnap & 16);
int osmode = 0;
foreach (KeyValuePair<int,CheckBox> pair in modes)
{
if (pair.Value.Checked)
osmode += pair.Key;
}
if (!chkF3.Checked)
osmode += 16384;
using (DocumentLock docLock = doc.LockDocument())
{
AcAp.SetSystemVariable("OSMODE", osmode);
AcAp.SetSystemVariable("AUTOSNAP", autosnap);
}
}
}
}
|
|