一、Input
在winform开发中最基础的接受输入的控件,本例程主要演示了AntdUI Input控件(含InputNumber 数字输入框)不同的样式及输入控制效果。
import win.ui;
import dotNet.AntdUI;
import dotNet;
//dotNet.import("AntdUI");
/*DSG{{*/
var winform = win.form(text="AntdUI Input & InputNumber";right=820;bottom=805;border="thin")
winform.add(
custom_base={cls="custom";left=0;top=0;right=822;bottom=805;ah=1;aw=1;db=1;disabled=1;dl=1;dr=1;dt=1;hide=1;z=1};
custom_btn_search={cls="custom";left=527;top=630;right=623;bottom=675;dl=1;dt=1;z=11};
custom_input_multiline={cls="custom";left=20;top=215;right=790;bottom=385;dl=1;dt=1;z=9};
custom_input_password={cls="custom";left=335;top=55;right=625;bottom=100;dl=1;dt=1;z=7};
custom_input_prefix={cls="custom";left=20;top=115;right=310;bottom=160;dl=1;dt=1;z=8};
custom_input_search={cls="custom";left=17;top=630;right=528;bottom=675;dl=1;dt=1;z=10};
custom_input_username={cls="custom";left=20;top=55;right=310;bottom=100;dl=1;dt=1;z=6};
custom_lbl_input={cls="custom";left=20;top=10;right=200;bottom=45;dl=1;dt=1;z=2};
custom_lbl_multiline={cls="custom";left=20;top=170;right=300;bottom=205;dl=1;dt=1;z=3};
custom_lbl_number={cls="custom";left=20;top=409;right=300;bottom=444;dl=1;dt=1;z=5};
custom_lbl_search={cls="custom";left=21;top=577;right=301;bottom=612;dl=1;dt=1;z=4};
custom_number_decimal={cls="custom";left=335;top=454;right=625;bottom=499;dl=1;dt=1;z=13};
custom_number_int={cls="custom";left=20;top=454;right=310;bottom=499;dl=1;dt=1;z=12};
custom_number_thousand={cls="custom";left=20;top=519;right=310;bottom=564;dl=1;dt=1;z=14}
)
/*}}*/
// 创建 AntdUI 嵌入容器
var baseForm = AntdUI.BaseForm();
baseForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
baseForm.Dock = System.Windows.Forms.DockStyle.Fill;
dotNet.setParent(baseForm, winform.custom_base);
// ---------- 英文标题 ----------
var lblInput = AntdUI.Label(winform.custom_lbl_input);
lblInput.Text = "Input";
lblInput.Font = System.Drawing.Font("Microsoft YaHei", 14, System.Drawing.FontStyle.Bold);
var lblMultiline = AntdUI.Label(winform.custom_lbl_multiline);
lblMultiline.Text = "Multiline Input";
lblMultiline.Font = System.Drawing.Font("Microsoft YaHei", 14, System.Drawing.FontStyle.Bold);
var lblSearch = AntdUI.Label(winform.custom_lbl_search);
lblSearch.Text = "Search Bar";
lblSearch.Font = System.Drawing.Font("Microsoft YaHei", 14, System.Drawing.FontStyle.Bold);
var lblNumber = AntdUI.Label(winform.custom_lbl_number);
lblNumber.Text = "InputNumber";
lblNumber.Font = System.Drawing.Font("Microsoft YaHei", 14, System.Drawing.FontStyle.Bold);
// ---------- 1. 常规 Input ----------
var userNameSvg = '<svg t="1780275317090" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5337" width="32" height="32"><path d="M502.057361 0q-81.323658 0-150.047876 40.661829T243.19614 151.19328q-40.089127 69.869622-40.089127 152.338683 0 74.451236 34.362109 139.739243 33.216705 64.142603 90.486887 106.522538-76.742043 33.216705-136.875735 94.4958T98.875282 784.601489q-34.362109 81.323658-34.362109 170.665141h1.145404q1.145404 19.471862 14.317545 32.071302t31.4986 12.59944q18.326458 0 31.4986-12.59944t14.317545-32.071302h1.145404v-3.436211q0-89.341483 42.379934-168.374334 40.089127-75.59664 111.676855-124.276294T471.131463 602.482311l9.163229 2.290807q13.744844 1.145404 21.762669 1.145404 81.323658 0 149.475174-40.661829t108.813345-109.958749Q801.007709 386.001024 801.007709 303.531963T760.34588 151.19328Q719.684051 81.323658 650.959833 40.661829T502.057361 0z m0 511.995424q-56.124778 0-103.659029-28.062389t-75.59664-76.169342Q294.739303 359.656741 294.739303 302.386559t28.062389-105.377134Q350.864081 148.902472 397.82563 120.840083T501.484659 92.777694q56.69748 0 104.231731 28.062389T680.740328 197.009425q27.489687 48.106953 27.489687 105.377134t-27.489687 105.377134q-27.489687 48.106953-75.023938 76.169342T502.057361 511.995424z m436.398784 440.980399v-1.145404q-1.145404-89.341483-35.507512-169.519737-33.216705-79.032851-92.777695-139.739244-12.59944-12.59944-31.4986-12.59944t-32.071301 13.172142Q733.428895 656.316282 733.428895 675.215442t13.744843 32.644003q45.816145 48.106953 71.587728 111.104153T844.533047 951.830419v3.436211h1.145404q1.145404 19.471862 14.317545 32.071302t31.4986 12.59944q18.326458 0 31.4986-12.59944t14.317546-32.071302h1.145403z" p-id="5338" fill="#515151"></path></svg>'
var inputUsername = AntdUI.Input(winform.custom_input_username);
inputUsername.IconRatio = 0.9;
inputUsername.PaddGap = 0.8;
inputUsername.PrefixSvg = userNameSvg;
inputUsername.PlaceholderText = "Username";
inputUsername.Font = System.Drawing.Font("Tahoma", 10);
var passwordSvg='<svg t="1780380575056" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9686" width="32" height="32"><path d="M819.2 1024 204.8 1024C134.1184 1024 76.8 966.6816 76.8 896L76.8 588.8C76.8 536.3456 108.4416 491.3664 153.6 471.6032L153.6 358.4C153.6 160.4608 314.0608 0 512 0 678.3744 0 817.8688 113.536 858.2656 267.264L857.7536 267.4176C859.0848 271.9488 860.0064 276.6336 860.0064 281.6 860.0064 309.8624 837.0688 332.8 808.8064 332.8 786.4576 332.8 767.6416 318.3872 760.6528 298.4192L760.6528 298.4192C733.6192 186.0352 632.704 102.4 512 102.4 370.6112 102.4 256 217.0112 256 358.4L256 460.8 277.4528 460.8C277.4528 460.8 277.4528 460.8 277.4528 460.8L819.2 460.8C889.8816 460.8 947.2 518.1184 947.2 588.8L947.2 896C947.2 966.6816 889.8816 1024 819.2 1024ZM844.8 614.4C844.8 586.112 821.888 563.2 793.6 563.2L230.4 563.2C202.112 563.2 179.2 586.112 179.2 614.4L179.2 870.4C179.2 898.6624 202.112 921.6 230.4 921.6L793.6 921.6C821.888 921.6 844.8 898.6624 844.8 870.4L844.8 614.4Z" p-id="9687" fill="#515151"></path></svg>'
var inputPassword = AntdUI.Input(winform.custom_input_password);
inputPassword.PlaceholderText = "Password";
inputPassword.PasswordChar = '●';
inputPassword.AllowClear = true;
inputPassword.IconRatio = 0.9;
inputPassword.PaddGap = 0.8;
inputPassword.PrefixSvg=passwordSvg
inputPassword.Font = System.Drawing.Font("Tahoma", 10);
// ---------- inputPrefix 带输入校验与提示 ----------
var inputPrefix = AntdUI.Input(winform.custom_input_prefix);
inputPrefix.PlaceholderText = "example.com";
inputPrefix.PrefixText = "https://";
inputPrefix.Font = System.Drawing.Font("Tahoma", 10);
var inputPrefixPopover = null;
var closeInputPrefixPopover = function(){
if(inputPrefixPopover){
call(function(){
inputPrefixPopover.Close();
});
inputPrefixPopover = null;
}
}
var showInputPrefixPopover = function(){
if(inputPrefixPopover) return;
inputPrefixPopover = AntdUI.Popover.open(
inputPrefix,
"提示",
"仅允许英文字母、数字和点号"
);
}
// 输入校验事件
inputPrefix.VerifyChar = function(sender, e){
var c = e.Char; // 数值,如 97 表示 'a'
// 退格键(8) 放行
if(c == 8){
e.Result = true;
return;
}
// 允许:数字 0-9 (48~57),大写字母 A-Z (65~90),小写字母 a-z (97~122),点号 '.' (46)
if( (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 46 ){
e.Result = true;
sender.Status=AntdUI.TType.None
closeInputPrefixPopover();
}
else{
e.Result = false;
sender.Status=AntdUI.TType.Error
// tipComponent.open(sender, "仅允许英文字母、数字和点号")
showInputPrefixPopover();
}
};
// ---------- 2. 多行文本(Emoji 已启用) ----------
var inputMultiline = AntdUI.Input(winform.custom_input_multiline);
inputMultiline.Multiline = true;
inputMultiline.AutoScroll = true;
inputMultiline.Font = System.Drawing.Font("Microsoft YaHei", 12);
inputMultiline.Text = '吾妻淑柔,展信安康,随信寄两百元,我一切无恙,生意昌顺,行船入夜,恰江上升明月,圆如玉坠,仿若身在故乡,似与你并肩共赏,江海万里,心中念你,便不觉遥远。\r\n——电影《给阿嬷的情书》';
// ---------- 3. 组合搜索(无缝拼接) ----------
var inputSearch = AntdUI.Input(winform.custom_input_search);
inputSearch.Text = "电影《给阿嬷的情书》";
inputSearch.Font = System.Drawing.Font("Microsoft YaHei", 12);
inputSearch.JoinRight = true; // 消除右侧边框
var btnSearch = AntdUI.Button(winform.custom_btn_search);
btnSearch.Text = "bing";
btnSearch.Type = AntdUI.TTypeMini.Primary;
btnSearch.Font = System.Drawing.Font("Tahoma", 9);
btnSearch.JoinLeft = true; // 消除左侧边框,与输入框融合
btnSearch.Click = function(s, e){
var query = inputSearch.Text;
if(query){
import inet.url
raw.execute("https://www.bing.com/search?q=" ++ inet.url.encode(query));
}
};
// ---------- 4. InputNumber ----------
var numInt = AntdUI.InputNumber(winform.custom_number_int);
numInt.Value = 58;
numInt.DecimalPlaces = 0;
numInt.Minimum = 0;
numInt.Maximum = 100;
numInt.Increment = 1;
numInt.SuffixText = "分";
numInt.Status = AntdUI.TType.Error;
numInt.ValueChanged = function(sender, e){
if(tonumber(sender.Value) < 60){
sender.Status = AntdUI.TType.Error;
}
else {
sender.Status = AntdUI.TType.None;
}
};
var numDecimal = AntdUI.InputNumber(winform.custom_number_decimal);
numDecimal.Value = 3.14;
numDecimal.DecimalPlaces = 2;
numDecimal.Minimum = 0;
numDecimal.Increment = 0.01;
var numThousand = AntdUI.InputNumber(winform.custom_number_thousand);
numThousand.Value = 10800000000.00;
numThousand.DecimalPlaces = 2;
numThousand.ThousandsSeparator = true;
numThousand.PrefixText = "$";
numThousand.Font = System.Drawing.Font("Tahoma", 10);
// ---------- 显示窗口 ----------
winform.show();
win.loopMessage();
下一篇预告:AntdUI Checkbox等选择类控件