WinFormPermission 1.0.0
dotnet add package WinFormPermission --version 1.0.0
NuGet\Install-Package WinFormPermission -Version 1.0.0
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="WinFormPermission" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WinFormPermission" Version="1.0.0" />
<PackageReference Include="WinFormPermission" />
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 WinFormPermission --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WinFormPermission, 1.0.0"
#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 WinFormPermission@1.0.0
#: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=WinFormPermission&version=1.0.0
#tool nuget:?package=WinFormPermission&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
WinFormPermission
WinForm 通用权限管理模块(.NET Framework 4.5)
项目介绍
这是一个轻量级 WinForm 权限管理模块,支持:
- 特性/动态两种方式给控件/菜单设置权限(隐藏/禁用)
- 账号密码PBKDF2加密存储,配置文件持久化
- 登录验证 + 多权限密码修改
- 权限变更后所有窗体动态刷新
- 完美适配Button、菜单、工具栏等常用WinForm控件
QuickStart —— WinFormPermission 快速集成
一、项目引用
- 将
WinFormPermission项目添加到你的解决方案 - 你的主项目 → 引用 → 项目引用 → 勾选
WinFormPermission
二、快速使用步骤
1. 窗体继承权限基类
把你的窗体继承自 PermissionBaseForm
using WinFormPermission;
public partial class MainForm : PermissionBaseForm
{
public MainForm()
{
InitializeComponent();
}
}
2. 给控件设置权限
方式 1:特性标记「PermissionControl」
用法步骤 窗体继承PermissionBaseForm(自动加载权限规则) 给控件私有字段加[PermissionControl]特性(必须标记字段,不能标记控件实例)
public partial class MainForm : PermissionBaseForm
{
// 2. 给控件字段加特性,自动生效
[PermissionControl(UserPermission.Supervisor)] // 主管及以上可见(默认隐藏)
private Button btnSupervisor;
[PermissionControl(UserPermission.Admin, ControlState.Disabled)] // 仅管理员可用,低权限禁用
private TextBox txtAdminInfo;
[PermissionControl(UserPermission.Operator)] // 操机员及以上可见
private ToolStripMenuItem tsmiOperator;
public MainForm()
{
InitializeComponent();
}
}
方式 2:动态调用「SetControlPermission」方法(灵活,运行时可改)
// 普通按钮:主管及以上可见
btnSupervisor.SetControlPermission(UserPermission.Supervisor);
// 文本框:仅管理员可用,低权限禁用
txtAdminInfo.SetControlPermission(UserPermission.Admin, ControlState.Disabled);
// 菜单控件:操机员及以上可见
tsmiOperator.SetControlPermission(UserPermission.Operator);
// 工具栏按钮:管理员及以上可见
tsbAdmin.SetControlPermission(UserPermission.Admin);
3. 启动登录窗口
程序入口调用登录:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 直接设置权限
GlobalPermissionService.Instance.PermissionService.SetCurrentPermission(UserPermission.Employee);
Application.Run(new MainForm());
//// 调用登录
//if (LoginDialog.ShowLogin() == DialogResult.OK)
//{
// Application.Run(new MainForm());
//}
}
三、默认账号密码
普通员工(Employee):123 操机员(Operator):666 主管(Supervisor):999 管理员(Admin):ccf
四、权限说明
权限等级(从低到高): Employee < Operator < Supervisor < Admin 高等级权限自动拥有低等级的所有权限。
适用场景
- WinForm 项目快速集成权限管理
- 自用项目复用权限模块
- 小型系统快速开发
运行环境
- .NET Framework 4.5
- Visual Studio 2019 及以上
- 依赖Newtonsoft.Json(NuGet直接安装)
快速使用
- 克隆项目直接编译
- 参考 QuickStart.md 快速集成到自己的项目
- 运行 Demo 查看权限效果
开源协议
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5
- Newtonsoft.Json (>= 12.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 151 | 3/25/2026 |