请教一个VBA关于颜色的问题
<p>我想编一个东西,需要在我的用户界面上选择颜色,但是我不想用RGB输入形式,况且我的CommonDialog不知道怎么的未授权,不能用。我想调用CAD自身的那个颜色选择框,我发命令Color到CAD虽然能出来色彩选择对话框,但是我不知道怎么获取返回值,选的颜色变成改变当前图层颜色。</p><p>所以想问高人:怎么通过VBA 调用CAD的色彩选择对话框,选择颜色确定后要能够返回选择值!</p><p>另外,还有一个问题,我多半希望返回的是CAD的颜色索引值,好像那个ACI的颜色是CAD自己弄的,返回了索引值后,我怎么把这个颜色变成RGB值或者VB系统认识的颜色,因为我想把用来打开选择颜色的按钮在选完色之后变成刚才选择的颜色,这样才知道自己选了那个颜色!!</p> <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 " & lColor<br/>End Sub</p> <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> <p>感谢版主老大!!!!!</p><p>东西已经受到,正在学习中.....</p>
页:
[1]