MAX里DotNet 应用函数

这个博客介绍了如何在MAXScript中使用.NET交互,特别是针对ListView控件的操作,如初始化、添加图像列表、创建和添加ListView项、删除项、设置字体样式等。示例代码展示了如何使用.NET类来实现颜色转换、图像加载、添加列头等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


struct ListViewOps
(  
   m_dnColor = dotNetClass "System.Drawing.Color",
   function MXSColor_to_dotNetColor hColor =
   (
      m_dnColor.fromARGB hColor.r hColor.g hColor.b
   ),


   function dotNetColor_to_MXSColor dnColor =
   (
      local mxsCol = color (dnColor.r as integer) (dnColor.g as integer) (dnColor.b as integer)
      mxsCol
   ),


   function InitImageList lv stringFileArray pSize:0 =
   (
      --[brief] This method only adds icons and bitmaps, to an imagelist.
      --        An imagelist is a structure that manages images for a control.
      --[param] lv - The listview control. Must inherit from System.Windows.Forms.Control class.
      --[param] stringFileArray - A maxscript array containing filenames of the images to add.
      -- Must pass the string file names as a symbolic pathname:
      -- i.e. "$ui/icons/mybitmap.bmp"
      --[param] pSize - The size of the bitmap to add. For example 16 if the image is 16 x 16 pixels.
      --[return] A System.Windows.Forms.ImageList


      local hImgList  = dotNetObject "System.Windows.Forms.ImageList"
      local imgSize   = dotNetObject "System.Drawing.Size" 16 16
  
      if pSize == 0 then
      (
         hImgList.imagesize = imgSize
      )else if (pSize > 2)

             then
      (
                   imgSize   = dotNetObject "System.Drawing.Size" pSize pSize
                   hImgList.imagesize = imgSize
              )
  
              local bColor  = dotNetClass "System.Drawing.Color"
              if pTransparentColor != undefined and (classof pTransparentColor == color) then
              ( 
                    local col = pTransparentColor --temporary
                    hImgList.transparentColor = bColor.fromARGB col.r col.g col.b
              ) 
             else
             (
                    hImgList.transparentColor = bColor.fromARGB 125 125 125 
              )
  
             local img    = dotNetClass "System.Drawing.Image"
  

            --获取图标名
            function IsIconFile stringFileName =
            (
                   local type = GetFileNameType stringFileName
                   local result = false
                   if type == ".ico" do ( result = true )
                  result 
            )
  
           for file in stringFileArray do
          (
                  fName = (symbolicPaths.expandFileName file)
                  if (IsIconFile fName ) then --Add icons
                  (
                         local icon  = dotNetObject "System.Drawing.Icon" fName
                         hImgList.images.add icon
                   )
                   else --or Add bitmaps
          (


          local dnBitmap = dotNetObject "System.Drawing.Bitmap" fName
          hImgList.images.add dnBitmap
         )
  )
  lv.SmallImageList = hImgList
 ),

 

   --给LISTVIEW添加成员
   function AddLvItem lv                 \
                    pTextItems:#()        \
                    pChecked:  false      \
                    pHashKey:  ""         \
                    pTag:      undefined  \
                    pToolTip:  ""         \
                    pInsertAt: undefined  \
                    pImgIndex: 1          \
                    pIndent:   0 =
  (
        --[brief] This function Creates and Adds a ListViewItem to a ListView control.
        --[param] pTextItems - A maxscript array that contains the strings to put in each cell
        --                     of the listview cells which are called ListViewSubItems
        --[param] pChecked   - If true displays a checkbox to the far left of the listview item
        --[param] pHashKey   - A string used for a hash table index
        --[param] pTag      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值