enocheasty 发表于 2007-10-14 00:40:00

请教一个VBA关于颜色的问题

<p>我想编一个东西,需要在我的用户界面上选择颜色,但是我不想用RGB输入形式,况且我的CommonDialog不知道怎么的未授权,不能用。我想调用CAD自身的那个颜色选择框,我发命令Color到CAD虽然能出来色彩选择对话框,但是我不知道怎么获取返回值,选的颜色变成改变当前图层颜色。</p><p>所以想问高人:怎么通过VBA 调用CAD的色彩选择对话框,选择颜色确定后要能够返回选择值!</p><p>另外,还有一个问题,我多半希望返回的是CAD的颜色索引值,好像那个ACI的颜色是CAD自己弄的,返回了索引值后,我怎么把这个颜色变成RGB值或者VB系统认识的颜色,因为我想把用来打开选择颜色的按钮在选完色之后变成刚才选择的颜色,这样才知道自己选了那个颜色!!</p>

alin 发表于 2007-10-14 22:33:00

<p>'By Kevin Terry</p><p>Option Explicit</p><p>Private Declare Function acedSetColorDialog Lib _<br/>"acad.exe" (color As Long, ByVal bAllowMetaColor _<br/>As Boolean, ByVal nCurLayerColor As Long) As Boolean</p><p>'Color choice using autocad color selection dialog box<br/>'<br/>Public Function ChooseColor(ByVal lngInitClr As Long, ByVal blnMetaColor As Boolean, _<br/>ByVal lngCurClr As Long) As Long</p><p>ChooseColor = -1</p><p>On Error Resume Next</p><p>If acedSetColorDialog(lngInitClr, blnMetaColor, lngCurClr) Then<br/>ChooseColor = lngInitClr<br/>End If</p><p>On Error GoTo 0</p><p>End Function</p><p><br/>Public Sub test()<br/>Dim lColor As Long<br/>lColor = ChooseColor(lColor, True, lColor)<br/>MsgBox "You have selected color " &amp; lColor<br/>End Sub</p>

alin 发表于 2007-10-14 22:38:00

<p>Public Function ACI2RGB(ByVal intACI As Integer) As Long<br/>Dim col As New AcadAcCmColor<br/>col.ColorIndex = intACI<br/>ACI2RGB = RGB(col.Red, col.Green, col.Blue)<br/>End Function</p><p>Public Function RGB2ACI(ByVal lngRGB As Long) As Integer<br/>Dim col As New AcadAcCmColor<br/>Dim r As Byte, g As Byte, b As Byte<br/>'split color into rgb components<br/>r = (lngRGB Mod 256 ^ 2) Mod 256<br/>g = (lngRGB Mod 256 ^ 2) \ 256<br/>b = lngRGB \ 256 ^ 2<br/>col.SetRGB r, g, b<br/>RGB2ACI = col.ColorIndex<br/>End Function</p>

enocheasty 发表于 2007-10-15 19:38:00

<p>感谢版主老大!!!!!</p><p>东西已经受到,正在学习中.....</p>

flydyt 发表于 2008-3-3 09:45:00

页: [1]
查看完整版本: 请教一个VBA关于颜色的问题