winform相关
winform高分辨率缩放
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
winform在管理员运行时Drag
FileDropHandler.cs
using System;using System.ComponentModel;using System.Runtime.InteropServices;using System.Text;using System.Windows.Forms;namespace PicCommon{public sealed class FileDropHandler : IMessageFilter, IDisposable{#region native members[DllImport("user32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)][return: MarshalAs(UnmanagedType.Bool)]private static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, uint message, ChangeFilterAction action, in ChangeFilterStruct pChangeFilterStruct);[DllImport("shell32.dll", SetLastError = false, CallingConvention = CallingConvention.Winapi)]private static extern void DragAcceptFiles(IntPtr hWnd, bool fAccept);[DllImport("shell32.dll", SetLastError = false, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]private static extern uint DragQueryFile(IntPtr hWnd, uint iFile, StringBuilder lpszFile, int cch);[DllImport("shell32.dll", SetLastError = false, CallingConvention = CallingConvention.Winapi)]private static extern void DragFinish(IntPtr hDrop);[StructLayout(LayoutKind.Sequential)]private struct ChangeFilterStruct{public uint CbSize;public ChangeFilterStatu ExtStatus;}private enum ChangeFilterAction : uint{MSGFLT_RESET,MSGFLT_ALLOW,MSGFLT_DISALLOW}private enum ChangeFilterStatu : uint{MSGFLTINFO_NONE,MSGFLTINFO_ALREADYALLOWED_FORWND,MSGFLTINFO_ALREADYDISALLOWED_FORWND,MSGFLTINFO_ALLOWED_HIGHER}private const uint WM_COPYGLOBALDATA = 0x0049;private const uint WM_COPYDATA = 0x004A;private const uint WM_DROPFILES = 0x0233;#endregionprivate const uint GetIndexCount = 0xFFFFFFFFU;private Control _ContainerControl;private readonly bool _DisposeControl;public Control ContainerControl { get; }public FileDropHandler(Control containerControl) : this(containerControl, false) { }public FileDropHandler(Control containerControl, bool releaseControl){_ContainerControl = containerControl ?? throw new ArgumentNullException("control", "control is null.");if (containerControl.IsDisposed) throw new ObjectDisposedException("control");_DisposeControl = releaseControl;var status = new ChangeFilterStruct() { CbSize = 8 };if (!ChangeWindowMessageFilterEx(containerControl.Handle, WM_DROPFILES, ChangeFilterAction.MSGFLT_ALLOW, in status)) throw new Win32Exception(Marshal.GetLastWin32Error());if (!ChangeWindowMessageFilterEx(containerControl.Handle, WM_COPYGLOBALDATA, ChangeFilterAction.MSGFLT_ALLOW, in status)) throw new Win32Exception(Marshal.GetLastWin32Error());if (!ChangeWindowMessageFilterEx(containerControl.Handle, WM_COPYDATA, ChangeFilterAction.MSGFLT_ALLOW, in status)) throw new Win32Exception(Marshal.GetLastWin32Error());DragAcceptFiles(containerControl.Handle, true);Application.AddMessageFilter(this);}public bool PreFilterMessage(ref Message m){if (_ContainerControl == null || _ContainerControl.IsDisposed) return false;if (_ContainerControl.AllowDrop) return _ContainerControl.AllowDrop = false;if (m.Msg == WM_DROPFILES){var handle = m.WParam;var fileCount = DragQueryFile(handle, GetIndexCount, null, 0);var fileNames = new string[fileCount];var sb = new StringBuilder(262);var charLength = sb.Capacity;for (uint i = 0; i < fileCount; i++){if (DragQueryFile(handle, i, sb, charLength) > 0) fileNames[i] = sb.ToString();}DragFinish(handle);_ContainerControl.AllowDrop = true;_ContainerControl.DoDragDrop(fileNames, DragDropEffects.All);_ContainerControl.AllowDrop = false;return true;}return false;}public void Dispose(){if (_ContainerControl == null){if (_DisposeControl && !_ContainerControl.IsDisposed) _ContainerControl.Dispose();Application.RemoveMessageFilter(this);_ContainerControl = null;}}}}
winform中使用.cs
private FileDropHandler fileDrop;private void MainForm_DragEnter(object sender, DragEventArgs e){var paths = e.Data.GetData(typeof(string[])) as string[];GetFileDetail(paths[0].ToString());}private void MainForm_Load(object sender, EventArgs e){PicDetail.RowHeadersVisible = false;fileDrop = new FileDropHandler(this); //初始化}
DataGridView
隐藏行第一列空白
dataGridView1.RowHeadersVisible = false;
属性中,设置标题不换行居中。
DataGridViewCellStyle
控制台启动Winform
有时候想在控制台输出log,所以可以右键点击winform,选择属性
在 应用程序中的输出类型选择 控制台应用程序 就可以了。
winform工具箱
主窗体.cs
using System;using System.Drawing;using System.Windows.Forms;using GadgetCollectionFactory;using GadgetCollectionOperation;using System.Configuration;namespace GadgetCollection{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){//读取配置文件//string[] config = File.ReadAllLines("Config.txt", Encoding.UTF8);string[] config = ConfigurationManager.AppSettings.AllKeys;//遍历配置文件,有多tool就生成多少按钮。foreach (string item in config){//有几条数据,就创建几个按钮Button btn = new Button();btn.Size = new Size(197, 42);btn.BackColor = Color.AliceBlue;btn.Text = ConfigurationManager.AppSettings.Get(item);//flowLayoutPanel1.AutoScroll = true;flowLayoutPanel1.Controls.Add(btn);btn.Click += button1_Click;}}private void button1_Click(object sender, EventArgs e){Button btn = sender as Button;//获得简单工厂提供的父类对象OperateTools oper = Factory.GetOperation(btn.Text);//判断对象是否为空if (oper == null){return;}//执行方法。oper.OperateSelectedTool();}/// <summary>/// 搜索按钮点击的时候/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void BtnSearch_Click(object sender, EventArgs e){if (string.IsNullOrEmpty(TxtSearch.Text)){MessageBox.Show("请输入查询内容", "错误提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}//把flowLayoutPanel1的Control对象集合传递进去FindControl(flowLayoutPanel1.Controls);}/// <summary>/// 把flowLayoutPanel1的Control对象集合传进去/// </summary>/// <param name="controlCollection">Control对象集合Control.ControlCollection</param>void FindControl(Control.ControlCollection controlCollection){//遍历控件集合foreach (Control control in controlCollection){//如果控件是按钮if (control is Button){//强转Button btn = (Button)control;//比较搜索的字符和按钮字符是否相同if (btn.Text.ToLower().Contains(TxtSearch.Text.ToLower())){//相同就变颜色和聚焦btn.BackColor = Color.Coral;btn.Focus();//聚焦}}}}/// <summary>/// 点击搜索输入框的时候重置颜色/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void TxtSearch_MouseClick(object sender, MouseEventArgs e){TxtSearch.Text = "";foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls){if (control is System.Windows.Forms.Button){System.Windows.Forms.Button btn = (System.Windows.Forms.Button)control;btn.BackColor = Color.AliceBlue;}}}}}
工厂类.cs
using System;
using System.IO;
using System.Reflection;
using GadgetCollectionOperation;
namespace GadgetCollectionFactory
{
public class Factory
 {
public static OperateTools GetOperation(string SelectedToolName)
 {
 OperateTools toolOperator = null;
//动态的获得程序集
string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
//获得dllPath路径下所有程序集文件的全路径
string[] filePath = Directory.GetFiles(dllPath);
//遍历filePath 加载所有的程序集文件
foreach (string item in filePath)
 {
 Assembly ass = Assembly.LoadFile(item);
//获得程序集中所有的公开数据类型
 Type[] types = ass.GetExportedTypes();
foreach (Type tt in types)
 {
//判断当前数据类型是不是自己需要的 是子类吗 是抽象类吗 
if (tt.IsSubclassOf(typeof(OperateTools)) && !tt.IsAbstract)
 {
//创建子类对象,赋值给oper
object o = Activator.CreateInstance(tt);
 toolOperator = (OperateTools)o;
//判断传进来的类型 如果是的话 就返回
if (SelectedToolName == toolOperator.toolName)
 {
return toolOperator;
 }
else//不是就break
 {
 toolOperator = null;
break;
 }
 }
 }
 }
return null;
 }
 }
}
抽象父类.cs
namespace GadgetCollectionOperation
{
public abstract class OperateTools
 {
//小工具的名称
public abstract string toolName { get; }
//开启选中的工具
public abstract void OperateSelectedTool();
 }
}
工具类示例.cs
using System;
using System.Diagnostics;
using GadgetCollectionOperation;
namespace ToolW3SchoolAPI
{
public class W3SchoolAPI : OperateTools
 {
public override string toolName
 {
get { return "W3SchoolAPI"; }//修改toolName
 }
public override void OperateSelectedTool()
 {
//修改启动文件的路径以及名称,在ToolFile文件夹内新建文件夹,然后把路径添加
 Process proc = Process.Start(AppDomain.CurrentDomain.BaseDirectory + "ToolFile/w3schoo.CHM");
 }
 }
}
应用程序图标设置
右键点击源winform程序。点击属性。
在这里可以修改默认的图标。
切换Debug&Release模式
JavaScript
相关文档
简介
是弱类型语言 :不需要指定变量的类型
大小写敏感
分号结尾
注释(单行// 多行 / /)
字符串推荐使用单引号,也可以使用双引号
双等号==判断值是否相等
三等号===先判断类型是否相同,再判断值是否相等
JavaScript不支持方法重载
后声明的函数会覆盖先声明的函数。
可变参数
//可变参数
function sum(a) {
//使用arguments获取所有参数,是一个数组
//alert(arguments.length);//返回数组的元素个数
var sum1 = 0;
for (var i = 0; i < arguments.length; i++) {
                sum1 += arguments[i];
            }
            alert(sum1);
        }
//调用
        sum(1, 2, 3,4,5,6);
数据类型
boolean布尔
number数字
string字符串
Undefined未定义
Null空对象
Object对象类型
Undefined类型、Null类型都是只有一个值的数据类型,值分别为undefined与null
查看变量的类型typeof 变量名或typeof(变量名),返回变量类型的字符串
类型转换:类型名(变量名)或parse*()
匿名函数
匿名函数
不需要定义方法名,直接写参数列表与方法体
方式一:function (参数){...return ...};
可以将方法赋值给一个变量,这个变量表示一个方法
方式二:(function(n1,n2){...})(1,2);
定义的同时完成调用
方式三:new Function("n1","n2","return n1+n2");
赋值给一个变量完成调用
最常使用:方式一
//典型应用:为事件绑定处理函数,传递回调函数
//根据id获取页面元素,为它绑定单击事件
            document.getElementById('btnShow').onclick = function() {
                alert(123);
            };
闭包
<script>
//定义一个函数show
function show(name) {
//返回一个函数
return function () {
//输出name的值
                alert(name);
            };
        }
//运行show函数,将返回值赋给f1
//因为返回值是函数,所以f1现在指向一个函数
var f1 = show('a');
//通过f1可以调用匿名函数执行
        f1();
//闭包:支持在函数内部调用函数之前声明过的变量
//作用域链:变量的作用域在当前函数中,及当前函数内部定义的函数中,形成了一个链条
//建议:避免闭包,每次在用一个变量时,都要先声明再使用
</script>
类
<script>
//为类增加成员
function Person(name) {
this.Name = name;//在类内部声明一个属性Name,初始化为name值
this.say = function () {
 alert(this.Name);
 };
 }
//使用构造方法创建对象
var p1 = new Person('zhh');
 p1.say();//调用 方法
//alert(typeof (p1));//object
//alert(typeof (Person('zhh')));//因为Person作为函数时,没有返回值,所以是undefined
//alert(typeof(Person));//Person就是一个函数,类型是function
</script>
//定义类的第二种方法
<script>
function Person() {
 }
//为对象增加成员
//var p1 = new Person();
//p1.Name = "zhh";//为对象p1新建了一个属性Name
//p1.say = function() {
// alert(p1.Name);
//};
//p1.say();
//新建出来的对象,是没有Name属性的,因为类Person中没有Name属性
//var p2 = new Person();
//alert(p2.Name);
</script>
原型
原型:就是对象的类型
<script>
function Person() {
this.Age = 100;
        }
var p1 = new Person();
//p1.Title = 'abc';
//访问原型
        p1.__proto__.Title = 'abc';//为原型注释数据成员
//Person.prototype.Title = 'abc';//功能同上面的代码
var p2 = new Person();
        alert(p2.Title);
</script>
数组
<script>
//使用[]定义数组
var array1 = [123, 'abc'];
        array1[0];
//键值对{键:值,...}
var array2 = {            
name: 'zhh',
age: 18,
gender:'你猜'
        };
//alert(array2['name']);//将array2认为是集合,通过键访问值
//alert(array2.name);//将array2认为是json,通过属性访问值
//定义json数组
var temp = [{
title: 'zhh',
age:18
        }, {
title: '牛头',
age:20
        }, {
title: '马面',
age:22
        }];
//输出每个对象的title值
for (var index in temp) {//temp是数组,所以index是索引
            alert(temp[index].title);
        }
</script>
HTML-DOM
HTML DOM 方法
| 方法 | 描述 | 
|---|---|
| getElementById() | 返回带有指定 ID 的元素。 | 
| getElementsByTagName() | 返回包含带有指定标签名称的所有元素的节点列表(集合/节点数组)。 | 
| getElementsByClassName() | 返回包含带有指定类名的所有元素的节点列表。 | 
| appendChild() | 把新的子节点添加到指定节点。 | 
| removeChild() | 删除子节点。 | 
| replaceChild() | 替换子节点。 | 
| insertBefore() | 在指定的子节点前面插入新的子节点。 | 
| createAttribute() | 创建属性节点。 | 
| createElement() | 创建元素节点。 | 
| createTextNode() | 创建文本节点。 | 
| getAttribute() | 返回指定的属性值。 | 
| setAttribute() | 把指定属性设置或修改为指定的值。 | 
C#小知识
拆分数组
使用linq。
firstArray = array.Take(array.Length / 2).ToArray();
secondArray = array.Skip(array.Length / 2).ToArray();
                    
