图片不让左键和右键点击
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-12 17:22:17 |
👁️ 阅读: 7
要让图片控件不响应鼠标点击,可以使用以下方法:
```lua
-- 创建父节点
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建图片控件
local img = GUI:Image_Create(parent, "test_img", 100, 100, "res/public/1900000610.png")
-- 方法1:禁用鼠标触摸
GUI:setMouseEnabled(img, false)
-- 方法2:设置触摸吞噬(阻止事件传递)
GUI:setSwallowTouches(img, true)
-- 方法3:设置鼠标右键触摸吞噬
GUI:setMouseRSwallowTouches(img)
```
**参数说明:**
- `setMouseEnabled(widget, value)`:设置控件是否可以鼠标触摸
- `widget`:控件对象
- `value`:false表示禁用鼠标触摸
- `setSwallowTouches(widget, value)`:设置控件是否触摸吞噬
- `widget`:控件对象
- `value`:true表示吞噬触摸事件
- `setMouseRSwallowTouches(widget)`:设置控件吞噬鼠标按键事件
**推荐组合使用:**
```lua
-- 最彻底的禁用方式
GUI:setMouseEnabled(img, false) -- 禁用鼠标触摸
GUI:setSwallowTouches(img, true) -- 吞噬触摸事件
```
这样图片就不会响应左键和右键点击了。如果之后需要恢复点击功能,只需将`setMouseEnabled`的参数改为`true`即可。
← 返回问答库