winform

WinForm控件之【ProgressBar】

匿名 (未验证) 提交于 2019-12-02 23:49:02
基本介绍 进度条控件,用于显示某操作动作进度或跑马灯效果。 常设置属性 Value :获取或设置进度栏的当前位置; Style :进度栏指示进度所使用的展示方式; Maximum :控件使用范围的上限; Minimum :控件使用范围的下限; MarqueeAnimationSpeed :进度块在进度栏内滚动所用的时间段,以毫秒为单位; Step :调用PerformStep()方法增加进度栏的当前位置时所根据的数量; Enabled :指示是否启用该控件,true为启用状态用户可编辑,false为禁用状态用户不可编辑; Name :指示代码中用来标识该对象的名称; 事例举例 相关代码      //任务:获取指定目录下所有文件,将文件基本信息显示在列表上 private void btn_ImportData_Click(object sender, EventArgs e) { //获取指定目录下所有文件数量(实际过程忽略) int fileCount = 10; //设置进度条基础属性 this.progressBar1.Value = 0; this.progressBar1.Style = ProgressBarStyle.Blocks; this.progressBar1.Maximum = fileCount; this.progressBar1.Minimum =

winform PictureBox图片上动态添加Label或其他控件

匿名 (未验证) 提交于 2019-12-02 23:47:01
代码: //分页或者多次加载时,需要删除之前产生的lable等控件 for (int tabID = 0; tabID < 15; tabID++) { foreach (Control control in this.tableLayoutPanel2.Controls) { // 遍历所有TextBox... if (control is PictureBox) { PictureBox t = (PictureBox)control; if (control.TabIndex == tabID) { if (tabID > list.Count - 1) { for (int i = tabID; i < 15; i++) { //this.tableLayoutPanel2.Controls.Remove(control); t.ImageLocation = null; t.Controls.Remove(t.Controls[tabID.ToString()]); string d = ("NO" + tabID.ToString()); t.Controls.Remove(t.Controls[d]); t.Tag = -1; } break; } t.ImageLocation = list[tabID].VehicleImage; t.Tag = (list

C# winform子线程更新UI

匿名 (未验证) 提交于 2019-12-02 23:43:01
在winform界面开发时,肯定会遇到子线程更新UI的情况,以前我都是这样写的: private void WorkThread2() { while (true) { UpdateLabel1(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Thread.Sleep(500); } } private void UpdateLabel1(string msg) { if (this.label1.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True { this.label1.Invoke(new Action<string>(UpdateLabel1), new object[] { msg }); } else { this.label1.Text = msg; } } 现在可以更简洁一点: private void WorkThread() { while (true) { this.label1.BeginInvoke((MethodInvoker)delegate { label1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); }); Thread.Sleep(500); } } 文章来源: https://blog

C# WinForm判断程序是否以管理员身份运行

匿名 (未验证) 提交于 2019-12-02 23:43:01
<?xml version="1.0" encoding="utf-8"?> <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app" /> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC 清单选项 如果要更改 Windows 用户帐户控制级别,请用以下节点之一替换 requestedExecutionLevel 节点。 <requestedExecutionLevel level="asInvoker" uiAccess="false" />

C# 应用程序配置文件操作

匿名 (未验证) 提交于 2019-12-02 23:42:01
为什么80%的码农都做不了架构师?>>> 应用程序配置文件,对于asp.net是 web.config对于WINFORM程序是 App.Config(ExeName.exe.config)。 配置文件,对于程序本身来说,就是基础和依据,其本质是一个xml文件,对于配置文件的操作,从.NET 2.0 开始,就非常方便了,提供了 System [.Web] .Configuration 这个管理功能的NameSpace,要使用它,需要添加对 System.configuration.dll的引用。 对于WINFORM程序,使用 System.Configuration.ConfigurationManager; 对于ASP.NET 程序, 使用 System.Web.Configuration.WebConfigurationManager; 我们以最常见的 AppSettings 小节来作为例子: 假设有如下的配置文件内容: <?xml version="1.0" encoding="utf-8" ?> <configuration> </configuration> 1. 读取值: System.Web.Configuration.WebConfigurationManager.AppSettings[“y”]; System.Configuration

Winform窗体验证登陆

匿名 (未验证) 提交于 2019-12-02 23:42:01
用户名,密码尽量不要在BLL,UIL判断,尽可能的在储存过程判断,通过返回的值不同,进行判断,这样提高安全性 SQL Server储存过程代码: BEGIN if(exists ( select User_ID from SYS_User where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) )) BEGIN if(exists ( select User_ID from SYS_User where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) and LTRIM(RTRIM(User_PassWord))=LTRIM(RTRIM(@User_PassWord)))) BEGIN if (exists(select User_ID from SYS_User where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) and LTRIM(RTRIM(User_PassWord))=LTRIM(RTRIM(@User_PassWord)) and UserType_ID=@UserType_ID)) BEGIN select User_Name,UserType_ID from SYS_User where LTRIM

winform控件之ListBox

匿名 (未验证) 提交于 2019-12-02 23:40:02
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mill_li/article/details/91412475 前面我们已经介绍了CheckedListBox,ListBox和它其实差不多,这里我们实现个拖拽的小功能,来学习ListBox控件 1.界面布局 界面布局这里很简单,就是一个ListBox 我们在代码里面为它添加元素,并重新事件来实现拖拽的功能 2.用法示例 想要实现拖拽功能,这里我们必须重新OnMouseDown,OnDragOver,OnDragDrop这三个事件,并且将AllowDrop属性设置为True,下面我们来看代码 using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace

WinForm 关闭登陆窗体,打开主窗体的实现

匿名 (未验证) 提交于 2019-12-02 23:36:01
首先在解决方案管理器(Program.cs)里的代码 static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form Login = new Login(); Login.ShowDialog();//显示登陆窗体 if (Login.DialogResult == DialogResult.OK) Application.Run(new Main());//判断登陆成功时主进程显示主窗口 else return; } 然后在登陆窗口(Login.cs)的登陆按钮(BTLogin)Click事件里 private void BTLogin_Click(object sender, EventArgs e) { if (TBUserName.Text == "www.520360.com" && TBPassWord.Text == "123") { this.DialogResult = DialogResult.OK;//关键:设置登陆成功状态 this.Close(); } else { MessageBox.Show("账号或密码错误,请重试"); } }

c# Winform PropertyGrid 实现下拉框 多选

匿名 (未验证) 提交于 2019-12-02 23:32:01
1 using PropertyGridHelpers.Controls; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Drawing.Design; 6 using System.Windows.Forms; 7 using System.Windows.Forms.Design; 8 9 namespace PropertyGridHelpers.UIEditors 10 { 11 12 public class FlagEnumUIEditor : UITypeEditor 13 { 14 private CheckedListBoxEx check; 15 16 public FlagEnumUIEditor() 17 { 18 check = new CheckedListBoxEx(); 19 check.BorderStyle = BorderStyle.None; 20 } 21 22 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 23 { 24 if

Winform 自定义窗体皮肤组件

匿名 (未验证) 提交于 2019-12-02 22:10:10
分享一个很久之前写的一个Winform换肤组件。 主要利用CBT钩子,NativeWindow来实现。可实现动态换皮肤插件修改窗体显示外观。 我们先定义一个自定义组件 using Skin; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace SkinControl { public class LySkinEngine : Component { #region 字段 public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam); private static HookProc _cbtHook; private static IntPtr Hook; private static string m_SkinName = ""; #endregion #region API ///