aardio 官方社区

用户名  找回密码
 注册会员

QQ登录

只需一步,快速开始

帖子
查看: 13433|回复: 3

基于标准库的inputbox,修改为用户库

[复制链接]

4

主题

45

回帖

733

积分

三级会员

积分
733
发表于 2018-4-10 23:59:15 | 显示全部楼层 |阅读模式
自带的inputbox显示和表现不符合预期,于是自己对标准库进行了一些修改,感谢作者开源了标准库,可以深入学习。
然后吧修改的inputbox库加入用户库,作为用户库来调用。代码智能感知部分未作深入探究,语法提示可能会有问题。
本文知识要点:inputbox,修改标准库,标准库的修改,用户库。

主文件代码如下:
  1. import win.ui;
  2. import inputbox2;//使用之前一定要先导入
  3. /*DSG{{*/
  4. var winform = win.form(text="测试用户库的inputbox";right=515;bottom=252)
  5. winform.add(
  6. button={cls="button";text="打开inputbox";left=147;top=100;right=351;bottom=160;z=1}
  7. )
  8. /*}}*/

  9. //自定义的inputbox初始化函数,避免oncommand函数内凌乱
  10. create_inputbox=function(){
  11.     inputbox = inputbox2.inputBox(mainForm.hwnd,true)
  12.         inputbox.text = "用户登录"
  13.         inputbox.info.text = "请输入密码:"
  14.         inputbox.input.text = "";
  15.         inputbox.input.passwordChar="*"
  16.         //inputbox.setPos(,,800,600)
  17.         //如果设定窗体大小导致显示效果不佳,可以到用户库内修改布局
  18.         //inputbox实质上是一个窗体,可以根据对窗体的需求自行修改和调用所需函数
  19.         inputbox.center()
  20.         return  inputbox;
  21. }

  22. winform.button.oncommand = function(id,event){
  23.         while(true){
  24.                          pass=create_inputbox().doModal();
  25.                          if(pass=="123"){//设定密码为123
  26.                                  break ;       
  27.                          }
  28.                          elseif(pass==null){
  29.                                                           win.msgbox("没有输入密码错误,登陆失败。","提示")
  30.                                                           break ;
  31.                          }                        
  32.                          else{
  33.                                  var msg=win.msgbox("密码错误,请重新输入。密码为123.","提示",0x3/*_MB_YESNOCANCEL*/+0x20/*_MB_ICONQUESTION*/)
  34.                                  }       
  35.         }
  36.         win.msgbox(pass);
  37. }

  38. winform.show();
  39. win.loopMessage();
复制代码


用户库的用法:将下面的代码存为文件名为 inputbox2.aardio 的代码文件,添加到 工程资源管理器 里 用户库 文件夹(实际文件夹名为lib)中。
用户库代码如下:
  1. //inputBox2 优化的输入框
  2. import win.ui;
  3. namespace inputbox2;

  4. class  inputBox{
  5.         ctor(parent,password){  
  6.                        
  7.                 this = ..win.form(
  8.                         cls="";
  9.                         text="aardio form";
  10.                         right=442;bottom=137;
  11.                         border="dialog frame";
  12.                         max=false;min=false;
  13.                         mode="popup";sysmenu=1;
  14.                         parent=parent;
  15.                         )
  16.                 this.add(
  17.                 btnCancel={
  18.                 cls="button";text="取消";
  19.                 left=349;top=90;right=423;
  20.                 bottom=118;db=1;dr=1;z=2};
  21. btnOk={
  22.                 cls="button";text="确定";
  23.                 left=256;top=90;right=330;
  24.                 bottom=118;db=1;dr=1;
  25.                 style=1;z=1
  26.                 };
  27. info={
  28.                 cls="static";text="请输入";
  29.                 left=20;top=20;right=350;
  30.                 bottom=38;dl=1;dt=1;notify=1;
  31.                 transparent=1;z=4
  32.                 };
  33. input={
  34.                 cls="edit";
  35.                 left=20;top=46;right=423;
  36.                 bottom=71;dl=1;dt=1;
  37.                 edge=1;password=1;z=3
  38.                 }
  39.                 )

  40.                 this.onInitDialog = function(hwnd,message,wParam,lParam){
  41.                         this.input.setFocus();
  42.                 };
  43.                
  44.                 this.btnCancel.oncommand = function(id,event){
  45.                         this.endModal();
  46.                 };
  47.                
  48.                 this.btnOk.oncommand = function(id,event){
  49.                         this.endModal( this.input.text );
  50.                 };  
  51.                
  52.                 this.onOk = function(){
  53.                     this.endModal( this.input.text );
  54.                 };
  55.                
  56.                 this.onCancel = function(){
  57.                     this.endModal();
  58.                 };
  59.         }
  60. }


  61. /***intellisense()
  62. inputbox2.inputBox() = 创建一个输入对话框
  63. inputbox2.inputBox(__/*可选在此指定父窗口*/) = 创建一个输入对话框
  64. inputbox2.inputBox(0__/*可选在此指定父窗口*/,true) = 创建一个输入密码的对话框
  65. !inputBox.doModal() = 弹出输入对话框\n该函数返回用户输入的值\n取消则返回null空值
  66. !inputBox.onInitDialog = @.onInitDialog = function(hwnd,message,wParam,lParam){\n        ??.center()__/*输入框初始化完成触发该函数*/\n}
  67. !inputBox.center() = 居中显示
  68. !inputBox.info = !edit.
  69. !inputBox.input = !edit.
  70. !inputBox.text = 输入框标题
  71. !inputBox.setPos(.(x,y,宽,高,插入位置,参数) = 调整窗口位置或排序\n所有参数可选
  72. !inputBox.getPos() = 返回相对坐标,宽,高
  73. !inputBox.topmost()=窗体始终最前
  74. !inputBox.topmost(false)=取消窗体始终最前
  75. !inputBox.modifyStyle(.(remove,add) = 如果指定第三个参数,则使用此参数调用::SetWidnowPos
  76. !inputBox.modifyStyleEx(.(remove,add) = 如果指定第三个参数,则使用此参数调用::SetWidnowPos  
  77. !inputBox.setInterval = @var tmId = ??.setInterval( \n        1000,\n        function(id){\n                /*定时回调函数*/\n        } \n)
  78. !inputBox.clearInterval(__/*请输入ID*/) = 删除定时器
  79. !inputBox.changeInterval(__/*请输入ID*/,1000) = 重新设定定时器的延时时间
  80. !inet_downBox.setTimeout(.(函数名,延时,其他参数) = 延时执行函数
  81. ?inputbox2.inputBox = !inputBox.
  82. end intellisense***/
复制代码


显示效果和之前差不多,只是做了一些细微的修改,就不上图了。

166

主题

2154

回帖

1万

积分

管理员

积分
13056
发表于 2018-4-11 00:38:33 | 显示全部楼层
自己根据需要改是可以的,
问题是一下子没看出来改了哪

166

主题

2154

回帖

1万

积分

管理员

积分
13056
发表于 2018-4-11 00:52:57 | 显示全部楼层
仔细比对了一下,原来你是去掉了最大化最小化按钮。
确实inputBox没必要这些按钮,但是按钮右对齐似乎不是很好,
这种你可以直接提交到意见反馈,我会改的,标准库里已经改了, 谢谢!

4

主题

45

回帖

733

积分

三级会员

积分
733
 楼主| 发表于 2018-4-11 08:57:35 | 显示全部楼层
Jacen.He 发表于 2018-4-11 00:52
仔细比对了一下,原来你是去掉了最大化最小化按钮。
确实inputBox没必要这些按钮,但是按钮右对齐似乎不是 ...

其实我一开始没想改标准库的,我搜了一下资料,好像只有VB自带,很多都是自己封装或者调用VB,就不太希望aardio的和VB的一样,就自己做成了用户库。
我主要是昨天复习inputbox的时候,写个一个反复验证密码的过程,却不小心导致后台线程残留,所以写一个完美一点的示例,给其他人省点力气;原来的inputbox最大化和设定指定大小后显示不太好看,就修改了一下源码;怕下次更新会导致样式恢复,我就采用了用户库的形式。
这篇帖其实应该是三合一:使用inputbox实现反复验证密码,标准库的修改,用户库的用法。着重是第一个。
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

手机版|未经许可严禁引用或转载本站文章|aardio.com|aardio 官方社区 ( 皖ICP备09012014号 )

GMT+8, 2025-6-19 08:44 , Processed in 0.059660 second(s), 22 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表