根据edit框中鼠标位置加减数值
By
admin
at 2018-09-30 • 0人收藏 • 1555人看过
var editAutoInc = function(ctrl){
var n,length = tonumber(ctrl.text);
if( length == #ctrl.text ){
var mousePos = ctrl.getsel();
var tab = string.split(ctrl.text)
var s = null;
for(k,v in tab){
if((k == 1) and (v == "-")){
continue ;
}
if(k == mousePos){
if(v == "."){
continue ;
}
v = 1;
}else {
if(tonumber(v)) v=0;
}
s = string.concat(s,v);
}
var ret = tonumber(s);
return ret,mousePos;
}else return null;
}
2 个回复 | 最后更新于 2018-12-25
记录:
编号框里除其他字母外,数字自加1和自减1
mainForm.芯片编号.wndproc = function(hwnd,message,wParam,lParam){
select(message) {
case 0x20A/*_WM_MOUSEWHEEL*/
{
var wheelDelta = raw.convert({int wParam=wParam },{word vk;word delta}).delta;
if( wheelDelta > 0 ){
var pos = owner.getsel();
var cNum = (tonumber(string.match(owner.text,"\d+$")))+1;
owner.text = string.replace(owner.text,"\d+$",cNum );
owner.setsel(pos);
}else {
var pos = owner.getsel();
var cNum = (tonumber(string.match(owner.text,"\d+$")))-1;
if(cNum<=0){
cNum = 0;
}
owner.text = string.replace(owner.text,"\d+$",cNum );
owner.setsel(pos);
}
}
}
}
登录后方可回帖
加入各种判断之后的完整代码如下:
import win.ui; /*DSG{{*/ var winform = win.form(text="动态输入框调整演示";right=471;bottom=201) winform.add( edit={cls="edit";text="10";left=136;top=65;right=323;bottom=97;align="center";edge=1;font=LOGFONT(h=-21);z=1}; static={cls="static";text="点击输入框数字之间观察转动鼠标滚轮后的不同效果";left=12;top=124;right=465;bottom=174;font=LOGFONT(h=-19);transparent=1;z=2} ) /*}}*/ var editAutoInc = function(ctrl){ var n,length = tonumber(ctrl.text); if( length == #ctrl.text ){ var mousePos = ctrl.getsel(); var tab = string.split(ctrl.text) var s = null; for(k,v in tab){ if((k == 1) and (v == "-")){ continue ; } if(k == mousePos){ if(v == "."){ continue ; } v = 1; }else { if(tonumber(v)) v=0; } s = string.concat(s,v); } var ret = tonumber(s); return ret,mousePos; }else return null; } winform.edit.wndproc = function(hwnd,message,wParam,lParam){ select(message) { case 0x20A/*_WM_MOUSEWHEEL*/ { var wheelDelta = raw.convert({int wParam=wParam },{word vk;word delta}).delta; if( wheelDelta > 0 ){ var reTstr,pos = editAutoInc(winform.edit); if(reTstr){ winform.edit.text = reTstr + winform.edit.text; winform.edit.setsel(pos); } }else { var reTstr,pos = editAutoInc(winform.edit); if(reTstr){ winform.edit.text = winform.edit.text - reTstr; winform.edit.setsel(pos); } } } } } winform.show() win.loopMessage();