WinFormTools 1.0.3
dotnet add package WinFormTools --version 1.0.3
NuGet\Install-Package WinFormTools -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WinFormTools" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WinFormTools" Version="1.0.3" />
<PackageReference Include="WinFormTools" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WinFormTools --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WinFormTools, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WinFormTools@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WinFormTools&version=1.0.3
#tool nuget:?package=WinFormTools&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
[toc]
怎样使用
CheckedListBox 的扩展方法
/// <summary>
/// 绑定数据源
/// </summary>
public static void BindDatas<T>(this CheckedListBox listBox, List<T> datas, string dsiplay, string value) where T : class, IKey
/// <summary>
/// 获取选中数据
/// </summary>
public static List<T> GetSelectedData<T>(this CheckedListBox listBox) where T : class, IKey
/// <summary>
/// 设置选中数据
/// </summary>
public static void SetSelectedData<T>(this CheckedListBox listBox, T selectedItem) where T : class, IKey
/// <summary>
/// 绑定枚举
/// </summary>
public static void BindEnum<T>(this CheckedListBox listBox, List<T>? exclude = null) where T : Enum
/// <summary>
/// 获取选中枚举
/// </summary>
public static List<T> GetSelectedEnum<T>(this CheckedListBox listBox) where T : struct
/// <summary>
/// 设置选中枚举
/// </summary>
public static void SetSelectedEnum<T>(this CheckedListBox listBox, T selectedItem) where T : Enum
ComboBox 的扩展方法
/// <summary>
/// 绑定数据源
/// </summary>
public static void BindDatas<T>(this ComboBox comboBox, List<T> datas, string dsiplay, string value) where T : class, IKey
/// <summary>
/// 获取选中数据
/// </summary>
public static T? GetSelectedData<T>(this ComboBox comboBox) where T : class, IKey
/// <summary>
/// 设置选中数据
/// </summary>
public static void SetSelectedData<T>(this ComboBox comboBox, T? selectedItem) where T : class, IKey
/// <summary>
/// 绑定枚举
/// </summary>
public static void BindEnum<T>(this ComboBox comboBox, List<T>? exclude = null) where T : Enum
/// <summary>
/// 获取选中枚举
/// </summary>
public static T GetSelectedEnum<T>(this ComboBox comboBox) where T : struct
/// <summary>
/// 设置选中枚举
/// </summary>
public static void SetSelectedEnum<T>(this ComboBox comboBox, T selectedItem) where T : Enum
ListBox 的扩展方法
/// <summary>
/// 绑定数据源
/// </summary>
public static void BindDatas<T>(this ListBox listBox, List<T> datas, string dsiplay, string value) where T : class, IKey
/// <summary>
/// 获取选中数据
/// </summary>
public static T? GetSelectedData<T>(this ListBox listBox) where T : class, IKey
/// <summary>
/// 设置选中数据
/// </summary>
public static void SetSelectedData<T>(this ListBox listBox, T? selectedItem) where T : class, IKey
/// <summary>
/// 绑定枚举
/// </summary>
public static void BindEnum<T>(this ListBox listBox, List<T>? exclude = null) where T : Enum
/// <summary>
/// 获取选中枚举
/// </summary>
public static T GetSelectedEnum<T>(this ListBox listBox) where T : struct
/// <summary>
/// 设置选中枚举
/// </summary>
public static void SetSelectedEnum<T>(this ListBox listBox, T selectedItem) where T : Enum
GridView 的扩展方法
/// <summary>
/// 绑定的数据集合
/// </summary>
public static List<T> GetBindModels<T>(this DataGridView gridView) where T : class, IKey
/// <summary>
/// 获取选中数据集合
/// </summary>
public static List<T> GetSelectedModels<T>(this DataGridView gridView) where T : class, IKey
/// <summary>
/// 获取勾选数据集合
/// </summary>
public static List<T> GetCheckedModels<T>(this DataGridView gridView) where T : class, IKey, IGridView
/// <summary>
/// 设置选中数据集合
/// </summary>
public static void SetSelectModels<T>(this DataGridView gridView, List<T> selectedDatas) where T : class, IKey
/// <summary>
/// 行号显示
/// </summary>
public static void DrawRowNo(this DataGridView gridView)
/// <summary>
/// 设置复选框列
/// </summary>
public static void SetCheckBox<T>(this DataGridView gridView) where T : class, IKey, IGridView
/// <summary>
/// 设置DataGridView样式
/// </summary>
public static void SetStyle(this DataGridView gridView, List<DataGridViewTextBoxColumn>? canEditColumn = null)
/// <summary>
/// 设置DataGridView样式2
/// </summary>
public static void SetStyle2(this DataGridView gridView, List<DataGridViewColumn>? canEditColumn = null)
TreeView 的扩展方法
/// <summary>
/// 绑定模型到TreeView
/// </summary>
public static void BindModels<T>(this TreeView treeView, List<T> models) where T : class, ITreeView<T>, IKey
/// <summary>
/// 获取选中的节点模型
/// </summary>
public static T GetSelectedModel<T>(this TreeView treeView) where T : class, ITreeView<T>, IKey
/// <summary>
/// 根据模型设置选中节点
/// </summary>
public static void SetSelectedNode<T>(this TreeView treeView, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 根据模型设置选中节点
/// </summary>
public static void SetCheckedNode<T>(this TreeView treeView, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 获取选中的节点模型
/// </summary>
public static List<T> GetCheckModels<T>(this TreeView treeView) where T : class, ITreeView<T>, IKey
/// <summary>
/// treeView的节点选中联动操作
/// </summary>
public static void SetCheckAction(this TreeView treeView)
/// <summary>
/// 展开到指定层级
/// </summary>
public static void ExpandTo(this TreeView treeView, int level)
/// <summary>
/// 为父节点插入子节点
/// </summary>
public static void InsertChild<T>(this TreeView treeView, T parentModel, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 为父节点插入多个节点
/// </summary>
public static void InsertChildren<T>(this TreeView treeView, T parentModel, List<T> models) where T : class, ITreeView<T>, IKey
/// <summary>
/// 在当前节点前插入节点
/// </summary>
public static void InsertBefore<T>(this TreeView treeView, T currentModel, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 在当前节点后插入节点
/// </summary>
public static void InsertAfter<T>(this TreeView treeView, T currentModel, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 根据模型查找节点
/// </summary>
public static TreeNode FindNode<T>(this TreeView treeView, T model) where T : class, ITreeView<T>, IKey
/// <summary>
/// 取TreeView的所有节点
/// </summary>
public static List<TreeNode> GetAllNodes(this TreeView treeView)
怎样调用webapi
准备项目
1.新建一个类库项目,假设项目名为:WebApiClient
2.在你的Winform主项目程序的App.config文件中加入
<appSettings>
<add key="WebApiClientDll" value="WebApiClient"/>
</appSettings>
3.通过nuget在你的Winform主项目中安装 WinFormTools
4.你的Winform窗体都继承FormBase类,如果是弹出窗体就继承FormPopBase类
5.程序启动进调用 ClientManager.Register()
创建请求接口
在WebApiClient项目中创建接口文件IDicClient.cs
internal class DicClientInfo
{
public const string Prefix = "Dic";
public const string Add = Prefix + "/" + nameof(Add);
public const string Update = Prefix + "/" + nameof(Update);
public const string UpdateStatus = Prefix + "/" + nameof(UpdateStatus);
public const string PageList = Prefix + "/" + nameof(PageList);
public const string GetByGroupId = Prefix + "/" + nameof(GetByGroupId);
}
#if DEBUG
[TraceFilter(OutputTarget = OutputTarget.Debug)]
#endif
public interface IDicClient : IHttpApi
{
/// <summary>
/// 添加字典
/// </summary>
/// <param name="dicModel"></param>
/// <returns></returns>
[HttpPost(DicClientInfo.Add)]
Task<ApiResult<bool>> Add([JsonContent] DicModel dicModel);
/// <summary>
/// 更新字典
/// </summary>
/// <param name="dicModel"></param>
/// <returns></returns>
[HttpPost(DicClientInfo.Update)]
Task<ApiResult<bool>> Update([JsonContent] DicModel dicModel);
/// <summary>
/// 更新状态
/// </summary>
/// <param name="dicModel"></param>
/// <returns></returns>
[HttpPost(DicClientInfo.UpdateStatus)]
Task<ApiResult<bool>> UpdateStatus([JsonContent] DicModel dicModel);
/// <summary>
/// 分页查询字典
/// </summary>
/// <param name="queryModel"></param>
/// <returns></returns>
[HttpGet(DicClientInfo.PageList)]
Task<ApiResult<PageResult<DicModel>>> PageList(DicPageQueryModel queryModel);
/// <summary>
/// 获取字典组里面的字典
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
[HttpGet(DicClientInfo.GetByGroupId)]
Task<ApiResult<List<DicModel>>> GetByGroupId(Guid groupId);
}
分页请求api(带进度条)
在窗体文件中请求接口
var resultPage = ClientRequest<IDicClient>.RequestProcess(this, r => r.PageList(queryModel).Result);
添加请求api(带进度条)
在窗体文件中请求接口
var resultAdd = ClientRequest<IDicClient>.RequestProcess(this, r => r.Add(model).Result);
编辑请求api(带进度条)
在窗体文件中请求接口
var resultUpdate = ClientRequest<IDicClient>.RequestProcess(this, r => r.Update(DicModel).Result);
删除请求api
在窗体文件中请求接口
var resultDel = ClientRequest<IDicClient>.RequestProcess(this, r => r.UpdateStatus(model).Result);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0-windows7.0
- Autofac (>= 8.0.0)
- CommTools.New (>= 1.0.0)
- WebApiClient.JIT (>= 1.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
调整为通过App.config读取程序集