winform

WinForm 自绘控件实现选中,拖拽,平移,缩放效果

余生长醉 提交于 2020-01-11 17:01:29
参考文章: https://zhuanlan.zhihu.com/p/91880547 代码主体思想按照参考文章里的方法写的,不过参考文章是用Direct2D绘制的,我使用GDI+绘制的. 添加了层叠时选中最高层元素的代码 效果: 鼠标进入 鼠标选中 拖拽及按照层叠顺序绘制 平移 以鼠标位置为中心缩放 控件代码 1 Imports System.Drawing.Drawing2D 2 3 Public Class BOMAttributeList 4 Inherits Control 5 6 Private Shared SizeWidth = 100 7 Private Shared SizeHeight = 100 8 9 Public Property DataSource As List(Of String) 10 Get 11 Return (From item In DrawItems 12 Select item.Name).ToList 13 End Get 14 Set 15 DrawItems.Clear() 16 DrawItems.AddRange(From item In Value 17 Select New RenderingAttribute() With { 18 .Name = item, 19 .Locantion = New Point(

C# Winform DataGridView 公共分页实现

醉酒当歌 提交于 2020-01-11 13:46:40
Demo的界面 我利用事件委托事件,仿http://www.cnblogs.com/huyong/写的公共分页用户控件 C#代码 #region 版权信息 /*---------------------------------------------------------------------* // 项目 名称:《Winform分页控件》 // 文 件 名: Pager.cs // 描 述: 分页控件 // 作 者:kwon yan *----------------------------------------------------------------------*/ #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace HuishengFS.Controls { /**/ /// <summary> /// 申明委托 /// </summary> /// <param name="e"></param> ///

WinForm下窗体权限设计

杀马特。学长 韩版系。学妹 提交于 2020-01-10 23:25:13
WinForm 下窗体权限设计 一、 描述 管理员通过控制窗体中的某个控件的 Enable 和 visable 来达到应用程序的权限控制 二、 设计思路 (一) 读取控件 将 menustrip 菜单选项绑定到 treeview 中,根据菜单选项的名称跟窗体名称相等,去 遍历出窗体中的所有 form 、 tabctrol 、 button 、 toolstripbutton 、等, 结果如下 (二) 保存控件 将 treeview 中显示 的控件 id 跟控件名称一起存入数据库,同时设置控件的可用状态,默认都可用。 (三) 将权限应用到具体窗体中 三、 数据库的设计 四、 关键部位的实现 1) 读取控件的难点 怎么样遍历到应用程序的所有窗体,这里使用了 net 的反射() 具体方法如下 1) TraverseForm( string Str) public bool TraverseForm( string Str) { Assembly a = Assembly .LoadFile( Application .ExecutablePath); //.net 中的反射 Type [] types = a.GetTypes(); foreach ( Type t in types) { if (t.BaseType.Name == "Form" || t.BaseType.Name

WinForm(C#)复制文件夹

我与影子孤独终老i 提交于 2020-01-10 05:09:40
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace CopyDirectory { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { CopyDirectory("c:\\downloads","d:\\"); } /// <summary> /// 拷贝文件夹 ///By Wang Hw www.pegete.com.cn /// </summary> /// <param name="srcdir"></param> /// <param name="desdir"></param> private void CopyDirectory(string srcdir, string desdir) {

【c#】winform 上传图片

≯℡__Kan透↙ 提交于 2020-01-10 03:47:45
1、拖拽上传图片 1.1、后台代码中修改窗体属性,添加 AllowDrop = true 1.2、给窗体添加拖拽事件,在事件列表找到拖拽 双击即可: 在 DragDrop 生成的方法中添加代码如下: private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } } 在 DragEnter 方法中添加代码如下: private void Form1_DragEnter(object sender, DragEventArgs e) { //判断 string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; string file = files[0]; if (!file.ToLower().EndsWith(".png") && !file.ToLower().EndsWith(".jpg")) { MessageBox.Show("需要图片文件!"); return; } /

C#中使用多线程访问winform中控件

流过昼夜 提交于 2020-01-09 06:42:43
我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。   首先来看传统方法:   public partial class Form1 : Form   {   public Form1()   {   InitializeComponent();   }   private void Form1_Load(object sender, EventArgs e)   {   Thread thread = new Thread(ThreadFuntion);   thread.IsBackground = true;   thread.Start();   }   private void ThreadFuntion()   {   while (true)   {   this.textBox1.Text = DateTime.Now.ToString();   Thread.Sleep(1000);   }   }   }   运行这段代码,我们会看到系统抛出一个异常:Cross-thread operation not valid:Control 'textBox1' accessed from a thread other than the thread it was

WinForm背景图片及图片位置

拈花ヽ惹草 提交于 2020-01-09 02:31:39
设置背景图片 :BackgroundImage属性选择对应的图片就可以了。 背景图片随窗体的变化而变化 :BackgroundImageLayout属性值设置为Stretch。 窗体放置图片 :PictureBox控件; PictureBox控件的背景为透明: BackColor的值为Transparent。 让图片的大小适合你的PictureBox控件的大小 :PictureBox的SizeMode属性值设置为Zoom。 控件的位置和大小随窗体大小的变化而变化 : 设计视图时将控件放置再你需要的位置,Dock属性为None, Anchor属性为None, 则该控件的位置一直处于窗体的相对位置上。 来源: https://www.cnblogs.com/bkyqtr/p/11357881.html

[C#] winform中的DataGridView的列宽设置(自动调整列宽)

纵饮孤独 提交于 2020-01-08 23:33:42
找了很多都说DataGridView有一个属性AutoSizeColumnMode,他有很多枚举值: 1、AllCells 调整列宽,以适合该列中的所有单元格的内容,包括标题单元格。 2、AllCellsExceptHeader 调整列宽,以适合该列中的所有单元格的内容,不包括标题单元格。 3、ColumnHeader 调整列宽,以适合列标题单元格的内容。 4、DisplayedCells 调整列宽,以适合当前屏幕上显示的行的列中的所有单元格的内容,包括标题单元格。 5、DisplayedCellsExceptHeader 调整列宽,以适合当前屏幕上显示的行的列中的所有单元格的内容,不包括标题单元格。 6、Fill 调整列宽,使所有列的宽度正好填充控件的显示区域,只需要水平滚动保证列宽在DataGridViewColumn.MinimumWidth 属性值以上。相对列宽由相对 DataGridViewColumn.FillWeight 属性值决定。 7、None 列宽不会自动调整。 8、NotSet 列的大小调整行为从 DataGridView.AutoSizeColumnsMode 属性继承。 使用方法举例: this . IssuesDataGridView . AutoSizeColumnsMode = System . Windows . Forms .

winform INI文件操作辅助类

断了今生、忘了曾经 提交于 2020-01-08 01:21:58
using System; using System.Runtime.InteropServices; using System.Text; namespace connectCMCC.Utils { /// <summary> /// INI文件操作辅助类 /// </summary> public class IniFileUtil { public string path; /// <summary> /// 传入INI文件路径构造对象 /// </summary> /// <param name="iniPath">INI文件路径</param> public IniFileUtil(string iniPath) { path = iniPath; } [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder

.NET中Winform窗体应用程序的几个关于坐标的知识点

别说谁变了你拦得住时间么 提交于 2020-01-07 05:20:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文是我对一些Winform下常用的坐标知识点做一个总结。 一、关于坐标 在计算机中,左上角是原点,从左上角向右为X轴的正方向,从左上角向下为Y轴的正方向。坐标在.NET中通过Point结构表示,该结构有两个属性X与Y用于指定横纵坐标,并重载了+、-、+=、-=等运算符。 二、几个常用坐标 1、鼠标在窗体(Form)中的相对坐标 在Form的MouseClick事件中,可以从MouseEventArgs类型的参数e中获取到鼠标在窗体中的相对坐标。 2、鼠标在屏幕上的绝对坐标 获取鼠标在电脑显示器屏幕上的坐标,可以使用Cursor.Position获取。 3、获取窗体(Form)四个角的坐标 窗体四个角的坐标可以通过窗体的上(Top)、下(Bottom)、左(Left)、右(Right)四边的横(纵)坐标计算得出。 4、某控件左上角在窗体中的相对坐标 控件都具有Location属性,该属性内存储了这个控件左上角的坐标 5、屏幕上坐标与工作区中坐标的换算 这里说的工作区中坐标,即以当前控件(可以为Form,也可以为其他控件)左上角为原点的坐标系。Control类中的PointToClient方法,可以将屏幕上的坐标换算为窗体(或某控件)内的相对坐标 可以参考MSDN文档: https://msdn