关于PB EditMask控件限制输入范围的问题

IT_TOM 2011-09-13 10:17:41
如题,PB的EditMask控件有属性min和max,希望能在任何时候限制用户输入的值都在我指定的范围内,不仅在于spin控件起作用,包括键盘直接输入也需要能够限制到,我尝试在pbm_keydown事件里判断然后返回1,好像并不起作用

求一个解决方案!
...全文
830 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
下午我再试试看,我好像单独用你的是可以控制,先谢谢了
yyoinge 2011-09-13
  • 打赏
  • 举报
回复
你通过uo_editmask建立一个控件,不对该控件写任何代码,看看能否输入201
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
可以啊,而且范围我是动态设置的,用spin控件是不行的,我用键盘输入可以输入几千几万的
yyoinge 2011-09-13
  • 打赏
  • 举报
回复
我那个对象默认的minmax为1~200,导入后建立的对象中,你可以输入大于200的数字吗?
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
我已经导入了,你给我的可以看到spin按钮,点按钮本来就可以控制的,但用键盘输入就不行,会不会PB版本问题
yyoinge 2011-09-13
  • 打赏
  • 举报
回复
dropdownlistbox是没有水平滚动条的,因为dropdownlistbox控件本身也是没有水平滚动条的
yyoinge 2011-09-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 it_tom 的回复:]
还是不行啊,而且我不想使用spin属性,而且即使使用了spin属性,当我用键盘输入的时候仍然可以输入范围外的值
[/Quote]

你肯定没有试过,试了再来说吧,可以的
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
另外发现数据窗体列使用DropDownListBox时无法出现水平滚动条,即使勾上Auto Horizontal Scroll也不行,使用PB版本是11.5 3127
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
还是不行啊,而且我不想使用spin属性,而且即使使用了spin属性,当我用键盘输入的时候仍然可以输入范围外的值
yyoinge 2011-09-13
  • 打赏
  • 举报
回复
以下内容保存为uo_editmask.sru
然后导入pbl中
利用它来创建editmask

$PBExportHeader$uo_editmask.sru
forward
global type uo_editmask from editmask
end type
end forward

global type uo_editmask from editmask
integer width = 457
integer height = 128
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = roman!
string facename = "Times New Roman"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
string mask = "##0"
boolean spin = true
string minmax = "1~~200"
event ue_change pbm_enchange
end type
global uo_editmask uo_editmask

type variables
boolean ib_change
end variables

event ue_change;long ll_min, ll_max
ll_min = long(left(minmax, pos(minmax, '~~') - 1))
ll_max = long(mid(minmax, pos(minmax, '~~') + 1))
if not ib_change and ll_min > 0 and ll_max > 0 then
ib_change = true
int li_pos
li_pos = selectedstart( )
if long(text) > ll_max or long(text) < ll_min then
text = left(text, li_pos - 2) + mid(text, li_pos)
this.selecttext(li_pos - 1,0)
end if
ib_change = false
end if

end event

on uo_editmask.create
end on

on uo_editmask.destroy
end on

IT_TOM 2011-09-13
  • 打赏
  • 举报
回复
这是我按照你的思路做的,不过有个问题如果没有指定默认值则不输入值,如果最小值为50,最大值为100,如果开始没有默认最小值50,连一个数字都不能输入,而且我的掩码是decimalmask!,mask是########.####,默认值为50,我想输入变成55却不行,如果是550,然后在ue_change里删除刚输入的值5最后还是50
IT_TOM 2011-09-13
  • 打赏
  • 举报
回复

forward
global type uo_editmask from editmask
end type
end forward

global type uo_editmask from editmask
integer width = 457
integer height = 128
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = roman!
string facename = "Times New Roman"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
maskdatatype maskdatatype = datemask!
string minmax = "1~~200"
event ue_change pbm_enchange
end type
global uo_editmask uo_editmask

type variables
//boolean ib_change
Public:
Boolean ib_Validatebound = False//驗證範圍
String is_min,is_max//範圍值
end variables

forward prototypes
public function boolean uf_validatebound ()
end prototypes

event ue_change;//long ll_min, ll_max
//ll_min = long(left(minmax, pos(minmax, '~~') - 1))
//ll_max = long(mid(minmax, pos(minmax, '~~') + 1))
//if not ib_change and ll_min > 0 and ll_max > 0 then
// ib_change = true
// int li_pos
// li_pos = selectedstart( )
// if long(text) > ll_max or long(text) < ll_min then
// text = left(text, li_pos - 2) + mid(text, li_pos)
// this.selecttext(li_pos - 1,0)
// end if
// ib_change = false
//end if
Integer li_pos

IF Not uf_validatebound() THEN
li_pos = selectedstart( )
THIS.Text = Left(THIS.Text, li_pos - 2) + mid(THIS.Text, li_pos)
THIS.selecttext(li_pos - 1,0)
END IF
end event

public function boolean uf_validatebound ();any la_min,la_max,la_value

IF Not ib_Validatebound THEN Return True

CHOOSE CASE THIS.MaskDatatype
CASE datemask!
la_value = Date(THIS.Text)
la_min = Date(is_min)
la_max = Date(is_max)
CASE datetimemask!
la_value = DateTime(THIS.Text)
la_min = DateTime(is_min)
la_max = DateTime(is_max)
CASE decimalmask!
la_value = Dec(THIS.Text)
la_min = Dec(is_min)
la_max = Dec(is_max)
CASE numericmask!
la_value = long(THIS.Text)
la_min = long(is_min)
la_max = long(is_max)
CASE stringmask!
la_value = THIS.Text
la_min = is_min
la_max = is_max
CASE timemask!
la_value = Time(THIS.Text)
la_min = Time(is_min)
la_max = Time(is_max)
CASE ELSE
Return False
END CHOOSE

Return (la_value >= la_min AND la_value <= la_max)
end function

on uo_editmask.create
end on

on uo_editmask.destroy
end on

event constructor;//默認為最小值
THIS.Text = is_min
//設置範圍
THIS.Minmax = is_min+"~~"+is_max
end event


604

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 控件与界面
社区管理员
  • 控件与界面社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧