### 2021-07-01更新
------ #### ryControlsV4 V3.0.2107.0101 - *.[新增]新增Sheng.Winform.Controls部分控件。 #### RyWeb V3.0.2107.0101 - *.[新增]QuickWeb新增引用页设置。 #### MyDbV4 V3.0.2107.0101 - *.[新增]支持忽略大小写的替换功能。
This commit is contained in:
parent
870234f406
commit
8b41f58f5c
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -982,6 +982,16 @@
|
||||||
<param name="replacement"></param>
|
<param name="replacement"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.Strings.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换功能
|
||||||
|
</summary>
|
||||||
|
<param name="str"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取匹配的内容
|
获取匹配的内容
|
||||||
|
|
@ -1065,6 +1075,16 @@
|
||||||
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.VarExtension.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换文本功能
|
||||||
|
</summary>
|
||||||
|
<param name="original"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取符合要求的第一个结果
|
获取符合要求的第一个结果
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -472,6 +472,11 @@
|
||||||
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RyWeb.QuickWeb.Referer">
|
||||||
|
<summary>
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:RyWeb.QuickWeb.Timeout">
|
<member name="P:RyWeb.QuickWeb.Timeout">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[Money_Op]
|
[Money_Op]
|
||||||
hwnd=263848
|
hwnd=1707890
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<root>
|
<root>
|
||||||
<list id="LastUpdateTime" Value="2021/6/13 23:15:28" />
|
<list id="LastUpdateTime" Value="2021/6/15 16:23:02" />
|
||||||
<list id="UpdateAfterTime" Value="0" />
|
<list id="UpdateAfterTime" Value="0" />
|
||||||
</root>
|
</root>
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
|
@ -982,6 +982,16 @@
|
||||||
<param name="replacement"></param>
|
<param name="replacement"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.Strings.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换功能
|
||||||
|
</summary>
|
||||||
|
<param name="str"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取匹配的内容
|
获取匹配的内容
|
||||||
|
|
@ -1065,6 +1075,16 @@
|
||||||
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.VarExtension.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换文本功能
|
||||||
|
</summary>
|
||||||
|
<param name="original"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取符合要求的第一个结果
|
获取符合要求的第一个结果
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -472,6 +472,11 @@
|
||||||
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RyWeb.QuickWeb.Referer">
|
||||||
|
<summary>
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:RyWeb.QuickWeb.Timeout">
|
<member name="P:RyWeb.QuickWeb.Timeout">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -982,6 +982,16 @@
|
||||||
<param name="replacement"></param>
|
<param name="replacement"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.Strings.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换功能
|
||||||
|
</summary>
|
||||||
|
<param name="str"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取匹配的内容
|
获取匹配的内容
|
||||||
|
|
@ -1065,6 +1075,16 @@
|
||||||
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.VarExtension.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换文本功能
|
||||||
|
</summary>
|
||||||
|
<param name="original"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取符合要求的第一个结果
|
获取符合要求的第一个结果
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -472,6 +472,11 @@
|
||||||
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RyWeb.QuickWeb.Referer">
|
||||||
|
<summary>
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:RyWeb.QuickWeb.Timeout">
|
<member name="P:RyWeb.QuickWeb.Timeout">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
|
@ -982,6 +982,16 @@
|
||||||
<param name="replacement"></param>
|
<param name="replacement"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.Strings.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换功能
|
||||||
|
</summary>
|
||||||
|
<param name="str"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.Strings.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取匹配的内容
|
获取匹配的内容
|
||||||
|
|
@ -1065,6 +1075,16 @@
|
||||||
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
<param name="isLike">是否是通配符表达式,不是,则普通替换,忽略大小写,是,则启用通配符替换</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:ryCommon.VarExtension.Replace(System.String,System.String,System.String,System.Boolean)">
|
||||||
|
<summary>
|
||||||
|
支持忽略大小写的替换文本功能
|
||||||
|
</summary>
|
||||||
|
<param name="original"></param>
|
||||||
|
<param name="oldValue"></param>
|
||||||
|
<param name="newValue"></param>
|
||||||
|
<param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
<member name="M:ryCommon.VarExtension.GetMatchStr(System.String,System.String,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
获取符合要求的第一个结果
|
获取符合要求的第一个结果
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -472,6 +472,11 @@
|
||||||
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RyWeb.QuickWeb.Referer">
|
||||||
|
<summary>
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:RyWeb.QuickWeb.Timeout">
|
<member name="P:RyWeb.QuickWeb.Timeout">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
19
CHANGELOG.md
19
CHANGELOG.md
|
|
@ -1,4 +1,17 @@
|
||||||
### 2021-06-13更新
|
### 2021-07-01更新
|
||||||
|
------
|
||||||
|
#### ryControlsV4 V3.0.2107.0101
|
||||||
|
- *.[新增]新增Sheng.Winform.Controls部分控件。
|
||||||
|
|
||||||
|
#### RyWeb V3.0.2107.0101
|
||||||
|
|
||||||
|
- *.[新增]QuickWeb新增引用页设置。
|
||||||
|
|
||||||
|
#### MyDbV4 V3.0.2107.0101
|
||||||
|
|
||||||
|
- *.[新增]支持忽略大小写的替换功能。
|
||||||
|
|
||||||
|
### 2021-06-13更新
|
||||||
------
|
------
|
||||||
#### ryControls V2.1.2106.1301
|
#### ryControls V2.1.2106.1301
|
||||||
|
|
||||||
|
|
@ -17,6 +30,10 @@
|
||||||
#### ryControls V2.1.2104.0201
|
#### ryControls V2.1.2104.0201
|
||||||
- *.[修复]修复在win7上Gdu.WinformUI会报错的BUG。
|
- *.[修复]修复在win7上Gdu.WinformUI会报错的BUG。
|
||||||
|
|
||||||
|
ryControls V2.1.2104.0201
|
||||||
|
|
||||||
|
- *.[修复]修复在win7上Gdu.WinformUI会报错的BUG。
|
||||||
|
|
||||||
### 2021-03-13更新
|
### 2021-03-13更新
|
||||||
------
|
------
|
||||||
#### ryControls V2.1.2103.1301
|
#### ryControls V2.1.2103.1301
|
||||||
|
|
|
||||||
Binary file not shown.
2
Source/Itrycn_Project/DbOp/FrmAdd.Designer.cs
generated
2
Source/Itrycn_Project/DbOp/FrmAdd.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
partial class FrmAdd
|
partial class FrmAdd
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
public partial class FrmAdd : Form
|
public partial class FrmAdd : Form
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
public partial class FrmView : Form
|
public partial class FrmView : Form
|
||||||
{
|
{
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project/DbOp/frmView.Designer.cs
generated
2
Source/Itrycn_Project/DbOp/frmView.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
partial class FrmView
|
partial class FrmView
|
||||||
{
|
{
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project/FrmAbout.Designer.cs
generated
2
Source/Itrycn_Project/FrmAbout.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
partial class FrmAbout
|
partial class FrmAbout
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
public partial class FrmAbout : Form
|
public partial class FrmAbout : Form
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using static ryCommonDb.DataProvider;
|
using static ryCommonDb.DataProvider;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 配置类(本系统基于乘黄V1架构)
|
/// 配置类(本系统基于乘黄V1架构)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Itrycn_Project.Properties {
|
namespace Itrycn_Project2.Properties {
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Itrycn_Project.Properties
|
namespace Itrycn_Project2.Properties
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Itrycn_Project;
|
using Itrycn_Project2;
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using RyHardWare;
|
using RyHardWare;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project/frmSetting.Designer.cs
generated
2
Source/Itrycn_Project/frmSetting.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
partial class FrmSetting
|
partial class FrmSetting
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
public partial class FrmSetting : Form
|
public partial class FrmSetting : Form
|
||||||
{
|
{
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project/frmmain.Designer.cs
generated
2
Source/Itrycn_Project/frmmain.Designer.cs
generated
|
|
@ -113,7 +113,7 @@
|
||||||
// picExpand
|
// picExpand
|
||||||
//
|
//
|
||||||
this.picExpand.Cursor = System.Windows.Forms.Cursors.Hand;
|
this.picExpand.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||||
this.picExpand.Image = global::Itrycn_Project.Properties.Resources.closetree;
|
this.picExpand.Image = global::Itrycn_Project2.Properties.Resources.closetree;
|
||||||
this.picExpand.Location = new System.Drawing.Point(187, 247);
|
this.picExpand.Location = new System.Drawing.Point(187, 247);
|
||||||
this.picExpand.Name = "picExpand";
|
this.picExpand.Name = "picExpand";
|
||||||
this.picExpand.Size = new System.Drawing.Size(10, 49);
|
this.picExpand.Size = new System.Drawing.Size(10, 49);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Itrycn_Project;
|
using Itrycn_Project2;
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -179,7 +179,7 @@ namespace Itrycn
|
||||||
{
|
{
|
||||||
if (isExpand)
|
if (isExpand)
|
||||||
{
|
{
|
||||||
picExpand.Image = Itrycn_Project.Properties.Resources.opentree;
|
picExpand.Image = Itrycn_Project2.Properties.Resources.opentree;
|
||||||
toolTip1.SetToolTip(picExpand,"展开列表");
|
toolTip1.SetToolTip(picExpand,"展开列表");
|
||||||
treeView1.Visible = false;
|
treeView1.Visible = false;
|
||||||
picExpand.Left = 0;
|
picExpand.Left = 0;
|
||||||
|
|
@ -187,7 +187,7 @@ namespace Itrycn
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
picExpand.Image = Itrycn_Project.Properties.Resources.closetree;
|
picExpand.Image = Itrycn_Project2.Properties.Resources.closetree;
|
||||||
toolTip1.SetToolTip(picExpand, "关闭列表");
|
toolTip1.SetToolTip(picExpand, "关闭列表");
|
||||||
treeView1.Visible = true;
|
treeView1.Visible = true;
|
||||||
picExpand.Left = treeView1.Left + treeView1.Width + 1;
|
picExpand.Left = treeView1.Left + treeView1.Width + 1;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using static ryCommonDb.DataProvider;
|
using static ryCommonDb.DataProvider;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
public static class Itrycn_Db
|
public static class Itrycn_Db
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 配置类,保存在文件中的配置信息(本系统基于乘黄V2架构)
|
/// 配置类,保存在文件中的配置信息(本系统基于乘黄V2架构)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 运行期间存储的变量,不会存储在文件中,只存储内存中.每次启动软件会初始化变量。
|
/// 运行期间存储的变量,不会存储在文件中,只存储内存中.每次启动软件会初始化变量。
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project2/DbOp/FrmAdd.Designer.cs
generated
2
Source/Itrycn_Project2/DbOp/FrmAdd.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
partial class FrmAdd
|
partial class FrmAdd
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
public partial class FrmAdd : RySkins.SKinForm
|
public partial class FrmAdd : RySkins.SKinForm
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,182 +1,204 @@
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using ryCommonDb;
|
using ryCommonDb;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
public partial class FrmView : RySkins.SKinForm
|
public partial class FrmView : RySkins.SKinForm
|
||||||
{
|
{
|
||||||
string orderSQL = "order by addTime desc";
|
string orderSQL = "order by addTime desc";
|
||||||
string tableName = "MainTable1";
|
string tableName = "MainTable1";
|
||||||
string titleName = "数据";
|
string titleName = "数据";
|
||||||
public FrmView()
|
public FrmView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
OlvName.AspectGetter = delegate (object x) { return ((ViewInfo)x).Name; };
|
OlvName.AspectGetter = delegate (object x) { return ((ViewInfo)x).Name; };
|
||||||
OlvAddTime.AspectGetter = delegate (object x) { return ((ViewInfo)x).AddTimeStr; };
|
OlvAddTime.AspectGetter = delegate (object x) { return ((ViewInfo)x).AddTimeStr; };
|
||||||
}
|
}
|
||||||
#region 需要修改的内容
|
#region 需要修改的内容
|
||||||
private void RySearch1_OnSearch(object sender, EventArgs e)
|
private void RySearch1_OnSearch(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//需要修改此处
|
//需要修改此处
|
||||||
//LoadDb("(" + TableProject.name + " like @SearchText or " + TableProject.des + " like @SearchText)");
|
//LoadDb("(" + TableProject.name + " like @SearchText or " + TableProject.des + " like @SearchText)");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CtlMyPage1_OnPageChange(object sender, EventArgs e)
|
private void CtlMyPage1_OnPageChange(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
#region 重新载入数据
|
#region 重新载入数据
|
||||||
LvCbResult.ClearObjects();
|
LvCbResult.ClearObjects();
|
||||||
DataProvider mydb = new DataProvider();
|
DataProvider mydb = new DataProvider();
|
||||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||||
List<ViewInfo> list = new List<ViewInfo>();
|
List<ViewInfo> list = new List<ViewInfo>();
|
||||||
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
||||||
{
|
{
|
||||||
DataSet ds = db.ReadData(ctlMyPage1.GetSQLText, ctlMyPage1.T_Parameters);
|
DataSet ds = db.ReadData(ctlMyPage1.GetSQLText, ctlMyPage1.T_Parameters);
|
||||||
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
||||||
{
|
{
|
||||||
DataRow row = ds.Tables[0].Rows[i];
|
DataRow row = ds.Tables[0].Rows[i];
|
||||||
list.Add(new ViewInfo()
|
list.Add(new ViewInfo()
|
||||||
{
|
{
|
||||||
Id=row["id"].ToInt(),
|
Id=row["id"].ToInt(),
|
||||||
Name = row["Name"].ToString(),
|
Name = row["Name"].ToString(),
|
||||||
AddTime = row["AddTime"].ToDateTime()
|
AddTime = row["AddTime"].ToDateTime()
|
||||||
}) ;
|
}) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.Free();
|
db.Free();
|
||||||
LvCbResult.AddObjects(list);
|
LvCbResult.AddObjects(list);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
private void GetRow(int id, int index)
|
private void GetRow(int id, int index)
|
||||||
{
|
|
||||||
#region 重新载入数据
|
|
||||||
DataProvider mydb = new DataProvider();
|
|
||||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
||||||
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
|
||||||
{
|
|
||||||
DataSet ds = db.ReadData("select * from " + tableName + " where id=" + id);
|
|
||||||
if (mydb.HaveData(ds))
|
|
||||||
{
|
|
||||||
DataRow row = ds.Tables[0].Rows[0];
|
|
||||||
var item=(ViewInfo) LvCbResult.GetModelObject(index);
|
|
||||||
item.Name = row["Name"].ToString();
|
|
||||||
//添加剩余的项目
|
|
||||||
//添加完毕
|
|
||||||
LvCbResult.UpdateObject(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.Free();
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
public void LoadDb(string whereSQL)
|
|
||||||
{
|
|
||||||
string _whereSQL = whereSQL;
|
|
||||||
DataProvider mydb = new DataProvider();
|
|
||||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
||||||
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
|
||||||
{
|
|
||||||
#region 重新载入数据
|
|
||||||
db.AddParameter("SearchText", "%" + rySearch1.Text + "%");
|
|
||||||
ctlMyPage1.RecordCount = db.GetCount(tableName, _whereSQL);
|
|
||||||
ctlMyPage1.T_Parameters = db.GetParameter();
|
|
||||||
ctlMyPage1.SQLText= db.GetPageSQL(tableName, _whereSQL, orderSQL);
|
|
||||||
ctlMyPage1.SQLText2 = db.GetPageSQL2(tableName, _whereSQL, orderSQL);
|
|
||||||
ctlMyPage1.GotoPageIndex(1);
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
db.Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BtnAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
FrmAdd frm = new FrmAdd()
|
|
||||||
{
|
|
||||||
Text = "添加"+ titleName,
|
|
||||||
Icon = Icon,
|
|
||||||
isAdd = 1
|
|
||||||
};
|
|
||||||
frm.mr = new ModalForm(this, frm);
|
|
||||||
frm.mr.OnDialogResult += new ModalForm.DialogResultHandler((object t, DialogResult dg) => {
|
|
||||||
if (dg == DialogResult.OK)
|
|
||||||
{
|
|
||||||
rySearch1.PerformClick();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
frm.mr.ShowModal();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BtnEdit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (LvCbResult.SelectedObject == null) { return; }
|
|
||||||
var item = (ViewInfo)LvCbResult.SelectedObject;
|
|
||||||
var selectId = item.Id;
|
|
||||||
FrmAdd frm = new FrmAdd()
|
|
||||||
{
|
|
||||||
Text = "修改"+ titleName,
|
|
||||||
Icon = Icon,
|
|
||||||
isAdd = 0
|
|
||||||
};
|
|
||||||
frm.GetInfo(selectId.ToString());
|
|
||||||
frm.mr = new ModalForm(this, frm);
|
|
||||||
frm.mr.OnDialogResult += new ModalForm.DialogResultHandler((object t, DialogResult dg) => {
|
|
||||||
if (dg == DialogResult.OK)
|
|
||||||
{
|
|
||||||
GetRow(selectId, LvCbResult.SelectedIndex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
frm.mr.ShowModal();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BtnDel_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
if (LvCbResult.SelectedObject == null) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
#region 重新载入数据
|
||||||
var item = (ViewInfo)LvCbResult.SelectedObject;
|
DataProvider mydb = new DataProvider();
|
||||||
var selectId = item.Id;
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||||
if (RySkins.Msg.ShowMsg("确定要删除该项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
|
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
||||||
{
|
{
|
||||||
return;
|
DataSet ds = db.ReadData("select * from " + tableName + " where id=" + id);
|
||||||
}
|
if (mydb.HaveData(ds))
|
||||||
//DataProvider mydb = new DataProvider();
|
{
|
||||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
DataRow row = ds.Tables[0].Rows[0];
|
||||||
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
var item=(ViewInfo) LvCbResult.GetModelObject(index);
|
||||||
{
|
item.Name = row["Name"].ToString();
|
||||||
db.DelById(tableName, selectId.ToString());
|
//添加剩余的项目
|
||||||
LvCbResult.RemoveObject(item);
|
//添加完毕
|
||||||
}
|
LvCbResult.UpdateObject(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void FrmView_Load(object sender, EventArgs e)
|
db.Free();
|
||||||
{
|
#endregion
|
||||||
Text = "浏览"+ titleName;
|
}
|
||||||
添加数据ToolStripMenuItem.Text = "添加"+ titleName;
|
#endregion
|
||||||
修改数据ToolStripMenuItem.Text = "修改" + titleName;
|
public void LoadDb(string whereSQL)
|
||||||
删除数据ToolStripMenuItem.Text = "删除" + titleName;
|
{
|
||||||
rySearch1.PerformClick();
|
string _whereSQL = whereSQL;
|
||||||
}
|
DataProvider mydb = new DataProvider();
|
||||||
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||||
private void 添加数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
||||||
{
|
{
|
||||||
btnAdd.PerformClick();
|
#region 重新载入数据
|
||||||
}
|
db.AddParameter("SearchText", "%" + rySearch1.Text + "%");
|
||||||
|
ctlMyPage1.RecordCount = db.GetCount(tableName, _whereSQL);
|
||||||
private void 修改数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
ctlMyPage1.T_Parameters = db.GetParameter();
|
||||||
{
|
ctlMyPage1.SQLText= db.GetPageSQL(tableName, _whereSQL, orderSQL);
|
||||||
btnEdit.PerformClick();
|
ctlMyPage1.SQLText2 = db.GetPageSQL2(tableName, _whereSQL, orderSQL);
|
||||||
}
|
ctlMyPage1.GotoPageIndex(1);
|
||||||
|
#endregion
|
||||||
private void 删除数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
}
|
||||||
{
|
db.Free();
|
||||||
btnDel.PerformClick();
|
}
|
||||||
}
|
|
||||||
}
|
private void BtnAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FrmAdd frm = new FrmAdd()
|
||||||
|
{
|
||||||
|
Text = "添加"+ titleName,
|
||||||
|
Icon = Icon,
|
||||||
|
isAdd = 1
|
||||||
|
};
|
||||||
|
frm.mr = new ModalForm(this, frm);
|
||||||
|
frm.mr.OnDialogResult += new ModalForm.DialogResultHandler((object t, DialogResult dg) => {
|
||||||
|
if (dg == DialogResult.OK)
|
||||||
|
{
|
||||||
|
rySearch1.PerformClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frm.mr.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnEdit_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (LvCbResult.SelectedObject == null) { return; }
|
||||||
|
var item = (ViewInfo)LvCbResult.SelectedObject;
|
||||||
|
var selectId = item.Id;
|
||||||
|
FrmAdd frm = new FrmAdd()
|
||||||
|
{
|
||||||
|
Text = "修改"+ titleName,
|
||||||
|
Icon = Icon,
|
||||||
|
isAdd = 0
|
||||||
|
};
|
||||||
|
frm.GetInfo(selectId.ToString());
|
||||||
|
frm.mr = new ModalForm(this, frm);
|
||||||
|
frm.mr.OnDialogResult += new ModalForm.DialogResultHandler((object t, DialogResult dg) => {
|
||||||
|
if (dg == DialogResult.OK)
|
||||||
|
{
|
||||||
|
GetRow(selectId, LvCbResult.SelectedIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frm.mr.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (LvCbResult.SelectedObject == null) { MessageBox.Show("请先选择要删除的项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
|
||||||
|
var item = (ViewInfo)LvCbResult.SelectedObject;
|
||||||
|
var selectId = item.Id;
|
||||||
|
if (RySkins.Msg.ShowMsg("确定要删除该项吗?一旦删除将不可恢复。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//DataProvider mydb = new DataProvider();
|
||||||
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||||
|
if (db.ConnDb(Itrycn_Db.SQLConnStr) == 1)
|
||||||
|
{
|
||||||
|
db.DelById(tableName, selectId.ToString());
|
||||||
|
LvCbResult.RemoveObject(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FrmView_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Text = "浏览"+ titleName;
|
||||||
|
添加数据ToolStripMenuItem.Text = "添加"+ titleName;
|
||||||
|
修改数据ToolStripMenuItem.Text = "修改" + titleName;
|
||||||
|
删除数据ToolStripMenuItem.Text = "删除" + titleName;
|
||||||
|
rySearch1.PerformClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void 添加数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
btnAdd.PerformClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void 修改数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
btnEdit.PerformClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void 删除数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
btnDel.PerformClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void 复制并添加数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (LvCbResult.SelectedObject == null) { return; }
|
||||||
|
var item = (ViewInfo)LvCbResult.SelectedObject;
|
||||||
|
var selectId = item.Id;
|
||||||
|
FrmAdd frm = new FrmAdd()
|
||||||
|
{
|
||||||
|
Text = "添加" + titleName,
|
||||||
|
Icon = Icon,
|
||||||
|
isAdd = 1
|
||||||
|
};
|
||||||
|
frm.GetInfo(selectId.ToString());
|
||||||
|
frm.mr = new ModalForm(this, frm);
|
||||||
|
frm.mr.OnDialogResult += new ModalForm.DialogResultHandler((object t, DialogResult dg) => {
|
||||||
|
if (dg == DialogResult.OK)
|
||||||
|
{
|
||||||
|
rySearch1.PerformClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frm.mr.ShowModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
class ViewInfo
|
class ViewInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -198,5 +220,5 @@ namespace Itrycn_Project.DbOp
|
||||||
{
|
{
|
||||||
get { return AddTime.ToString("yyyy-MM-dd dddd HH:mm:ss"); }
|
get { return AddTime.ToString("yyyy-MM-dd dddd HH:mm:ss"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
Source/Itrycn_Project2/DbOp/frmView.Designer.cs
generated
15
Source/Itrycn_Project2/DbOp/frmView.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project.DbOp
|
namespace Itrycn_Project2.DbOp
|
||||||
{
|
{
|
||||||
partial class FrmView
|
partial class FrmView
|
||||||
{
|
{
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
this.LvCbResult = new BrightIdeasSoftware.FastObjectListView();
|
this.LvCbResult = new BrightIdeasSoftware.FastObjectListView();
|
||||||
this.OlvName = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
this.OlvName = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
||||||
this.OlvAddTime = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
this.OlvAddTime = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
||||||
|
this.复制并添加数据ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.contextMenuStrip1.SuspendLayout();
|
this.contextMenuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.LvCbResult)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.LvCbResult)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
|
|
@ -59,11 +60,12 @@
|
||||||
// contextMenuStrip1
|
// contextMenuStrip1
|
||||||
//
|
//
|
||||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.复制并添加数据ToolStripMenuItem,
|
||||||
this.添加数据ToolStripMenuItem,
|
this.添加数据ToolStripMenuItem,
|
||||||
this.修改数据ToolStripMenuItem,
|
this.修改数据ToolStripMenuItem,
|
||||||
this.删除数据ToolStripMenuItem});
|
this.删除数据ToolStripMenuItem});
|
||||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||||
this.contextMenuStrip1.Size = new System.Drawing.Size(125, 70);
|
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 114);
|
||||||
//
|
//
|
||||||
// 添加数据ToolStripMenuItem
|
// 添加数据ToolStripMenuItem
|
||||||
//
|
//
|
||||||
|
|
@ -153,6 +155,7 @@
|
||||||
this.LvCbResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
this.LvCbResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||||
this.OlvName,
|
this.OlvName,
|
||||||
this.OlvAddTime});
|
this.OlvAddTime});
|
||||||
|
this.LvCbResult.ContextMenuStrip = this.contextMenuStrip1;
|
||||||
this.LvCbResult.Cursor = System.Windows.Forms.Cursors.Default;
|
this.LvCbResult.Cursor = System.Windows.Forms.Cursors.Default;
|
||||||
this.LvCbResult.EmptyListMsg = "当前列表没有任何项";
|
this.LvCbResult.EmptyListMsg = "当前列表没有任何项";
|
||||||
this.LvCbResult.FullRowSelect = true;
|
this.LvCbResult.FullRowSelect = true;
|
||||||
|
|
@ -179,6 +182,13 @@
|
||||||
this.OlvAddTime.Text = "时间";
|
this.OlvAddTime.Text = "时间";
|
||||||
this.OlvAddTime.Width = 200;
|
this.OlvAddTime.Width = 200;
|
||||||
//
|
//
|
||||||
|
// 复制并添加数据ToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.复制并添加数据ToolStripMenuItem.Name = "复制并添加数据ToolStripMenuItem";
|
||||||
|
this.复制并添加数据ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.复制并添加数据ToolStripMenuItem.Text = "复制并添加数据";
|
||||||
|
this.复制并添加数据ToolStripMenuItem.Click += new System.EventHandler(this.复制并添加数据ToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// FrmView
|
// FrmView
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||||
|
|
@ -214,5 +224,6 @@
|
||||||
private BrightIdeasSoftware.FastObjectListView LvCbResult;
|
private BrightIdeasSoftware.FastObjectListView LvCbResult;
|
||||||
private BrightIdeasSoftware.OLVColumn OlvName;
|
private BrightIdeasSoftware.OLVColumn OlvName;
|
||||||
private BrightIdeasSoftware.OLVColumn OlvAddTime;
|
private BrightIdeasSoftware.OLVColumn OlvAddTime;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem 复制并添加数据ToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +118,6 @@
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>269, 21</value>
|
<value>35, 26</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
2
Source/Itrycn_Project2/FrmAbout.Designer.cs
generated
2
Source/Itrycn_Project2/FrmAbout.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
partial class FrmAbout
|
partial class FrmAbout
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
public partial class FrmAbout : RySkins.SKinForm
|
public partial class FrmAbout : RySkins.SKinForm
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Itrycn_Project;
|
using Itrycn_Project2;
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using ryCommonDb;
|
using ryCommonDb;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Itrycn_Project;
|
using Itrycn_Project2;
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -164,12 +164,12 @@ namespace Itrycn_Project2
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
//RyWeb.QuickWeb ry3h3 = new RyWeb.QuickWeb();
|
//RyWeb.QuickWeb ry3h3 = new RyWeb.QuickWeb();
|
||||||
IsExit = false;
|
|
||||||
IsRunning = false;
|
|
||||||
Soft_MemInfo.IsCanCloseForm = true;
|
|
||||||
//将扫描的代码写在下面
|
//将扫描的代码写在下面
|
||||||
|
|
||||||
//↑将扫描的代码写在上面
|
//↑将扫描的代码写在上面
|
||||||
|
IsExit = false;
|
||||||
|
IsRunning = false;
|
||||||
|
Soft_MemInfo.IsCanCloseForm = true;
|
||||||
this.Invoke(new Action(() =>
|
this.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//LvCbResult.AddObjects(list);
|
//LvCbResult.AddObjects(list);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Itrycn_Project;
|
using Itrycn_Project2;
|
||||||
using ryCommon;
|
using ryCommon;
|
||||||
using RyHardWare;
|
using RyHardWare;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Itrycn_Project.Properties
|
namespace Itrycn_Project2.Properties
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,12 @@ namespace RySkins
|
||||||
this.Controls.Add(this.btnCancel);
|
this.Controls.Add(this.btnCancel);
|
||||||
this.Controls.Add(this.btnYes);
|
this.Controls.Add(this.btnYes);
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
|
this.Location = new System.Drawing.Point(0, 0);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Name = "FrmMessageBox";
|
this.Name = "FrmMessageBox";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmMessageBox_FormClosing);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,11 @@ namespace RySkins
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
private bool ProcUse = false;
|
||||||
public MessageBoxButtons ResultDg { get; set; } = MessageBoxButtons.OKCancel;
|
public MessageBoxButtons ResultDg { get; set; } = MessageBoxButtons.OKCancel;
|
||||||
private void BtnYes_Click(object sender, EventArgs e)
|
private void BtnYes_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
ProcUse = true;
|
||||||
if (this.Modal)
|
if (this.Modal)
|
||||||
{
|
{
|
||||||
switch (ResultDg)
|
switch (ResultDg)
|
||||||
|
|
@ -38,6 +40,7 @@ namespace RySkins
|
||||||
|
|
||||||
private void BtnCancel_Click(object sender, EventArgs e)
|
private void BtnCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
ProcUse = true;
|
||||||
switch (ResultDg)
|
switch (ResultDg)
|
||||||
{
|
{
|
||||||
case MessageBoxButtons.YesNo:
|
case MessageBoxButtons.YesNo:
|
||||||
|
|
@ -54,5 +57,13 @@ namespace RySkins
|
||||||
lblMsg.UpdateInfo();
|
lblMsg.UpdateInfo();
|
||||||
lblMsg.Refresh();
|
lblMsg.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FrmMessageBox_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.CloseReason == CloseReason.UserClosing && !ProcUse)
|
||||||
|
{
|
||||||
|
this.DialogResult = DialogResult.Cancel;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
Source/Itrycn_Project2/frmSetting.Designer.cs
generated
2
Source/Itrycn_Project2/frmSetting.Designer.cs
generated
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
partial class FrmSetting
|
partial class FrmSetting
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Itrycn_Project
|
namespace Itrycn_Project2
|
||||||
{
|
{
|
||||||
public partial class FrmSetting : RySkins.SKinForm
|
public partial class FrmSetting : RySkins.SKinForm
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -342,6 +342,32 @@ namespace ryCommon
|
||||||
//return replace.IsMatch(wildcardStr1);
|
//return replace.IsMatch(wildcardStr1);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 支持忽略大小写的替换功能
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <param name="oldValue"></param>
|
||||||
|
/// <param name="newValue"></param>
|
||||||
|
/// <param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string Replace(string str, string oldValue, string newValue,bool IgnoreCase)
|
||||||
|
{
|
||||||
|
if(IgnoreCase)
|
||||||
|
{
|
||||||
|
var str2 = "";
|
||||||
|
var str_tmp = str;
|
||||||
|
var pos = str_tmp.IndexOfEx(oldValue);
|
||||||
|
while(pos>=0)
|
||||||
|
{
|
||||||
|
str2 += str_tmp.Substring(0, pos);
|
||||||
|
str_tmp = str_tmp.Substring(pos + oldValue.Length);
|
||||||
|
pos = str_tmp.IndexOfEx(oldValue);
|
||||||
|
}
|
||||||
|
str2 += str_tmp;
|
||||||
|
return str2;
|
||||||
|
}
|
||||||
|
else { return str.Replace(oldValue,newValue); }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 获取匹配的内容
|
/// 获取匹配的内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,18 @@ namespace ryCommon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 支持忽略大小写的替换文本功能
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="original"></param>
|
||||||
|
/// <param name="oldValue"></param>
|
||||||
|
/// <param name="newValue"></param>
|
||||||
|
/// <param name="IgnoreCase">是否忽略大小写</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static public string Replace(this string original, string oldValue, string newValue, bool IgnoreCase)
|
||||||
|
{
|
||||||
|
return Strings.Replace(original, oldValue, newValue, IgnoreCase);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 获取符合要求的第一个结果
|
/// 获取符合要求的第一个结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
|
|
|
||||||
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("3.0.2105.2201")]
|
[assembly: AssemblyVersion("3.0.2107.0101")]
|
||||||
[assembly: AssemblyFileVersion("3.0.2105.2201")]
|
[assembly: AssemblyFileVersion("3.0.2107.0101")]
|
||||||
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("3.0.2105.2201")]
|
[assembly: AssemblyVersion("3.0.2107.0101")]
|
||||||
[assembly: AssemblyFileVersion("3.0.2105.2201")]
|
[assembly: AssemblyFileVersion("3.0.2107.0101")]
|
||||||
|
|
@ -1,282 +1,293 @@
|
||||||
using DotNet4.Utilities;
|
using DotNet4.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace RyWeb
|
namespace RyWeb
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QuickWeb
|
public class QuickWeb
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以post方式获取网页源码
|
/// 以post方式获取网页源码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="post"></param>
|
/// <param name="post"></param>
|
||||||
/// <param name="cookie"></param>
|
/// <param name="cookie"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public HttpResult Post(string url, string post, string cookie)
|
public HttpResult Post(string url, string post, string cookie)
|
||||||
{
|
{
|
||||||
return Post(url, post, "application/x-www-form-urlencoded", cookie);
|
return Post(url, post, "application/x-www-form-urlencoded", cookie);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以post方式提交json内容
|
/// 以post方式提交json内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="post"></param>
|
/// <param name="post"></param>
|
||||||
/// <param name="cookie"></param>
|
/// <param name="cookie"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public HttpResult PostJson(string url, string post, string cookie)
|
public HttpResult PostJson(string url, string post, string cookie)
|
||||||
{
|
{
|
||||||
return Post(url, post, "application/json", cookie);
|
return Post(url, post, "application/json", cookie);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以post方式提交json内容
|
/// 以post方式提交json内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="post"></param>
|
/// <param name="post"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public HttpResult PostJson(string url, string post)
|
public HttpResult PostJson(string url, string post)
|
||||||
{
|
{
|
||||||
return Post(url, post, "application/json", "");
|
return Post(url, post, "application/json", "");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以post方式获取网页源码
|
/// 以post方式获取网页源码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="post"></param>
|
/// <param name="post"></param>
|
||||||
/// <param name="ContentType"></param>
|
/// <param name="ContentType"></param>
|
||||||
/// <param name="cookie"></param>
|
/// <param name="cookie"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public HttpResult Post(string url, string post,string ContentType, string cookie)
|
public HttpResult Post(string url, string post,string ContentType, string cookie)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpHelper t = new HttpHelper();
|
HttpHelper t = new HttpHelper();
|
||||||
HttpItem m = new HttpItem()
|
HttpItem m = new HttpItem()
|
||||||
{
|
{
|
||||||
URL = url,
|
URL = url,
|
||||||
Postdata = post,
|
Postdata = post,
|
||||||
ContentType = ContentType,
|
ContentType = ContentType,
|
||||||
Method = "POST",
|
Method = "POST",
|
||||||
Timeout = Timeout,
|
Timeout = Timeout,
|
||||||
ReadWriteTimeout = Timeout,
|
ReadWriteTimeout = Timeout,
|
||||||
UserAgent = UserAgent
|
UserAgent = UserAgent,
|
||||||
};
|
Referer=Referer
|
||||||
if (cookie.Length > 0)
|
};
|
||||||
{
|
if (cookie.Length > 0)
|
||||||
m.Cookie = cookie;
|
{
|
||||||
}
|
m.Cookie = cookie;
|
||||||
HttpResult r = t.GetHtml(m);
|
}
|
||||||
return r;
|
HttpResult r = t.GetHtml(m);
|
||||||
}
|
return r;
|
||||||
catch
|
}
|
||||||
{
|
catch
|
||||||
HttpResult r = new HttpResult();
|
{
|
||||||
return r;
|
HttpResult r = new HttpResult();
|
||||||
}
|
return r;
|
||||||
}
|
}
|
||||||
/// <summary>
|
}
|
||||||
/// 以post方式获取网页源码
|
/// <summary>
|
||||||
/// </summary>
|
/// 以post方式获取网页源码
|
||||||
/// <param name="url"></param>
|
/// </summary>
|
||||||
/// <param name="post"></param>
|
/// <param name="url"></param>
|
||||||
/// <returns></returns>
|
/// <param name="post"></param>
|
||||||
public HttpResult Post(string url, string post)
|
/// <returns></returns>
|
||||||
{
|
public HttpResult Post(string url, string post)
|
||||||
return Post(url, post, cookie);
|
{
|
||||||
}
|
return Post(url, post, cookie);
|
||||||
/// <summary>
|
}
|
||||||
/// 获取网址对应的文件大小
|
/// <summary>
|
||||||
/// </summary>
|
/// 获取网址对应的文件大小
|
||||||
/// <param name="url"></param>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="url"></param>
|
||||||
public long GetSize(string url)
|
/// <returns></returns>
|
||||||
{
|
public long GetSize(string url)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
HttpHelper t = new HttpHelper();
|
{
|
||||||
HttpItem m = new HttpItem()
|
HttpHelper t = new HttpHelper();
|
||||||
{
|
HttpItem m = new HttpItem()
|
||||||
URL = url,
|
{
|
||||||
Method = "HEAD",
|
URL = url,
|
||||||
Allowautoredirect = true,
|
Method = "HEAD",
|
||||||
Cookie = cookie,
|
Allowautoredirect = true,
|
||||||
Timeout = Timeout,
|
Cookie = cookie,
|
||||||
ReadWriteTimeout = Timeout,
|
Timeout = Timeout,
|
||||||
UserAgent=UserAgent
|
ReadWriteTimeout = Timeout,
|
||||||
};
|
UserAgent = UserAgent,
|
||||||
HttpResult r = t.GetHtml(m);
|
Referer = Referer
|
||||||
if (r.StatusCode == System.Net.HttpStatusCode.OK)
|
};
|
||||||
{
|
HttpResult r = t.GetHtml(m);
|
||||||
return Convert.ToInt64(r.Header["Content-Length"]);
|
if (r.StatusCode == System.Net.HttpStatusCode.OK)
|
||||||
}
|
{
|
||||||
else if (r.StatusCode == System.Net.HttpStatusCode.MethodNotAllowed)
|
return Convert.ToInt64(r.Header["Content-Length"]);
|
||||||
{
|
}
|
||||||
System.Net.ServicePointManager.DefaultConnectionLimit = 512;
|
else if (r.StatusCode == System.Net.HttpStatusCode.MethodNotAllowed)
|
||||||
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
|
{
|
||||||
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
|
System.Net.ServicePointManager.DefaultConnectionLimit = 512;
|
||||||
long totalBytes = response.ContentLength;
|
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
|
||||||
return totalBytes;
|
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
|
||||||
}
|
long totalBytes = response.ContentLength;
|
||||||
else
|
return totalBytes;
|
||||||
return 0;
|
}
|
||||||
}
|
else
|
||||||
catch
|
return 0;
|
||||||
{
|
}
|
||||||
return 0;
|
catch
|
||||||
}
|
{
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserAgent
|
public string UserAgent
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
} = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
|
} = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取网页源码
|
/// 获取网页源码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="cookie"></param>
|
/// <param name="cookie"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public HttpResult Get(string url, string cookie)
|
public HttpResult Get(string url, string cookie)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpHelper t = new HttpHelper();
|
HttpHelper t = new HttpHelper();
|
||||||
HttpItem m = new HttpItem()
|
HttpItem m = new HttpItem()
|
||||||
{
|
{
|
||||||
URL = url,
|
URL = url,
|
||||||
ContentType= "application/x-www-form-urlencoded"
|
ContentType= "application/x-www-form-urlencoded"
|
||||||
};
|
};
|
||||||
if (cookie.Length>0)
|
if (cookie.Length>0)
|
||||||
{
|
{
|
||||||
m.Cookie = cookie;
|
m.Cookie = cookie;
|
||||||
}
|
}
|
||||||
m.UserAgent = UserAgent;
|
m.UserAgent = UserAgent;
|
||||||
m.Allowautoredirect = true;
|
m.Allowautoredirect = true;
|
||||||
m.Timeout = Timeout;
|
m.Timeout = Timeout;
|
||||||
m.ReadWriteTimeout = Timeout;
|
m.ReadWriteTimeout = Timeout;
|
||||||
HttpResult r = t.GetHtml(m);
|
m.Referer = Referer;
|
||||||
return r;
|
HttpResult r = t.GetHtml(m);
|
||||||
}
|
return r;
|
||||||
catch
|
}
|
||||||
{
|
catch
|
||||||
HttpResult r = new HttpResult()
|
{
|
||||||
{
|
HttpResult r = new HttpResult()
|
||||||
Html = ""
|
{
|
||||||
};
|
Html = ""
|
||||||
return r;
|
};
|
||||||
}
|
return r;
|
||||||
}
|
}
|
||||||
/// <summary>
|
}
|
||||||
/// 获取网页源码
|
/// <summary>
|
||||||
/// </summary>
|
/// 获取网页源码
|
||||||
/// <param name="url"></param>
|
/// </summary>
|
||||||
///<param name="encoding"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="cookie"></param>
|
///<param name="encoding"></param>
|
||||||
/// <returns></returns>
|
/// <param name="cookie"></param>
|
||||||
public HttpResult Get(string url,Encoding encoding, string cookie)
|
/// <returns></returns>
|
||||||
{
|
public HttpResult Get(string url,Encoding encoding, string cookie)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
HttpHelper t = new HttpHelper();
|
{
|
||||||
HttpItem m = new HttpItem()
|
HttpHelper t = new HttpHelper();
|
||||||
{
|
HttpItem m = new HttpItem()
|
||||||
URL = url
|
{
|
||||||
};
|
URL = url
|
||||||
if (cookie != "")
|
};
|
||||||
{
|
if (cookie != "")
|
||||||
m.Cookie = cookie;
|
{
|
||||||
}
|
m.Cookie = cookie;
|
||||||
m.UserAgent = UserAgent;
|
}
|
||||||
m.Encoding = encoding;
|
m.UserAgent = UserAgent;
|
||||||
m.Allowautoredirect = true;
|
m.Encoding = encoding;
|
||||||
m.Timeout = Timeout;
|
m.Allowautoredirect = true;
|
||||||
m.ReadWriteTimeout = Timeout;
|
m.Timeout = Timeout;
|
||||||
HttpResult r = t.GetHtml(m);
|
m.ReadWriteTimeout = Timeout;
|
||||||
return r;
|
m.Referer = Referer;
|
||||||
}
|
HttpResult r = t.GetHtml(m);
|
||||||
catch
|
return r;
|
||||||
{
|
}
|
||||||
HttpResult r = new HttpResult()
|
catch
|
||||||
{
|
{
|
||||||
Html = ""
|
HttpResult r = new HttpResult()
|
||||||
};
|
{
|
||||||
return r;
|
Html = ""
|
||||||
}
|
};
|
||||||
}
|
return r;
|
||||||
/// <summary>
|
}
|
||||||
/// 获取网页源码
|
}
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="url"></param>
|
/// 获取网页源码
|
||||||
/// <returns></returns>
|
/// </summary>
|
||||||
public HttpResult Get(string url)
|
/// <param name="url"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
return Get(url, cookie);
|
public HttpResult Get(string url)
|
||||||
}
|
{
|
||||||
|
return Get(url, cookie);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Cookie
|
public string Cookie
|
||||||
{
|
{
|
||||||
get { return cookie; }
|
get { return cookie; }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Timeout { get; set; } = 10000;
|
public string Referer
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public int Timeout { get; set; } = 10000;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
/// <param name="encode"></param>
|
/// <param name="encode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string UrlEncode(string str, Encoding encode)
|
public string UrlEncode(string str, Encoding encode)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
byte[] byStr = encode.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
|
byte[] byStr = encode.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
|
||||||
for (int i = 0; i < byStr.Length; i++)
|
for (int i = 0; i < byStr.Length; i++)
|
||||||
{
|
{
|
||||||
var item = Convert.ToString(byStr[i], 16);
|
var item = Convert.ToString(byStr[i], 16);
|
||||||
if (item.Length == 1) { item = "0" + item; }
|
if (item.Length == 1) { item = "0" + item; }
|
||||||
sb.Append(@"%" + item);
|
sb.Append(@"%" + item);
|
||||||
}
|
}
|
||||||
return (sb.ToString());
|
return (sb.ToString());
|
||||||
}
|
}
|
||||||
private string cookie = "";
|
private string cookie = "";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将相对网址转换成绝对网址
|
/// 将相对网址转换成绝对网址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rel_url">相对网址</param>
|
/// <param name="rel_url">相对网址</param>
|
||||||
/// <param name="cur_pageUrl">当前页面地址</param>
|
/// <param name="cur_pageUrl">当前页面地址</param>
|
||||||
/// <returns>转换后的绝对网址</returns>
|
/// <returns>转换后的绝对网址</returns>
|
||||||
public string ConvertUrl(string rel_url, string cur_pageUrl)
|
public string ConvertUrl(string rel_url, string cur_pageUrl)
|
||||||
{
|
{
|
||||||
if (rel_url == "")
|
if (rel_url == "")
|
||||||
{
|
{
|
||||||
return cur_pageUrl;
|
return cur_pageUrl;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string _rel_url = rel_url;
|
string _rel_url = rel_url;
|
||||||
if (_rel_url.IndexOf("//")==0)
|
if (_rel_url.IndexOf("//")==0)
|
||||||
{
|
{
|
||||||
int iPos = cur_pageUrl.IndexOf(":");
|
int iPos = cur_pageUrl.IndexOf(":");
|
||||||
if (iPos > 0)
|
if (iPos > 0)
|
||||||
{
|
{
|
||||||
_rel_url = cur_pageUrl.Substring(0,iPos)+ ":" + _rel_url;
|
_rel_url = cur_pageUrl.Substring(0,iPos)+ ":" + _rel_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Uri baseUri = new Uri(cur_pageUrl); //
|
Uri baseUri = new Uri(cur_pageUrl); //
|
||||||
Uri absoluteUri = new Uri(baseUri, _rel_url);//相对绝对路径都在这里转 这里的urlx ="../test.html"
|
Uri absoluteUri = new Uri(baseUri, _rel_url);//相对绝对路径都在这里转 这里的urlx ="../test.html"
|
||||||
return absoluteUri.AbsoluteUri.Replace("&", "&");//
|
return absoluteUri.AbsoluteUri.Replace("&", "&");//
|
||||||
}
|
}
|
||||||
catch { return rel_url; }
|
catch { return rel_url; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("3.0.2106.1301")]
|
[assembly: AssemblyVersion("3.0.2107.0101")]
|
||||||
[assembly: AssemblyFileVersion("3.0.2106.1301")]
|
[assembly: AssemblyFileVersion("3.0.2107.0101")]
|
||||||
41
Source/ryControls/Sheng.Winform.Controls/DragHelper.cs
Normal file
41
Source/ryControls/Sheng.Winform.Controls/DragHelper.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
//用在SETreeView 的拖放操作时
|
||||||
|
//http://www.codeproject.com/KB/tree/TreeViewDragDrop.aspx
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls
|
||||||
|
{
|
||||||
|
public class DragHelper
|
||||||
|
{
|
||||||
|
[DllImport("comctl32.dll")]
|
||||||
|
public static extern bool InitCommonControls();
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool ImageList_BeginDrag(IntPtr himlTrack, int
|
||||||
|
iTrack, int dxHotspot, int dyHotspot);
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool ImageList_DragMove(int x, int y);
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern void ImageList_EndDrag();
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool ImageList_DragEnter(IntPtr hwndLock, int x, int y);
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool ImageList_DragLeave(IntPtr hwndLock);
|
||||||
|
|
||||||
|
[DllImport("comctl32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool ImageList_DragShowNolock(bool fShow);
|
||||||
|
|
||||||
|
static DragHelper()
|
||||||
|
{
|
||||||
|
InitCommonControls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
279
Source/ryControls/Sheng.Winform.Controls/Drawing/BmpAdjuster.cs
Normal file
279
Source/ryControls/Sheng.Winform.Controls/Drawing/BmpAdjuster.cs
Normal file
|
|
@ -0,0 +1,279 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Drawing
|
||||||
|
{
|
||||||
|
public class BmpAdjuster
|
||||||
|
{
|
||||||
|
#region 原有方法
|
||||||
|
|
||||||
|
public delegate ColorPalette PaletteAdjustEvent(ColorPalette plt);
|
||||||
|
|
||||||
|
public unsafe delegate void ConvertScanLineEvent(IntPtr srcLine, IntPtr dstLine, int width, int srcPixBit, int dstPixBit, Bitmap srcBmp, Bitmap dstBmp);
|
||||||
|
|
||||||
|
private int alpha = 255;
|
||||||
|
|
||||||
|
public BmpAdjuster()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化的时候给个alpha值,这样在灰图片的时候可以半透明
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="alpha"></param>
|
||||||
|
public BmpAdjuster(int alpha)
|
||||||
|
{
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AdjustColor(ref Bitmap bmp, PixelFormat format, PaletteAdjustEvent PalleteAdjust, ConvertScanLineEvent ConvertScanLine)
|
||||||
|
{
|
||||||
|
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||||
|
Bitmap bmpOut = new Bitmap(bmp.Width, bmp.Height, format);
|
||||||
|
|
||||||
|
bmpOut.Palette = PalleteAdjust(bmpOut.Palette);
|
||||||
|
|
||||||
|
PixelFormat srcFmt = bmp.PixelFormat;
|
||||||
|
PixelFormat dstFmt = bmpOut.PixelFormat;
|
||||||
|
int srcPixBit = GetPixelSize(srcFmt);
|
||||||
|
int dstPixBit = GetPixelSize(dstFmt);
|
||||||
|
|
||||||
|
BitmapData srcData = null;
|
||||||
|
BitmapData dstData = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
srcData = bmp.LockBits(rect, ImageLockMode.ReadOnly, srcFmt);
|
||||||
|
dstData = bmpOut.LockBits(rect, ImageLockMode.WriteOnly, dstFmt);
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
byte* srcLine = (byte*)srcData.Scan0.ToPointer();
|
||||||
|
byte* dstLine = (byte*)dstData.Scan0.ToPointer();
|
||||||
|
for (int L = 0; L < srcData.Height; L++)
|
||||||
|
{
|
||||||
|
ConvertScanLine((IntPtr)srcLine, (IntPtr)dstLine, srcData.Width, srcPixBit, dstPixBit, bmp, bmpOut);
|
||||||
|
|
||||||
|
srcLine += srcData.Stride;
|
||||||
|
dstLine += dstData.Stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
bmp.UnlockBits(srcData);
|
||||||
|
bmpOut.UnlockBits(dstData);
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp = bmpOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal int GetPixelSize(PixelFormat format)
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case PixelFormat.Format16bppRgb555: return 16;
|
||||||
|
case PixelFormat.Format16bppRgb565: return 16;
|
||||||
|
case PixelFormat.Format24bppRgb: return 24;
|
||||||
|
case PixelFormat.Format32bppRgb: return 32;
|
||||||
|
case PixelFormat.Format1bppIndexed: return 1;
|
||||||
|
case PixelFormat.Format4bppIndexed: return 4;
|
||||||
|
case PixelFormat.Format8bppIndexed: return 8;
|
||||||
|
case PixelFormat.Format16bppArgb1555: return 16;
|
||||||
|
case PixelFormat.Format32bppPArgb: return 32;
|
||||||
|
case PixelFormat.Format16bppGrayScale: return 16;
|
||||||
|
case PixelFormat.Format48bppRgb: return 48;
|
||||||
|
case PixelFormat.Format64bppPArgb: return 64;
|
||||||
|
case PixelFormat.Canonical: return 32;
|
||||||
|
case PixelFormat.Format32bppArgb: return 32;
|
||||||
|
case PixelFormat.Format64bppArgb: return 64;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void Monochrome(ref Bitmap bmp)
|
||||||
|
{
|
||||||
|
AdjustColor(ref bmp, PixelFormat.Format1bppIndexed,
|
||||||
|
new PaletteAdjustEvent(SetBlackWhitePallete),
|
||||||
|
new ConvertScanLineEvent(ConvertBlackWhiteScanLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorPalette SetBlackWhitePallete(ColorPalette plt)
|
||||||
|
{
|
||||||
|
plt.Entries[0] = Color.Black;
|
||||||
|
plt.Entries[1] = Color.White;
|
||||||
|
return plt;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe void ConvertBlackWhiteScanLine(IntPtr srcLine, IntPtr dstLine, int width, int srcPixBit, int dstPixBit, Bitmap srcBmp, Bitmap dstBmp)
|
||||||
|
{
|
||||||
|
byte* src = (byte*)srcLine.ToPointer();
|
||||||
|
byte* dst = (byte*)dstLine.ToPointer();
|
||||||
|
int srcPixByte = srcPixBit / 8;
|
||||||
|
int x, v, t = 0;
|
||||||
|
|
||||||
|
for (x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
v = 28 * src[0] + 151 * src[1] + 77 * src[2];
|
||||||
|
t = (t << 1) | (v > 200 * 256 ? 1 : 0);
|
||||||
|
src += srcPixByte;
|
||||||
|
|
||||||
|
if (x % 8 == 7)
|
||||||
|
{
|
||||||
|
*dst = (byte)t;
|
||||||
|
dst++;
|
||||||
|
t = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((x %= 8) != 7)
|
||||||
|
{
|
||||||
|
t <<= 8 - x;
|
||||||
|
*dst = (byte)t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Gray(ref Bitmap bmp)
|
||||||
|
{
|
||||||
|
AdjustColor(ref bmp, PixelFormat.Format8bppIndexed,
|
||||||
|
new PaletteAdjustEvent(SetGrayPallete),
|
||||||
|
new ConvertScanLineEvent(ConvertGaryScanLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorPalette SetGrayPallete(ColorPalette plt)
|
||||||
|
{
|
||||||
|
//for (int i = plt.Entries.Length - 1; i >= 0; i--)
|
||||||
|
// plt.Entries[i] = Color.FromArgb( i, i, i);
|
||||||
|
for (int i = plt.Entries.Length - 1; i >= 0; i--)
|
||||||
|
plt.Entries[i] = Color.FromArgb(alpha, i, i, i);
|
||||||
|
return plt;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe void ConvertGaryScanLine(IntPtr srcLine, IntPtr dstLine, int width, int srcPixBit, int dstPixBit, Bitmap srcBmp, Bitmap dstBmp)
|
||||||
|
{
|
||||||
|
byte* src = (byte*)srcLine.ToPointer();
|
||||||
|
byte* dst = (byte*)dstLine.ToPointer();
|
||||||
|
int srcPixByte = srcPixBit / 8;
|
||||||
|
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
*dst = (byte)((28 * src[0] + 151 * src[1] + 77 * src[2]) >> 8);
|
||||||
|
src += srcPixByte;
|
||||||
|
dst++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使图片单色化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pimage"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Bitmap MonochromeLockBits(Bitmap pimage)
|
||||||
|
{
|
||||||
|
Bitmap source = null;
|
||||||
|
|
||||||
|
// If original bitmap is not already in 32 BPP, ARGB format, then convert
|
||||||
|
if (pimage.PixelFormat != PixelFormat.Format32bppArgb)
|
||||||
|
{
|
||||||
|
source = new Bitmap(pimage.Width, pimage.Height, PixelFormat.Format32bppArgb);
|
||||||
|
source.SetResolution(pimage.HorizontalResolution, pimage.VerticalResolution);
|
||||||
|
using (Graphics g = Graphics.FromImage(source))
|
||||||
|
{
|
||||||
|
g.DrawImageUnscaled(pimage, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source = pimage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock source bitmap in memory
|
||||||
|
BitmapData sourceData = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
|
// Copy image data to binary array
|
||||||
|
int imageSize = sourceData.Stride * sourceData.Height;
|
||||||
|
byte[] sourceBuffer = new byte[imageSize];
|
||||||
|
Marshal.Copy(sourceData.Scan0, sourceBuffer, 0, imageSize);
|
||||||
|
|
||||||
|
// Unlock source bitmap
|
||||||
|
source.UnlockBits(sourceData);
|
||||||
|
|
||||||
|
// Create destination bitmap
|
||||||
|
Bitmap destination = new Bitmap(source.Width, source.Height, PixelFormat.Format1bppIndexed);
|
||||||
|
|
||||||
|
// Lock destination bitmap in memory
|
||||||
|
BitmapData destinationData = destination.LockBits(new Rectangle(0, 0, destination.Width, destination.Height), ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);
|
||||||
|
|
||||||
|
// Create destination buffer
|
||||||
|
imageSize = destinationData.Stride * destinationData.Height;
|
||||||
|
byte[] destinationBuffer = new byte[imageSize];
|
||||||
|
|
||||||
|
int sourceIndex = 0;
|
||||||
|
int destinationIndex = 0;
|
||||||
|
int pixelTotal = 0;
|
||||||
|
byte destinationValue = 0;
|
||||||
|
int pixelValue = 128;
|
||||||
|
int height = source.Height;
|
||||||
|
int width = source.Width;
|
||||||
|
int threshold = 500;
|
||||||
|
|
||||||
|
// Iterate lines
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
sourceIndex = y * sourceData.Stride;
|
||||||
|
destinationIndex = y * destinationData.Stride;
|
||||||
|
destinationValue = 0;
|
||||||
|
pixelValue = 128;
|
||||||
|
|
||||||
|
// Iterate pixels
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
// Compute pixel brightness (i.e. total of Red, Green, and Blue values)
|
||||||
|
pixelTotal = sourceBuffer[sourceIndex + 1] + sourceBuffer[sourceIndex + 2] + sourceBuffer[sourceIndex + 3];
|
||||||
|
if (pixelTotal > threshold)
|
||||||
|
{
|
||||||
|
destinationValue += (byte)pixelValue;
|
||||||
|
}
|
||||||
|
if (pixelValue == 1)
|
||||||
|
{
|
||||||
|
destinationBuffer[destinationIndex] = destinationValue;
|
||||||
|
destinationIndex++;
|
||||||
|
destinationValue = 0;
|
||||||
|
pixelValue = 128;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pixelValue >>= 1;
|
||||||
|
}
|
||||||
|
sourceIndex += 4;
|
||||||
|
}
|
||||||
|
if (pixelValue != 128)
|
||||||
|
{
|
||||||
|
destinationBuffer[destinationIndex] = destinationValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy binary image data to destination bitmap
|
||||||
|
Marshal.Copy(destinationBuffer, 0, destinationData.Scan0, imageSize);
|
||||||
|
|
||||||
|
// Unlock destination bitmap
|
||||||
|
destination.UnlockBits(destinationData);
|
||||||
|
|
||||||
|
// Dispose of source if not originally supplied bitmap
|
||||||
|
if (source != pimage)
|
||||||
|
{
|
||||||
|
source.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Drawing
|
||||||
|
{
|
||||||
|
public enum ChooseColorType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义
|
||||||
|
/// </summary>
|
||||||
|
Custom = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// 预置
|
||||||
|
/// </summary>
|
||||||
|
Define = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// 系统
|
||||||
|
/// </summary>
|
||||||
|
System = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 颜色表示法
|
||||||
|
/// </summary>
|
||||||
|
public class ColorRepresentationHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 根据颜色表示字符串获取对应的颜色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="colorValueString"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Color GetColorByValue(string colorValueString)
|
||||||
|
{
|
||||||
|
if (colorValueString == null || colorValueString == String.Empty)
|
||||||
|
{
|
||||||
|
return Color.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] strArray = colorValueString.Split('.');
|
||||||
|
|
||||||
|
ChooseColorType type =
|
||||||
|
(ChooseColorType)Convert.ToInt32(strArray[0]);
|
||||||
|
Color color = Color.Empty;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ChooseColorType.Custom:
|
||||||
|
color = Color.FromArgb(Convert.ToInt32(strArray[2]));
|
||||||
|
break;
|
||||||
|
case ChooseColorType.Define:
|
||||||
|
color = Color.FromArgb(Convert.ToInt32(strArray[2]));
|
||||||
|
break;
|
||||||
|
case ChooseColorType.System:
|
||||||
|
Type typeSystemColors = typeof(System.Drawing.SystemColors);
|
||||||
|
PropertyInfo p = typeSystemColors.GetProperty(strArray[1]);
|
||||||
|
color = (Color)p.GetValue(typeSystemColors, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
494
Source/ryControls/Sheng.Winform.Controls/Drawing/DrawingTool.cs
Normal file
494
Source/ryControls/Sheng.Winform.Controls/Drawing/DrawingTool.cs
Normal file
|
|
@ -0,0 +1,494 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Drawing
|
||||||
|
{
|
||||||
|
public static class DrawingTool
|
||||||
|
{
|
||||||
|
#region GetImage
|
||||||
|
|
||||||
|
public static Image GetImage(string filePath)
|
||||||
|
{
|
||||||
|
return GetImage(filePath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image GetImage(string filePath, bool memberCopy)
|
||||||
|
{
|
||||||
|
return GetImage(filePath, memberCopy, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从文件中获取Image对象
|
||||||
|
/// 这个函数的主要功能是处理一些ico文件
|
||||||
|
/// 一些ico文件的格式可能比较新,直接Image.FormFile,会报内存不足的异常
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath"></param>
|
||||||
|
/// <param name="memberCopy">是否将文件读入内存操作,如果为false,将直接返回Image.FromFile,在此情况下,
|
||||||
|
/// 必须手动释放Image对象,否则文件将一直处于占用状态,如果为true,则在内存中拷贝副本</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Image GetImage(string filePath,bool memberCopy, bool markNotFind)
|
||||||
|
{
|
||||||
|
FileInfo file = new FileInfo(filePath);
|
||||||
|
Image image = null;
|
||||||
|
|
||||||
|
if (!file.Exists)
|
||||||
|
{
|
||||||
|
if (markNotFind)
|
||||||
|
{
|
||||||
|
image = new Bitmap(16, 16);
|
||||||
|
Mark.FileNotFind(image);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch (file.Extension.ToLower())
|
||||||
|
{
|
||||||
|
case ".ico": try
|
||||||
|
{
|
||||||
|
Icon icon = new Icon(file.FullName);
|
||||||
|
image = icon.ToBitmap();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
image = new Bitmap(16, 16);
|
||||||
|
Mark.FileCanNotRead(image);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (memberCopy)
|
||||||
|
{
|
||||||
|
Image imgTemp = Image.FromFile(file.FullName);
|
||||||
|
image = new System.Drawing.Bitmap(imgTemp);
|
||||||
|
imgTemp.Dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Image.FromFile(file.FullName);会使文件一直处于被占用状态,必须手动释放
|
||||||
|
image = Image.FromFile(file.FullName);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ImageToIcon
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将图像转为Icon对象,使用png格式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Icon ImageToIcon(Image image)
|
||||||
|
{
|
||||||
|
return ImageToIcon(image, ImageFormat.Png);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将图像转为Icon对象
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="format"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Icon ImageToIcon(Image image, ImageFormat format)
|
||||||
|
{
|
||||||
|
System.IO.Stream ms = new MemoryStream();
|
||||||
|
image.Save(ms, format);
|
||||||
|
Icon icon = Icon.FromHandle(new Bitmap(ms).GetHicon());
|
||||||
|
ms.Close();
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetScaleImage
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回适应指定容器大小的图像
|
||||||
|
/// 如果图像的尺寸(长或宽)超出了容器范围,将按比例获取图像的缩略图返回,否则直接返回图像
|
||||||
|
/// 此方法最终调用 Image.GetThumbnailImage
|
||||||
|
/// 但是注意,在指定的容器尺寸过小时,返回的Image尺寸不可知,是在为了显示16x16的小缩略图是发现了此问题
|
||||||
|
/// 使用 GetScaleImage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="containerWidth"></param>
|
||||||
|
/// <param name="containerHeight"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Image GetAutoScaleThumbnailImage(Image image, int containerWidth, int containerHeight)
|
||||||
|
{
|
||||||
|
if (image.Size.Width > containerWidth ||
|
||||||
|
image.Size.Height > containerHeight)
|
||||||
|
{
|
||||||
|
double height = containerHeight;
|
||||||
|
double width = containerWidth;
|
||||||
|
|
||||||
|
double new_height;
|
||||||
|
double new_width;
|
||||||
|
double scale;
|
||||||
|
new_height = height;
|
||||||
|
new_width = width;
|
||||||
|
if ((image.Width > width) || (image.Height > height))
|
||||||
|
{
|
||||||
|
if (image.Width > width)
|
||||||
|
{
|
||||||
|
scale = image.Width / width;
|
||||||
|
new_width = image.Width / scale;
|
||||||
|
new_height = image.Height / scale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scale = image.Height / height;
|
||||||
|
new_width = image.Width / scale;
|
||||||
|
new_height = image.Height / scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return image.GetThumbnailImage(Convert.ToInt32(new_width), Convert.ToInt32(new_height),
|
||||||
|
thumbnailCallback, IntPtr.Zero);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static Image.GetThumbnailImageAbort thumbnailCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
|
||||||
|
private static bool ThumbnailCallback()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回适应指定容器大小的图像
|
||||||
|
/// 在需要的情况下,此方法创建一个新对象,进行绘制
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="containerWidth"></param>
|
||||||
|
/// <param name="containerHeight"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Image GetScaleImage(Image image, Size size)
|
||||||
|
{
|
||||||
|
if (image.Size.Width > size.Width ||
|
||||||
|
image.Size.Height > size.Height)
|
||||||
|
{
|
||||||
|
double width = size.Width;
|
||||||
|
double height = size.Height;
|
||||||
|
|
||||||
|
double new_width;
|
||||||
|
double new_height;
|
||||||
|
double scale;
|
||||||
|
new_height = height;
|
||||||
|
new_width = width;
|
||||||
|
if ((image.Width > width) || (image.Height > height))
|
||||||
|
{
|
||||||
|
if (image.Width > width)
|
||||||
|
{
|
||||||
|
scale = image.Width / width;
|
||||||
|
new_width = image.Width / scale;
|
||||||
|
new_height = image.Height / scale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scale = image.Height / height;
|
||||||
|
new_width = image.Width / scale;
|
||||||
|
new_height = image.Height / scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bitmap = new Bitmap(Convert.ToInt32(new_width), Convert.ToInt32(new_height));
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(bitmap);
|
||||||
|
|
||||||
|
g.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height);
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回适应指定容器大小的图像
|
||||||
|
/// 在需要的情况下,此方法创建一个新对象,进行绘制
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="containerWidth"></param>
|
||||||
|
/// <param name="containerHeight"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Image GetScaleImage(Image image, int containerWidth, int containerHeight)
|
||||||
|
{
|
||||||
|
if (containerWidth == null || containerHeight == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "containerWidth 或 containerHeight为空");
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetScaleImage(image, new Size(containerWidth, containerHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the bounding rectangle of an image required to fit
|
||||||
|
/// in to the given rectangle keeping the image aspect ratio.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">The source image.</param>
|
||||||
|
/// <param name="fit">The rectangle to fit in to.</param>
|
||||||
|
/// <param name="hAlign">Horizontal image aligment in percent.</param>
|
||||||
|
/// <param name="vAlign">Vertical image aligment in percent.</param>
|
||||||
|
/// <returns>New image size.</returns>
|
||||||
|
public static Rectangle GetSizedImageBounds(Image image, Rectangle fit, float hAlign, float vAlign)
|
||||||
|
{
|
||||||
|
if (hAlign < 0 || hAlign > 100.0f)
|
||||||
|
throw new ArgumentException("hAlign must be between 0.0 and 100.0 (inclusive).", "hAlign");
|
||||||
|
if (vAlign < 0 || vAlign > 100.0f)
|
||||||
|
throw new ArgumentException("vAlign must be between 0.0 and 100.0 (inclusive).", "vAlign");
|
||||||
|
Size scaled = GetSizedImageBounds(image, fit.Size);
|
||||||
|
int x = fit.Left + (int)(hAlign / 100.0f * (float)(fit.Width - scaled.Width));
|
||||||
|
int y = fit.Top + (int)(vAlign / 100.0f * (float)(fit.Height - scaled.Height));
|
||||||
|
|
||||||
|
return new Rectangle(x, y, scaled.Width, scaled.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the bounding rectangle of an image required to fit
|
||||||
|
/// in to the given rectangle keeping the image aspect ratio.
|
||||||
|
/// The image will be centered in the fit box.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">The source image.</param>
|
||||||
|
/// <param name="fit">The rectangle to fit in to.</param>
|
||||||
|
/// <returns>New image size.</returns>
|
||||||
|
public static Rectangle GetSizedImageBounds(Image image, Rectangle fit)
|
||||||
|
{
|
||||||
|
return GetSizedImageBounds(image, fit, 50.0f, 50.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the scaled size of an image required to fit
|
||||||
|
/// in to the given size keeping the image aspect ratio.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">The source image.</param>
|
||||||
|
/// <param name="fit">The size to fit in to.</param>
|
||||||
|
/// <returns>New image size.</returns>
|
||||||
|
public static Size GetSizedImageBounds(Image image, Size fit)
|
||||||
|
{
|
||||||
|
float f = System.Math.Max((float)image.Width / (float)fit.Width, (float)image.Height / (float)fit.Height);
|
||||||
|
if (f < 1.0f) f = 1.0f; // Do not upsize small images
|
||||||
|
int width = (int)System.Math.Round((float)image.Width / f);
|
||||||
|
int height = (int)System.Math.Round((float)image.Height / f);
|
||||||
|
return new Size(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region RoundedRect
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取一个圆角矩形
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width"></param>
|
||||||
|
/// <param name="height"></param>
|
||||||
|
/// <param name="radius">角度</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static GraphicsPath RoundedRect(int width, int height, int radius)
|
||||||
|
{
|
||||||
|
RectangleF baseRect = new RectangleF(0, 0, width, height);
|
||||||
|
return RoundedRect(baseRect, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取一个圆角矩形
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width"></param>
|
||||||
|
/// <param name="height"></param>
|
||||||
|
/// <param name="radius">角度</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static GraphicsPath RoundedRect(RectangleF baseRect, int radius)
|
||||||
|
{
|
||||||
|
//RectangleF baseRect = new RectangleF(0, 0, width, height);
|
||||||
|
float diameter = radius * 2.0f;
|
||||||
|
SizeF sizeF = new SizeF(diameter, diameter);
|
||||||
|
RectangleF arc = new RectangleF(baseRect.Location, sizeF);
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
|
||||||
|
// top left arc
|
||||||
|
path.AddArc(arc, 180, 90);
|
||||||
|
|
||||||
|
// top right arc
|
||||||
|
arc.X = baseRect.Right - diameter;
|
||||||
|
path.AddArc(arc, 270, 90);
|
||||||
|
|
||||||
|
// bottom right arc
|
||||||
|
arc.Y = baseRect.Bottom - diameter;
|
||||||
|
path.AddArc(arc, 0, 90);
|
||||||
|
|
||||||
|
// bottom left arc
|
||||||
|
arc.X = baseRect.Left;
|
||||||
|
path.AddArc(arc, 90, 90);
|
||||||
|
|
||||||
|
path.CloseFigure();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetArrowPath
|
||||||
|
|
||||||
|
public static GraphicsPath GetArrowPath(PointF startPoint, PointF endPoint)
|
||||||
|
{
|
||||||
|
return GetArrowPath(startPoint, endPoint, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GraphicsPath GetArrowPath(PointF startPoint, PointF endPoint, double arrowLength)
|
||||||
|
{
|
||||||
|
return GetArrowPath(startPoint, endPoint, arrowLength, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回一个表示箭头的Path
|
||||||
|
/// 如果开始坐标和结束坐标之间的距离大于箭头的大小,箭头向结束坐标对齐,顶着结束坐标
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startPoint">开始坐标</param>
|
||||||
|
/// <param name="endPoint">结束坐标(顶点,方向)</param>
|
||||||
|
/// <param name="arrowLength">箭头的长短,大小</param>
|
||||||
|
/// <param name="relativeValue">箭头的粗细</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static GraphicsPath GetArrowPath(PointF startPoint, PointF endPoint,
|
||||||
|
double arrowLength, double relativeValue)
|
||||||
|
{
|
||||||
|
//http://www.cnblogs.com/jasenkin/archive/2011/01/04/graphic_drawing_arrow_head_II.html
|
||||||
|
|
||||||
|
double distance = Math.Abs(Math.Sqrt(
|
||||||
|
(startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) +
|
||||||
|
(startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y)));
|
||||||
|
|
||||||
|
if (distance == 0)
|
||||||
|
{
|
||||||
|
return new GraphicsPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
double xa = endPoint.X + arrowLength * ((startPoint.X - endPoint.X)
|
||||||
|
+ (startPoint.Y - endPoint.Y) / relativeValue) / distance;
|
||||||
|
double ya = endPoint.Y + arrowLength * ((startPoint.Y - endPoint.Y)
|
||||||
|
- (startPoint.X - endPoint.X) / relativeValue) / distance;
|
||||||
|
double xb = endPoint.X + arrowLength * ((startPoint.X - endPoint.X)
|
||||||
|
- (startPoint.Y - endPoint.Y) / relativeValue) / distance;
|
||||||
|
double yb = endPoint.Y + arrowLength * ((startPoint.Y - endPoint.Y)
|
||||||
|
+ (startPoint.X - endPoint.X) / relativeValue) / distance;
|
||||||
|
|
||||||
|
PointF[] polygonPoints =
|
||||||
|
{
|
||||||
|
new PointF(endPoint.X , endPoint.Y),
|
||||||
|
new PointF( (float)xa , (float)ya),
|
||||||
|
new PointF( (float)xb , (float)yb)
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
path.AddLines(polygonPoints);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mark
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 在指定的Image上绘制特定标记
|
||||||
|
/// </summary>
|
||||||
|
public static class Mark
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 文件不存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img"></param>
|
||||||
|
[Obsolete("改用 FileNotFind(Size size)")]
|
||||||
|
public static void FileNotFind(Image image)
|
||||||
|
{
|
||||||
|
if (image == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "image = null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(image);
|
||||||
|
g.DrawRectangle(Pens.Red, 0, 0, image.Width - 1, image.Height - 1);
|
||||||
|
g.DrawLine(Pens.Red, 0, 0, image.Width, image.Height);
|
||||||
|
g.DrawLine(Pens.Red, image.Width, 0, 0, image.Height);
|
||||||
|
g.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件不存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size"></param>
|
||||||
|
public static Image FileNotFind(Size size)
|
||||||
|
{
|
||||||
|
Image image = new Bitmap(size.Width, size.Height);
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(image);
|
||||||
|
g.Clear(Color.White);
|
||||||
|
g.DrawRectangle(Pens.Red, 0, 0, image.Width - 1, image.Height - 1);
|
||||||
|
g.DrawLine(Pens.Red, 0, 0, image.Width, image.Height);
|
||||||
|
g.DrawLine(Pens.Red, image.Width, 0, 0, image.Height);
|
||||||
|
g.Dispose();
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 无法读取文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
[Obsolete("改用 FileCanNotRead(Size size)")]
|
||||||
|
public static void FileCanNotRead(Image image)
|
||||||
|
{
|
||||||
|
if (image == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "image = null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(image);
|
||||||
|
g.DrawRectangle(Pens.Red, 0, 0, image.Width - 1, image.Height - 1);
|
||||||
|
g.DrawLine(Pens.Red, 0, 0, image.Width, image.Height);
|
||||||
|
g.DrawLine(Pens.Red, image.Width, 0, 0, image.Height);
|
||||||
|
g.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image FileCanNotRead(Size size)
|
||||||
|
{
|
||||||
|
Image image = new Bitmap(size.Width, size.Height);
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(image);
|
||||||
|
g.Clear(Color.White);
|
||||||
|
g.DrawRectangle(Pens.Red, 0, 0, image.Width - 1, image.Height - 1);
|
||||||
|
g.DrawLine(Pens.Red, 0, 0, image.Width, image.Height);
|
||||||
|
g.DrawLine(Pens.Red, image.Width, 0, 0, image.Height);
|
||||||
|
g.Dispose();
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,268 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
|
||||||
|
namespace SEDrawing
|
||||||
|
{
|
||||||
|
public class GraphPlotting
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 最大圆角半径
|
||||||
|
/// </summary>
|
||||||
|
protected const int roundMaxRoundRadius = 3;
|
||||||
|
/// <summary>
|
||||||
|
/// 最小矩形边长,用于自动处理圆角大小
|
||||||
|
/// </summary>
|
||||||
|
protected const int roundMinBorderLength = 20;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 绘制一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="nLeft">矩形左上角X坐标</param>
|
||||||
|
/// <param name="nTop">矩形左上角Y坐标</param>
|
||||||
|
/// <param name="nRight">矩形右下角X坐标</param>
|
||||||
|
/// <param name="nBottom">矩形右下角Y坐标</param>
|
||||||
|
/// <param name="round">圆角的半径长度</param>
|
||||||
|
public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Pen drawPen, int nLeft, int nTop, int nRight, int nBottom, int round)
|
||||||
|
{
|
||||||
|
if (round > roundMaxRoundRadius)
|
||||||
|
{
|
||||||
|
round = roundMaxRoundRadius;
|
||||||
|
}
|
||||||
|
else if (round < 0)
|
||||||
|
{
|
||||||
|
round = 0;
|
||||||
|
}
|
||||||
|
if (Math.Abs(nRight - nLeft) < roundMinBorderLength && Math.Abs(nBottom - nTop) < roundMinBorderLength)
|
||||||
|
{
|
||||||
|
round = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point Polygon1 = new Point(nLeft + round, nTop);
|
||||||
|
Point Polygon2 = new Point(nRight - round + 1, nTop);
|
||||||
|
|
||||||
|
Point Polygon3 = new Point(nLeft, nTop + round);
|
||||||
|
Point Polygon4 = new Point(nRight + 1, nTop + round);
|
||||||
|
|
||||||
|
Point Polygon5 = new Point(nLeft, nBottom - round);
|
||||||
|
Point Polygon6 = new Point(nRight + 1, nBottom - round);
|
||||||
|
|
||||||
|
Point Polygon7 = new Point(nLeft + round, nBottom + 1);
|
||||||
|
Point Polygon8 = new Point(nRight - round, nBottom + 1);
|
||||||
|
|
||||||
|
//四条主线(上下左右)
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon1.X, Polygon1.Y, Polygon2.X, Polygon2.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon7.X, Polygon7.Y, Polygon8.X, Polygon8.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon3.X, Polygon3.Y, Polygon5.X, Polygon5.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon4.X, Polygon4.Y, Polygon6.X, Polygon6.Y);
|
||||||
|
|
||||||
|
//四个边角
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon1.X, Polygon1.Y, Polygon3.X, Polygon3.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon2.X, Polygon2.Y, Polygon4.X, Polygon4.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon5.X, Polygon5.Y, Polygon7.X, Polygon7.Y);
|
||||||
|
currentGraphicObject.DrawLine(drawPen, Polygon6.X, Polygon6.Y, Polygon8.X, Polygon8.Y);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 绘制一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="rect">要绘制的矩形对象</param>
|
||||||
|
/// <param name="round">圆角的半径长度</param>
|
||||||
|
public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Pen drawPen, Rectangle rect, int round)
|
||||||
|
{
|
||||||
|
DrawRoundRect(currentGraphicObject, drawPen, rect.Left, rect.Top, rect.Right, rect.Bottom, round);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 绘制一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="rect">要绘制的矩形对象</param>
|
||||||
|
public static void DrawRoundRect(System.Drawing.Graphics currentGraphicObject, Pen drawPen, Rectangle rect)
|
||||||
|
{
|
||||||
|
DrawRoundRect(currentGraphicObject, drawPen, rect.Left, rect.Top, rect.Right, rect.Bottom, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 填充一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="nLeft">矩形左上角X坐标</param>
|
||||||
|
/// <param name="nTop">矩形左上角Y坐标</param>
|
||||||
|
/// <param name="nRight">矩形右下角X坐标</param>
|
||||||
|
/// <param name="nBottom">矩形右下角Y坐标</param>
|
||||||
|
/// <param name="round">圆角的半径长度</param>
|
||||||
|
public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Brush brush, int nLeft, int nTop, int nRight, int nBottom, int round)
|
||||||
|
{
|
||||||
|
if (round > roundMaxRoundRadius)
|
||||||
|
{
|
||||||
|
round = roundMaxRoundRadius;
|
||||||
|
}
|
||||||
|
else if (round < 0)
|
||||||
|
{
|
||||||
|
round = 0;
|
||||||
|
}
|
||||||
|
if (Math.Abs(nRight - nLeft) < roundMinBorderLength && Math.Abs(nBottom - nTop) < roundMinBorderLength)
|
||||||
|
{
|
||||||
|
round = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point Polygon1 = new Point(nLeft + round, nTop);
|
||||||
|
Point Polygon2 = new Point(nRight - round + 1, nTop);
|
||||||
|
|
||||||
|
Point Polygon3 = new Point(nLeft, nTop + round);
|
||||||
|
Point Polygon4 = new Point(nRight + 1, nTop + round);
|
||||||
|
|
||||||
|
Point Polygon5 = new Point(nLeft, nBottom - round);
|
||||||
|
Point Polygon6 = new Point(nRight + 1, nBottom - round);
|
||||||
|
|
||||||
|
Point Polygon7 = new Point(nLeft + round, nBottom + 1);
|
||||||
|
Point Polygon8 = new Point(nRight - round, nBottom + 1);
|
||||||
|
|
||||||
|
currentGraphicObject.FillPolygon(brush, new Point[]{ Polygon1,
|
||||||
|
Polygon3,
|
||||||
|
Polygon5,
|
||||||
|
Polygon7,
|
||||||
|
Polygon8,
|
||||||
|
Polygon6,
|
||||||
|
Polygon4,
|
||||||
|
Polygon2});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 填充一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="rect">要填充的矩形</param>
|
||||||
|
/// <param name="indentSize">填充区域针对矩形的缩进距离</param>
|
||||||
|
/// <param name="round">圆角的半径长度</param>
|
||||||
|
public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Brush brush, Rectangle rect, int indentSize, int round)
|
||||||
|
{
|
||||||
|
FillRoundRect(currentGraphicObject, brush, rect.Left + indentSize, rect.Top + indentSize, rect.Right - indentSize + 1, rect.Bottom - indentSize + 1, round);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 填充一个圆角矩形.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentGraphicObject">当前屏幕的图形对象</param>
|
||||||
|
/// <param name="lineColor">矩形线条的颜色</param>
|
||||||
|
/// <param name="rect">要填充的矩形</param>
|
||||||
|
public static void FillRoundRect(System.Drawing.Graphics currentGraphicObject, Brush brush, Rectangle rect)
|
||||||
|
{
|
||||||
|
FillRoundRect(currentGraphicObject, brush, rect, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使图片单色化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pimage"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Bitmap MonochromeLockBits(Bitmap pimage)
|
||||||
|
{
|
||||||
|
Bitmap source = null;
|
||||||
|
|
||||||
|
// If original bitmap is not already in 32 BPP, ARGB format, then convert
|
||||||
|
if (pimage.PixelFormat != PixelFormat.Format32bppArgb)
|
||||||
|
{
|
||||||
|
source = new Bitmap(pimage.Width, pimage.Height, PixelFormat.Format32bppArgb);
|
||||||
|
source.SetResolution(pimage.HorizontalResolution, pimage.VerticalResolution);
|
||||||
|
using (Graphics g = Graphics.FromImage(source))
|
||||||
|
{
|
||||||
|
g.DrawImageUnscaled(pimage, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source = pimage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock source bitmap in memory
|
||||||
|
BitmapData sourceData = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
|
// Copy image data to binary array
|
||||||
|
int imageSize = sourceData.Stride * sourceData.Height;
|
||||||
|
byte[] sourceBuffer = new byte[imageSize];
|
||||||
|
Marshal.Copy(sourceData.Scan0, sourceBuffer, 0, imageSize);
|
||||||
|
|
||||||
|
// Unlock source bitmap
|
||||||
|
source.UnlockBits(sourceData);
|
||||||
|
|
||||||
|
// Create destination bitmap
|
||||||
|
Bitmap destination = new Bitmap(source.Width, source.Height, PixelFormat.Format1bppIndexed);
|
||||||
|
|
||||||
|
// Lock destination bitmap in memory
|
||||||
|
BitmapData destinationData = destination.LockBits(new Rectangle(0, 0, destination.Width, destination.Height), ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);
|
||||||
|
|
||||||
|
// Create destination buffer
|
||||||
|
imageSize = destinationData.Stride * destinationData.Height;
|
||||||
|
byte[] destinationBuffer = new byte[imageSize];
|
||||||
|
|
||||||
|
int sourceIndex = 0;
|
||||||
|
int destinationIndex = 0;
|
||||||
|
int pixelTotal = 0;
|
||||||
|
byte destinationValue = 0;
|
||||||
|
int pixelValue = 128;
|
||||||
|
int height = source.Height;
|
||||||
|
int width = source.Width;
|
||||||
|
int threshold = 500;
|
||||||
|
|
||||||
|
// Iterate lines
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
sourceIndex = y * sourceData.Stride;
|
||||||
|
destinationIndex = y * destinationData.Stride;
|
||||||
|
destinationValue = 0;
|
||||||
|
pixelValue = 128;
|
||||||
|
|
||||||
|
// Iterate pixels
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
// Compute pixel brightness (i.e. total of Red, Green, and Blue values)
|
||||||
|
pixelTotal = sourceBuffer[sourceIndex + 1] + sourceBuffer[sourceIndex + 2] + sourceBuffer[sourceIndex + 3];
|
||||||
|
if (pixelTotal > threshold)
|
||||||
|
{
|
||||||
|
destinationValue += (byte)pixelValue;
|
||||||
|
}
|
||||||
|
if (pixelValue == 1)
|
||||||
|
{
|
||||||
|
destinationBuffer[destinationIndex] = destinationValue;
|
||||||
|
destinationIndex++;
|
||||||
|
destinationValue = 0;
|
||||||
|
pixelValue = 128;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pixelValue >>= 1;
|
||||||
|
}
|
||||||
|
sourceIndex += 4;
|
||||||
|
}
|
||||||
|
if (pixelValue != 128)
|
||||||
|
{
|
||||||
|
destinationBuffer[destinationIndex] = destinationValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy binary image data to destination bitmap
|
||||||
|
Marshal.Copy(destinationBuffer, 0, destinationData.Scan0, imageSize);
|
||||||
|
|
||||||
|
// Unlock destination bitmap
|
||||||
|
destination.UnlockBits(destinationData);
|
||||||
|
|
||||||
|
// Dispose of source if not originally supplied bitmap
|
||||||
|
if (source != pimage)
|
||||||
|
{
|
||||||
|
source.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,454 @@
|
||||||
|
/* GraphicsExtension - [Extended Graphics]
|
||||||
|
* Author name: Arun Reginald Zaheeruddin
|
||||||
|
* Current version: 1.0.0.4 (12b)
|
||||||
|
* Release documentation: http://www.codeproject.com
|
||||||
|
* License information: Microsoft Public License (Ms-PL) [http://www.opensource.org/licenses/ms-pl.html]
|
||||||
|
*
|
||||||
|
* Enhancements and history
|
||||||
|
* ------------------------
|
||||||
|
* 1.0.0.1 (20 Jul 2009): Initial release with modified code from previous CodeProject article.
|
||||||
|
* 1.0.0.2 (25 Jul 2009): Added functionality that allows selected corners on a rectangle to be rounded.
|
||||||
|
* Modified code to adapt to an anti-aliased output while drawing and filling rounded rectangles.
|
||||||
|
* 1.0.0.3 (26 Jul 2009): Added DrawRoundedRectangle and FillRoundedRectangle methods that take a Rectangle and RectangleF object.
|
||||||
|
* 1.0.0.4 (27 Jul 2009): Added font metrics and measuring utility that measures a font's height, leading, ascent, etc.
|
||||||
|
*
|
||||||
|
* Issues addressed
|
||||||
|
* ----------------
|
||||||
|
* 1. Rounded rectangles - rounding edges of a rectangle.
|
||||||
|
* 2. Font Metrics - Measuring a font's height, leading, ascent, etc.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Drawing
|
||||||
|
{
|
||||||
|
static class GraphicsExtension
|
||||||
|
{
|
||||||
|
private static GraphicsPath GenerateRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
RectangleF rectangle,
|
||||||
|
float radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
float diameter;
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
if (radius <= 0.0F || filter == RectangleEdgeFilter.None)
|
||||||
|
{
|
||||||
|
path.AddRectangle(rectangle);
|
||||||
|
path.CloseFigure();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)
|
||||||
|
return graphics.GenerateCapsule(rectangle);
|
||||||
|
diameter = radius * 2.0F;
|
||||||
|
SizeF sizeF = new SizeF(diameter, diameter);
|
||||||
|
RectangleF arc = new RectangleF(rectangle.Location, sizeF);
|
||||||
|
if ((RectangleEdgeFilter.TopLeft & filter) == RectangleEdgeFilter.TopLeft)
|
||||||
|
path.AddArc(arc, 180, 90);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
|
||||||
|
path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
|
||||||
|
}
|
||||||
|
arc.X = rectangle.Right - diameter;
|
||||||
|
if ((RectangleEdgeFilter.TopRight & filter) == RectangleEdgeFilter.TopRight)
|
||||||
|
path.AddArc(arc, 270, 90);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
|
||||||
|
path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y);
|
||||||
|
}
|
||||||
|
arc.Y = rectangle.Bottom - diameter;
|
||||||
|
if ((RectangleEdgeFilter.BottomRight & filter) == RectangleEdgeFilter.BottomRight)
|
||||||
|
path.AddArc(arc, 0, 90);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height);
|
||||||
|
path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height);
|
||||||
|
}
|
||||||
|
arc.X = rectangle.Left;
|
||||||
|
if ((RectangleEdgeFilter.BottomLeft & filter) == RectangleEdgeFilter.BottomLeft)
|
||||||
|
path.AddArc(arc, 90, 90);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height);
|
||||||
|
path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
|
||||||
|
}
|
||||||
|
path.CloseFigure();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
private static GraphicsPath GenerateCapsule(
|
||||||
|
this Graphics graphics,
|
||||||
|
RectangleF rectangle)
|
||||||
|
{
|
||||||
|
float diameter;
|
||||||
|
RectangleF arc;
|
||||||
|
GraphicsPath path = new GraphicsPath();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (rectangle.Width > rectangle.Height)
|
||||||
|
{
|
||||||
|
diameter = rectangle.Height;
|
||||||
|
SizeF sizeF = new SizeF(diameter, diameter);
|
||||||
|
arc = new RectangleF(rectangle.Location, sizeF);
|
||||||
|
path.AddArc(arc, 90, 180);
|
||||||
|
arc.X = rectangle.Right - diameter;
|
||||||
|
path.AddArc(arc, 270, 180);
|
||||||
|
}
|
||||||
|
else if (rectangle.Width < rectangle.Height)
|
||||||
|
{
|
||||||
|
diameter = rectangle.Width;
|
||||||
|
SizeF sizeF = new SizeF(diameter, diameter);
|
||||||
|
arc = new RectangleF(rectangle.Location, sizeF);
|
||||||
|
path.AddArc(arc, 180, 180);
|
||||||
|
arc.Y = rectangle.Bottom - diameter;
|
||||||
|
path.AddArc(arc, 0, 180);
|
||||||
|
}
|
||||||
|
else path.AddEllipse(rectangle);
|
||||||
|
}
|
||||||
|
catch { path.AddEllipse(rectangle); }
|
||||||
|
finally { path.CloseFigure(); }
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height,
|
||||||
|
float radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
RectangleF rectangle = new RectangleF(x, y, width, height);
|
||||||
|
GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius, filter);
|
||||||
|
SmoothingMode old = graphics.SmoothingMode;
|
||||||
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
graphics.DrawPath(pen, path);
|
||||||
|
graphics.SmoothingMode = old;
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height,
|
||||||
|
float radius)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
Convert.ToSingle(x),
|
||||||
|
Convert.ToSingle(y),
|
||||||
|
Convert.ToSingle(width),
|
||||||
|
Convert.ToSingle(height),
|
||||||
|
Convert.ToSingle(radius));
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
Rectangle rectangle,
|
||||||
|
int radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
filter);
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
Rectangle rectangle,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
RectangleF rectangle,
|
||||||
|
int radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
filter);
|
||||||
|
}
|
||||||
|
public static void DrawRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Pen pen,
|
||||||
|
RectangleF rectangle,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.DrawRoundedRectangle(
|
||||||
|
pen,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height,
|
||||||
|
float radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
RectangleF rectangle = new RectangleF(x, y, width, height);
|
||||||
|
GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius, filter);
|
||||||
|
SmoothingMode old = graphics.SmoothingMode;
|
||||||
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
graphics.FillPath(brush, path);
|
||||||
|
graphics.SmoothingMode = old;
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
float width,
|
||||||
|
float height,
|
||||||
|
float radius)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
Convert.ToSingle(x),
|
||||||
|
Convert.ToSingle(y),
|
||||||
|
Convert.ToSingle(width),
|
||||||
|
Convert.ToSingle(height),
|
||||||
|
Convert.ToSingle(radius));
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
Rectangle rectangle,
|
||||||
|
int radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
filter);
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
Rectangle rectangle,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
RectangleF rectangle,
|
||||||
|
int radius,
|
||||||
|
RectangleEdgeFilter filter)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
filter);
|
||||||
|
}
|
||||||
|
public static void FillRoundedRectangle(
|
||||||
|
this Graphics graphics,
|
||||||
|
Brush brush,
|
||||||
|
RectangleF rectangle,
|
||||||
|
int radius)
|
||||||
|
{
|
||||||
|
graphics.FillRoundedRectangle(
|
||||||
|
brush,
|
||||||
|
rectangle.X,
|
||||||
|
rectangle.Y,
|
||||||
|
rectangle.Width,
|
||||||
|
rectangle.Height,
|
||||||
|
radius,
|
||||||
|
RectangleEdgeFilter.All);
|
||||||
|
}
|
||||||
|
public static FontMetrics GetFontMetrics(
|
||||||
|
this Graphics graphics,
|
||||||
|
Font font)
|
||||||
|
{
|
||||||
|
return FontMetricsImpl.GetFontMetrics(graphics, font);
|
||||||
|
}
|
||||||
|
private class FontMetricsImpl : FontMetrics
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct TEXTMETRIC
|
||||||
|
{
|
||||||
|
public int tmHeight;
|
||||||
|
public int tmAscent;
|
||||||
|
public int tmDescent;
|
||||||
|
public int tmInternalLeading;
|
||||||
|
public int tmExternalLeading;
|
||||||
|
public int tmAveCharWidth;
|
||||||
|
public int tmMaxCharWidth;
|
||||||
|
public int tmWeight;
|
||||||
|
public int tmOverhang;
|
||||||
|
public int tmDigitizedAspectX;
|
||||||
|
public int tmDigitizedAspectY;
|
||||||
|
public char tmFirstChar;
|
||||||
|
public char tmLastChar;
|
||||||
|
public char tmDefaultChar;
|
||||||
|
public char tmBreakChar;
|
||||||
|
public byte tmItalic;
|
||||||
|
public byte tmUnderlined;
|
||||||
|
public byte tmStruckOut;
|
||||||
|
public byte tmPitchAndFamily;
|
||||||
|
public byte tmCharSet;
|
||||||
|
}
|
||||||
|
[DllImport("gdi32.dll", CharSet = CharSet.Unicode)]
|
||||||
|
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
|
||||||
|
[DllImport("gdi32.dll", CharSet = CharSet.Unicode)]
|
||||||
|
public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC lptm);
|
||||||
|
[DllImport("gdi32.dll", CharSet = CharSet.Unicode)]
|
||||||
|
public static extern bool DeleteObject(IntPtr hdc);
|
||||||
|
private TEXTMETRIC GenerateTextMetrics(
|
||||||
|
Graphics graphics,
|
||||||
|
Font font)
|
||||||
|
{
|
||||||
|
IntPtr hDC = IntPtr.Zero;
|
||||||
|
TEXTMETRIC textMetric;
|
||||||
|
IntPtr hFont = IntPtr.Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hDC = graphics.GetHdc();
|
||||||
|
hFont = font.ToHfont();
|
||||||
|
IntPtr hFontDefault = SelectObject(hDC, hFont);
|
||||||
|
bool result = GetTextMetrics(hDC, out textMetric);
|
||||||
|
SelectObject(hDC, hFontDefault);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (hFont != IntPtr.Zero) DeleteObject(hFont);
|
||||||
|
if (hDC != IntPtr.Zero) graphics.ReleaseHdc(hDC);
|
||||||
|
}
|
||||||
|
return textMetric;
|
||||||
|
}
|
||||||
|
private TEXTMETRIC metrics;
|
||||||
|
public override int Height { get { return this.metrics.tmHeight; } }
|
||||||
|
public override int Ascent { get { return this.metrics.tmAscent; } }
|
||||||
|
public override int Descent { get { return this.metrics.tmDescent; } }
|
||||||
|
public override int InternalLeading { get { return this.metrics.tmInternalLeading; } }
|
||||||
|
public override int ExternalLeading { get { return this.metrics.tmExternalLeading; } }
|
||||||
|
public override int AverageCharacterWidth { get { return this.metrics.tmAveCharWidth; } }
|
||||||
|
public override int MaximumCharacterWidth { get { return this.metrics.tmMaxCharWidth; } }
|
||||||
|
public override int Weight { get { return this.metrics.tmWeight; } }
|
||||||
|
public override int Overhang { get { return this.metrics.tmOverhang; } }
|
||||||
|
public override int DigitizedAspectX { get { return this.metrics.tmDigitizedAspectX; } }
|
||||||
|
public override int DigitizedAspectY { get { return this.metrics.tmDigitizedAspectY; } }
|
||||||
|
private FontMetricsImpl(Graphics graphics, Font font)
|
||||||
|
{
|
||||||
|
this.metrics = this.GenerateTextMetrics(graphics, font);
|
||||||
|
}
|
||||||
|
public static FontMetrics GetFontMetrics(
|
||||||
|
Graphics graphics,
|
||||||
|
Font font)
|
||||||
|
{
|
||||||
|
return new FontMetricsImpl(graphics, font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum RectangleEdgeFilter
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
TopLeft = 1,
|
||||||
|
TopRight = 2,
|
||||||
|
BottomLeft = 4,
|
||||||
|
BottomRight = 8,
|
||||||
|
All = TopLeft | TopRight | BottomLeft | BottomRight
|
||||||
|
}
|
||||||
|
public abstract class FontMetrics
|
||||||
|
{
|
||||||
|
public virtual int Height { get { return 0; } }
|
||||||
|
public virtual int Ascent { get { return 0; } }
|
||||||
|
public virtual int Descent { get { return 0; } }
|
||||||
|
public virtual int InternalLeading { get { return 0; } }
|
||||||
|
public virtual int ExternalLeading { get { return 0; } }
|
||||||
|
public virtual int AverageCharacterWidth { get { return 0; } }
|
||||||
|
public virtual int MaximumCharacterWidth { get { return 0; } }
|
||||||
|
public virtual int Weight { get { return 0; } }
|
||||||
|
public virtual int Overhang { get { return 0; } }
|
||||||
|
public virtual int DigitizedAspectX { get { return 0; } }
|
||||||
|
public virtual int DigitizedAspectY { get { return 0; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Source/ryControls/Sheng.Winform.Controls/IShengValidate.cs
Normal file
35
Source/ryControls/Sheng.Winform.Controls/IShengValidate.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls
|
||||||
|
{
|
||||||
|
public delegate bool CustomValidateMethod(object sender, out string msg);
|
||||||
|
|
||||||
|
interface IShengValidate
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 验证失败中显示错误信息时用的标题
|
||||||
|
/// </summary>
|
||||||
|
string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证失败时是否需要高亮显示(改变背景色)
|
||||||
|
/// </summary>
|
||||||
|
bool HighLight { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证控件的输入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool SEValidate(out string msg);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义验证方法
|
||||||
|
/// 在基础验证都通过后,才会调用自定义验证方法(如果有)
|
||||||
|
/// </summary>
|
||||||
|
CustomValidateMethod CustomValidate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Sheng.Winform.Controls.Win32;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
public static class EnvironmentHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否支持 Windows Vista 以上的玻璃效果
|
||||||
|
/// </summary>
|
||||||
|
public static bool SupportAreo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Environment.OSVersion.Version.Major < 6)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否打开了玻璃效果
|
||||||
|
/// </summary>
|
||||||
|
public static bool DwmIsCompositionEnabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return DwmApi.DwmIsCompositionEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取应用程序主窗体
|
||||||
|
/// </summary>
|
||||||
|
public static System.Windows.Forms.Form MainForm
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
public interface IConstructorInvoker
|
||||||
|
{
|
||||||
|
object Invoke(params object[] parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConstructorInvoker : IConstructorInvoker
|
||||||
|
{
|
||||||
|
private Func<object[], object> m_invoker;
|
||||||
|
|
||||||
|
public ConstructorInfo ConstructorInfo { get; private set; }
|
||||||
|
|
||||||
|
public ConstructorInvoker(ConstructorInfo constructorInfo)
|
||||||
|
{
|
||||||
|
this.ConstructorInfo = constructorInfo;
|
||||||
|
this.m_invoker = InitializeInvoker(constructorInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Func<object[], object> InitializeInvoker(ConstructorInfo constructorInfo)
|
||||||
|
{
|
||||||
|
// Target: (object)new T((T0)parameters[0], (T1)parameters[1], ...)
|
||||||
|
|
||||||
|
// parameters to execute
|
||||||
|
var parametersParameter = Expression.Parameter(typeof(object[]), "parameters");
|
||||||
|
|
||||||
|
// build parameter list
|
||||||
|
var parameterExpressions = new List<Expression>();
|
||||||
|
var paramInfos = constructorInfo.GetParameters();
|
||||||
|
for (int i = 0; i < paramInfos.Length; i++)
|
||||||
|
{
|
||||||
|
// (Ti)parameters[i]
|
||||||
|
var valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i));
|
||||||
|
var valueCast = Expression.Convert(valueObj, paramInfos[i].ParameterType);
|
||||||
|
|
||||||
|
parameterExpressions.Add(valueCast);
|
||||||
|
}
|
||||||
|
|
||||||
|
// new T((T0)parameters[0], (T1)parameters[1], ...)
|
||||||
|
var instanceCreate = Expression.New(constructorInfo, parameterExpressions);
|
||||||
|
|
||||||
|
// (object)new T((T0)parameters[0], (T1)parameters[1], ...)
|
||||||
|
var instanceCreateCast = Expression.Convert(instanceCreate, typeof(object));
|
||||||
|
|
||||||
|
var lambda = Expression.Lambda<Func<object[], object>>(instanceCreateCast, parametersParameter);
|
||||||
|
|
||||||
|
return lambda.Compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Invoke(params object[] parameters)
|
||||||
|
{
|
||||||
|
return this.m_invoker(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IConstructorInvoker Members
|
||||||
|
|
||||||
|
object IConstructorInvoker.Invoke(params object[] parameters)
|
||||||
|
{
|
||||||
|
return this.Invoke(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
public class ConstructorInvokerPool : FastReflectionPool<Type[], IConstructorInvoker>
|
||||||
|
{
|
||||||
|
public ConstructorInvokerPool()
|
||||||
|
{
|
||||||
|
CustomCompare = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool Compare(Type[] key1, Type[] key2)
|
||||||
|
{
|
||||||
|
return key1.SequenceEqual(key2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IConstructorInvoker Create(Type type, Type[] key)
|
||||||
|
{
|
||||||
|
if (type == null || key == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "type 或 key 为空");
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstructorInfo constructorInfo = type.GetConstructor(key);
|
||||||
|
|
||||||
|
if (constructorInfo == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "没有指定的ConstructorInfo");
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ConstructorInvoker(constructorInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* 想用 Dictionary<Type, Dictionary<object, TAccessor>>
|
||||||
|
* 因为用于获取类构造函数的方法, type.GetConstructor
|
||||||
|
* 接收的是一个Types数组,而一般的GetProperty,GetMethod接收的都是一个String
|
||||||
|
* 构造函数接收的是Types数组,光光用Types数组做为缓存的Key
|
||||||
|
* 是没意义的,因为两个同样内容的数组Eques是不会相同的,必须使用扩展方法判断数组的内容是否相同
|
||||||
|
* 所以用 GetAccessorKeyFunc 来专门为以Type数组做为缓存的构造函数Cache查找缓存中的key
|
||||||
|
* 但是用object的话,在构造函数缓存中定位key时,每次都要进行Type数组和object的转换
|
||||||
|
* 比较麻烦,也可能会消耗性能,FastReflection的目的就是追求高性能,
|
||||||
|
* 所以加一个TKeyType来标识key的类型
|
||||||
|
*/
|
||||||
|
//这个缓存是全局的
|
||||||
|
public abstract class FastReflectionPool<TKeyType, TAccessor> : IFastReflectionPool<TKeyType,TAccessor>
|
||||||
|
{
|
||||||
|
private object _mutex = new object();
|
||||||
|
|
||||||
|
private Dictionary<Type, Dictionary<TKeyType, TAccessor>> _cache =
|
||||||
|
new Dictionary<Type, Dictionary<TKeyType, TAccessor>>();
|
||||||
|
|
||||||
|
private bool _customCompare = false;
|
||||||
|
public bool CustomCompare { get { return _customCompare; } set { _customCompare = value; } }
|
||||||
|
protected virtual bool Compare(TKeyType key1, TKeyType key2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TAccessor Get(Type type, TKeyType key)
|
||||||
|
{
|
||||||
|
TAccessor accessor;
|
||||||
|
Dictionary<TKeyType, TAccessor> accessorCache;
|
||||||
|
|
||||||
|
if (this._cache.TryGetValue(type, out accessorCache))
|
||||||
|
{
|
||||||
|
TKeyType accessorKey;
|
||||||
|
if (_customCompare)
|
||||||
|
{
|
||||||
|
accessorKey = accessorCache.Keys.Single((k) => { return Compare(k, key); });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
accessorKey = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessorCache.TryGetValue(key, out accessor))
|
||||||
|
{
|
||||||
|
return accessor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (_mutex)
|
||||||
|
{
|
||||||
|
if (this._cache.ContainsKey(type) == false)
|
||||||
|
{
|
||||||
|
this._cache[type] = new Dictionary<TKeyType, TAccessor>();
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor = Create(type, key);
|
||||||
|
this._cache[type][key] = accessor;
|
||||||
|
|
||||||
|
return accessor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract TAccessor Create(Type type, TKeyType key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
public interface IFieldAccessor
|
||||||
|
{
|
||||||
|
object GetValue(object instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FieldAccessor : IFieldAccessor
|
||||||
|
{
|
||||||
|
private Func<object, object> m_getter;
|
||||||
|
|
||||||
|
public FieldInfo FieldInfo { get; private set; }
|
||||||
|
|
||||||
|
public FieldAccessor(FieldInfo fieldInfo)
|
||||||
|
{
|
||||||
|
this.FieldInfo = fieldInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeGet(FieldInfo fieldInfo)
|
||||||
|
{
|
||||||
|
// target: (object)(((TInstance)instance).Field)
|
||||||
|
|
||||||
|
// preparing parameter, object type
|
||||||
|
var instance = Expression.Parameter(typeof(object), "instance");
|
||||||
|
|
||||||
|
// non-instance for static method, or ((TInstance)instance)
|
||||||
|
var instanceCast = fieldInfo.IsStatic ? null :
|
||||||
|
Expression.Convert(instance, fieldInfo.ReflectedType);
|
||||||
|
|
||||||
|
// ((TInstance)instance).Property
|
||||||
|
var fieldAccess = Expression.Field(instanceCast, fieldInfo);
|
||||||
|
|
||||||
|
// (object)(((TInstance)instance).Property)
|
||||||
|
var castFieldValue = Expression.Convert(fieldAccess, typeof(object));
|
||||||
|
|
||||||
|
// Lambda expression
|
||||||
|
var lambda = Expression.Lambda<Func<object, object>>(castFieldValue, instance);
|
||||||
|
|
||||||
|
this.m_getter = lambda.Compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetValue(object instance)
|
||||||
|
{
|
||||||
|
return this.m_getter(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IFieldAccessor Members
|
||||||
|
|
||||||
|
object IFieldAccessor.GetValue(object instance)
|
||||||
|
{
|
||||||
|
return this.GetValue(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Sheng.Winform.Controls.Kernal
|
||||||
|
{
|
||||||
|
public class FieldAccessorPool : FastReflectionPool<string,IFieldAccessor>
|
||||||
|
{
|
||||||
|
protected override IFieldAccessor Create(Type type, string key)
|
||||||
|
{
|
||||||
|
if (type == null || String.IsNullOrEmpty(key))
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "type 或 key 为空");
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldInfo fieldInfo = type.GetField(key);
|
||||||
|
|
||||||
|
if (fieldInfo == null)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, "没有指定的FieldInfo:" + key);
|
||||||
|
throw new MissingFieldException(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FieldAccessor(fieldInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user