WPF表单组件,表单项支持:简单文本、格式校验文本、多选项、按钮选择项,支持两种界面风格。
ZFormDialog
ZFormGrid
GitHub地址:
ZhyForm:WPF表单组件
目录说明:
- zhy.common.form:基于.Net Framework 4.8框架。
- zhy.common.form.core:基于.Net 6.0框架。
项目引用:
- 编译源码后,在项目中添加编译生成的zhy.common.form.dll或zhy.common.form.core.dll引用;Dll文件
- 在解决方案中直接引入zhy.common.form.csproj或zhy.common.form.core.csproj项目;
代码示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| ZTextFormItem zTextFormItem = new ZTextFormItem(); zTextFormItem.Title = "输入项"; zTextFormItem.Value = "输入值"; zTextFormItem.IsRequired = true;
ZFormatTextFormItem zFormatTextFormItem = new ZFormatTextFormItem(); zFormatTextFormItem.Title = "格式验证项"; zFormatTextFormItem.IsRequired = true; zFormatTextFormItem.ErrMessage = "输入必须位数字!"; zFormatTextFormItem.FormatVerification = (currentVal) => { try { int v = int.Parse(currentVal); return true; } catch { return false; } };
ZComboFormItem zComboFormItem = new ZComboFormItem(); zComboFormItem.Title = "多选项"; zComboFormItem.Values = new List<ZComboItem> { new ZComboItem() { Display = "项1", Value="值1" }, new ZComboItem() { Display = "项2", Value="值2" }, new ZComboItem() { Display = "项3", Value="值3" } };
ZButtonFormItem zButtonFormItem = new ZButtonFormItem(); zButtonFormItem.Title = "选择项"; zButtonFormItem.ButtonContent = "参数选择"; zButtonFormItem.Value = "选择值"; zButtonFormItem.IsReadOnly = true; zButtonFormItem.ButtonCommand = (currentVal) => { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string selectedPath = folderBrowserDialog.SelectedPath; if (selectedPath.Last() != Path.DirectorySeparatorChar) selectedPath += Path.DirectorySeparatorChar; return selectedPath; } return currentVal; };
List<IZFormItem> zFormItems = new List<IZFormItem>(); zFormItems.Add(zTextFormItem); zFormItems.Add(zFormatTextFormItem); zFormItems.Add(zComboFormItem); zFormItems.Add(zButtonFormItem);
ZFormGrid zFormGrid = new ZFormGrid(zFormItems); zFormGrid.Title = "测试"; bool dr = (bool)zFormGrid.ShowDialog(); ; if (dr) { List<ZFormResultItem> resultItems = zFormGrid.ResultItems; }
ZFormDialog zFormDialog = new ZFormDialog(zFormItems); zFormDialog.Title = "测试"; bool dr1 = (bool)zFormDialog.ShowDialog(); if (dr1) { List<ZFormResultItem> resultItems = zFormDialog.ResultItems; }
|
API参考
zhy.common.form API参考
zhy.common.form.core API参考