功能调整
This commit is contained in:
1 parent
42acf1b1cb
commit
772d9f4780
40 files changed
+4953
-389
No files matched your search
@@ -236,12 +236,6 @@
|
||||
<DependentUpon>MyProSkuItemsControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MyControl\TextAndImageColumn.cs" />
|
||||
<Compile Include="MyControl\UcCheckBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MyControl\UcCheckBox.Designer.cs">
|
||||
<DependentUpon>UcCheckBox.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MyControl\UcPager.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
||||
Generated
+2
-2
@@ -54,7 +54,7 @@ namespace _29WxOrder
|
||||
this.pnlAfterSale = new DevComponents.DotNetBar.PanelEx();
|
||||
this.pnlOrderManage = new DevComponents.DotNetBar.PanelEx();
|
||||
this.splitMain = new System.Windows.Forms.SplitContainer();
|
||||
this.chkHasLogisticsThenSend = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.chkHasLogisticsThenSend = new Work.UserComponents.UcCheckBox(this.components);
|
||||
this.btn电子面单测试 = new System.Windows.Forms.Button();
|
||||
this.btnExportExcel = new DevComponents.DotNetBar.PanelEx();
|
||||
this.btnSetMutliBuyer = new DevComponents.DotNetBar.PanelEx();
|
||||
@@ -1783,7 +1783,7 @@ namespace _29WxOrder
|
||||
private DevComponents.DotNetBar.Controls.CheckBoxX chkUseMultiBuyer;
|
||||
private DevComponents.DotNetBar.PanelEx btnSetMutliBuyer;
|
||||
private System.Windows.Forms.Button btn电子面单测试;
|
||||
private TemuKJD.UserComponent.UcCheckBox chkHasLogisticsThenSend;
|
||||
private Work.UserComponents.UcCheckBox chkHasLogisticsThenSend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -44,6 +45,95 @@ namespace AllBase
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取网络图片转为Img以在DataGridView中显示,用于HttpWebRequest直接读取可能403的情况
|
||||
/// </summary>
|
||||
/// <param name="imgUrl"></param>
|
||||
/// <param name="rst"></param>
|
||||
/// <returns></returns>
|
||||
public static Image GetUrlImg(string imgUrl, out string rst)
|
||||
{
|
||||
rst = "";
|
||||
//return LoadImage(imgUrl);
|
||||
Image image = null;
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imgUrl);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
|
||||
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
//request.IfModifiedSince = DateTime.Parse("Fri, 18 Jul 2025 06:00:49 GMT"); // 没改动不更新,CS程序无缓存不使用
|
||||
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
using (Stream stream = response.GetResponseStream())
|
||||
{
|
||||
image = Image.FromStream(stream);
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
rst = ReadResponse(response);
|
||||
}
|
||||
if (string.IsNullOrEmpty(rst))
|
||||
rst = ex.Message;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rst = e.Message;
|
||||
}
|
||||
if (response != null)
|
||||
{
|
||||
response.Close();
|
||||
response.Dispose();
|
||||
}
|
||||
return image;
|
||||
|
||||
//try
|
||||
//{
|
||||
// if (!string.IsNullOrEmpty(prodSelect?.main_img))
|
||||
// {
|
||||
// using (Stream stream = WebRequest.Create(prodSelect.main_img.Replace("https", "http")).GetResponse().GetResponseStream())
|
||||
// {
|
||||
// image = Image.FromStream(stream);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
//}
|
||||
}
|
||||
|
||||
public static string ReadResponse(HttpWebResponse response, Encoding encoding = null)
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
Stream streamToRead = responseStream;
|
||||
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
||||
{
|
||||
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
||||
}
|
||||
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
||||
{
|
||||
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
||||
}
|
||||
if (encoding == null) encoding = Encoding.UTF8;
|
||||
using (StreamReader streamReader = new StreamReader(streamToRead, encoding))
|
||||
{
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代理抓取
|
||||
/// </summary>
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
</Reference>
|
||||
<Reference Include="DevComponents.DotNetBar2, Version=14.0.0.3, Culture=neutral, PublicKeyToken=c39c3242a43eee2b, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>DLL\DevComponents.DotNetBar2.dll</HintPath>
|
||||
<HintPath>..\DllReference\DevComponents.DotNetBar2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NaiBa.CefHelper.138, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -81,6 +81,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\NaiBa.Util.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NaiBa.Util.Winform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\DllReference\NaiBa.Util.Winform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -102,6 +106,12 @@
|
||||
<Compile Include="Api\JumpUpProductNew.cs" />
|
||||
<Compile Include="AutoConfirmExpress.cs" />
|
||||
<Compile Include="Base64ChangeImgUrl.cs" />
|
||||
<Compile Include="BaseForms\BaseForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\BaseForm.Designer.cs">
|
||||
<DependentUpon>BaseForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\BaseGeneralForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -114,6 +124,75 @@
|
||||
<Compile Include="BaseForms\BaseMsgForm.Designer.cs">
|
||||
<DependentUpon>BaseMsgForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserControls\ButtonEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserControls\CustomDataGridViewTextBoxCell.cs" />
|
||||
<Compile Include="BaseForms\UserControls\StatusBarUserControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserControls\StatusBarUserControl.designer.cs">
|
||||
<DependentUpon>StatusBarUserControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserControls\UcSplitPage.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserControls\UcSplitPage.designer.cs">
|
||||
<DependentUpon>UcSplitPage.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\ButtonLc.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\DataGridViewCheckBoxColumnSelectAll.cs" />
|
||||
<Compile Include="BaseForms\UserComponents\DataGridViewEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\DataGridViewXEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcCheckBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcCheckBox.designer.cs">
|
||||
<DependentUpon>UcCheckBox.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcComboBoxBase.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcComboBoxMutiSelect .cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcComboBoxMutiSelect .designer.cs">
|
||||
<DependentUpon>UcComboBoxMutiSelect .cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcDataGridViewCheckBoxColumn.cs" />
|
||||
<Compile Include="BaseForms\UserComponents\UcDataGridViewCheckBoxColumn.designer.cs">
|
||||
<DependentUpon>UcDataGridViewCheckBoxColumn.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcGroupBoxEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcGroupBoxEx.designer.cs">
|
||||
<DependentUpon>UcGroupBoxEx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTabControl.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTabControl.designer.cs">
|
||||
<DependentUpon>UcTabControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTabControlMetro.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTabControlMetro.designer.cs">
|
||||
<DependentUpon>UcTabControlMetro.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTreeView.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BaseForms\UserComponents\UcTreeView.designer.cs">
|
||||
<DependentUpon>UcTreeView.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BoundJs.cs" />
|
||||
<Compile Include="BuyUsers\ALBuyUser.cs" />
|
||||
<Compile Include="BuyUsers\CookieVisitor.cs" />
|
||||
@@ -132,6 +211,8 @@
|
||||
<Compile Include="Model\BaseModel.cs" />
|
||||
<Compile Include="Model\ExpressBase.cs" />
|
||||
<Compile Include="MulitServicerSet.cs" />
|
||||
<Compile Include="Extension\ControlExtension.cs" />
|
||||
<Compile Include="Extension\DataGridViewExtension.cs" />
|
||||
<Compile Include="PayGroupOrder.cs" />
|
||||
<Compile Include="PinduoduoApiGetProduct.cs" />
|
||||
<Compile Include="PinduoduoProductCollect.cs" />
|
||||
@@ -164,7 +245,6 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="DLL\DevComponents.DotNetBar2.dll" />
|
||||
<Content Include="Resources\BaseMsgErr.png" />
|
||||
<Content Include="Resources\BaseMsgInfo.png" />
|
||||
<Content Include="Resources\BaseMsgQue.png" />
|
||||
@@ -175,6 +255,7 @@
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources\icon.ico" />
|
||||
<Content Include="Resources\errpic.png" />
|
||||
<Content Include="Resources\max.hover.png" />
|
||||
<Content Include="Resources\max.png" />
|
||||
<Content Include="Resources\min.hover.png" />
|
||||
@@ -193,12 +274,24 @@
|
||||
<Content Include="Resources\x-6.1.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="BaseForms\BaseForm.resx">
|
||||
<DependentUpon>BaseForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BaseForms\BaseGeneralForm.resx">
|
||||
<DependentUpon>BaseGeneralForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BaseForms\BaseMsgForm.resx">
|
||||
<DependentUpon>BaseMsgForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BaseForms\UserControls\StatusBarUserControl.resx">
|
||||
<DependentUpon>StatusBarUserControl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BaseForms\UserControls\UcSplitPage.resx">
|
||||
<DependentUpon>UcSplitPage.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BaseForms\UserComponents\DataGridViewEx.resx">
|
||||
<DependentUpon>DataGridViewEx.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
||||
Generated
+2
-131
@@ -29,149 +29,20 @@ namespace Work.BaseForms
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.pbMinBase = new System.Windows.Forms.PictureBox();
|
||||
this.pbNormalBase = new System.Windows.Forms.PictureBox();
|
||||
this.pbMaxBase = new System.Windows.Forms.PictureBox();
|
||||
this.pictureBox3 = new System.Windows.Forms.PictureBox();
|
||||
this.lbTitle = new System.Windows.Forms.Label();
|
||||
this.pbCloseBase = new System.Windows.Forms.PictureBox();
|
||||
this.panel2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbMinBase)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbNormalBase)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbMaxBase)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbCloseBase)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
this.panel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(160)))), ((int)(((byte)(233)))));
|
||||
this.panel2.Controls.Add(this.pbMinBase);
|
||||
this.panel2.Controls.Add(this.pbNormalBase);
|
||||
this.panel2.Controls.Add(this.pbMaxBase);
|
||||
this.panel2.Controls.Add(this.pictureBox3);
|
||||
this.panel2.Controls.Add(this.lbTitle);
|
||||
this.panel2.Controls.Add(this.pbCloseBase);
|
||||
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel2.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(386, 32);
|
||||
this.panel2.TabIndex = 2;
|
||||
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
|
||||
this.panel2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseMove);
|
||||
//
|
||||
// pbMinBase
|
||||
//
|
||||
this.pbMinBase.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.pbMinBase.Image = global::Work.Properties.Resources.min;
|
||||
this.pbMinBase.Location = new System.Drawing.Point(258, 0);
|
||||
this.pbMinBase.Name = "pbMinBase";
|
||||
this.pbMinBase.Size = new System.Drawing.Size(32, 32);
|
||||
this.pbMinBase.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pbMinBase.TabIndex = 1;
|
||||
this.pbMinBase.TabStop = false;
|
||||
this.pbMinBase.Click += new System.EventHandler(this.PictureBox2_Click);
|
||||
this.pbMinBase.MouseLeave += new System.EventHandler(this.PictureBox2_MouseLeave);
|
||||
this.pbMinBase.MouseHover += new System.EventHandler(this.PictureBox2_MouseHover);
|
||||
//
|
||||
// pbNormalBase
|
||||
//
|
||||
this.pbNormalBase.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.pbNormalBase.Image = global::Work.Properties.Resources.normal;
|
||||
this.pbNormalBase.Location = new System.Drawing.Point(290, 0);
|
||||
this.pbNormalBase.Name = "pbNormalBase";
|
||||
this.pbNormalBase.Size = new System.Drawing.Size(32, 32);
|
||||
this.pbNormalBase.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pbNormalBase.TabIndex = 6;
|
||||
this.pbNormalBase.TabStop = false;
|
||||
this.pbNormalBase.Visible = false;
|
||||
this.pbNormalBase.Click += new System.EventHandler(this.pbNormalBase_Click);
|
||||
this.pbNormalBase.MouseLeave += new System.EventHandler(this.pbNormalBase_MouseLeave);
|
||||
this.pbNormalBase.MouseHover += new System.EventHandler(this.pbNormalBase_MouseHover);
|
||||
//
|
||||
// pbMaxBase
|
||||
//
|
||||
this.pbMaxBase.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.pbMaxBase.Image = global::Work.Properties.Resources.max;
|
||||
this.pbMaxBase.Location = new System.Drawing.Point(322, 0);
|
||||
this.pbMaxBase.Name = "pbMaxBase";
|
||||
this.pbMaxBase.Size = new System.Drawing.Size(32, 32);
|
||||
this.pbMaxBase.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pbMaxBase.TabIndex = 5;
|
||||
this.pbMaxBase.TabStop = false;
|
||||
this.pbMaxBase.Visible = false;
|
||||
this.pbMaxBase.Click += new System.EventHandler(this.pbMaxBase_Click);
|
||||
this.pbMaxBase.MouseLeave += new System.EventHandler(this.pbMaxBase_MouseLeave);
|
||||
this.pbMaxBase.MouseHover += new System.EventHandler(this.pbMaxBase_MouseHover);
|
||||
//
|
||||
// pictureBox3
|
||||
//
|
||||
this.pictureBox3.BackColor = System.Drawing.Color.Transparent;
|
||||
this.pictureBox3.Image = global::Work.Properties.Resources.icon;
|
||||
this.pictureBox3.Location = new System.Drawing.Point(5, 3);
|
||||
this.pictureBox3.Name = "pictureBox3";
|
||||
this.pictureBox3.Size = new System.Drawing.Size(23, 23);
|
||||
this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.pictureBox3.TabIndex = 3;
|
||||
this.pictureBox3.TabStop = false;
|
||||
//
|
||||
// lbTitle
|
||||
//
|
||||
this.lbTitle.AutoSize = true;
|
||||
this.lbTitle.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.lbTitle.ForeColor = System.Drawing.Color.White;
|
||||
this.lbTitle.Location = new System.Drawing.Point(31, 6);
|
||||
this.lbTitle.Name = "lbTitle";
|
||||
this.lbTitle.Size = new System.Drawing.Size(45, 17);
|
||||
this.lbTitle.TabIndex = 2;
|
||||
this.lbTitle.Text = "label1";
|
||||
//
|
||||
// pbCloseBase
|
||||
//
|
||||
this.pbCloseBase.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.pbCloseBase.Image = global::Work.Properties.Resources.close;
|
||||
this.pbCloseBase.Location = new System.Drawing.Point(354, 0);
|
||||
this.pbCloseBase.Name = "pbCloseBase";
|
||||
this.pbCloseBase.Size = new System.Drawing.Size(32, 32);
|
||||
this.pbCloseBase.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pbCloseBase.TabIndex = 0;
|
||||
this.pbCloseBase.TabStop = false;
|
||||
this.pbCloseBase.Click += new System.EventHandler(this.PictureBox1_Click);
|
||||
this.pbCloseBase.MouseLeave += new System.EventHandler(this.PictureBox1_MouseLeave);
|
||||
this.pbCloseBase.MouseHover += new System.EventHandler(this.PictureBox1_MouseHover);
|
||||
//
|
||||
// BaseForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(160)))), ((int)(((byte)(233)))));
|
||||
this.ClientSize = new System.Drawing.Size(386, 183);
|
||||
this.Controls.Add(this.panel2);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Name = "BaseForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "BaseForm";
|
||||
this.Load += new System.EventHandler(this.LcBaseForm_Load);
|
||||
this.panel2.ResumeLayout(false);
|
||||
this.panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbMinBase)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbNormalBase)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbMaxBase)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbCloseBase)).EndInit();
|
||||
this.Load += new System.EventHandler(this.BaseForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Panel panel2;
|
||||
private System.Windows.Forms.PictureBox pbMinBase;
|
||||
private System.Windows.Forms.PictureBox pbNormalBase;
|
||||
private System.Windows.Forms.PictureBox pbMaxBase;
|
||||
private System.Windows.Forms.PictureBox pictureBox3;
|
||||
private System.Windows.Forms.Label lbTitle;
|
||||
protected System.Windows.Forms.PictureBox pbCloseBase;
|
||||
}
|
||||
}
|
||||
+148
-245
@@ -1,278 +1,181 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using DevComponents.DotNetBar;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Work.UserControls;
|
||||
|
||||
namespace Work.BaseForms
|
||||
{
|
||||
public partial class BaseForm : Form
|
||||
{
|
||||
const int WM_NCHITTEST = 0x0084;
|
||||
const int HTLEFT = 10; //左边界
|
||||
const int HTRIGHT = 11; //右边界
|
||||
const int HTTOP = 12; //上边界
|
||||
const int HTTOPLEFT = 13; //左上角
|
||||
const int HTTOPRIGHT = 14; //右上角
|
||||
const int HTBOTTOM = 15; //下边界
|
||||
const int HTBOTTOMLEFT = 0x10; //左下角
|
||||
const int HTBOTTOMRIGHT = 17; //右下角
|
||||
|
||||
protected bool Minimized { get { return this.pbMinBase.Visible; } set { this.pbMinBase.Visible = value; } }
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
switch (m.Msg)
|
||||
{
|
||||
case WM_NCHITTEST:
|
||||
base.WndProc(ref m);
|
||||
Point vPoint = new Point((int)m.LParam & 0xFFFF,
|
||||
(int)m.LParam >> 16 & 0xFFFF);
|
||||
vPoint = PointToClient(vPoint);
|
||||
if (vPoint.X <= 5)
|
||||
if (vPoint.Y <= 5)
|
||||
m.Result = (IntPtr)HTTOPLEFT;
|
||||
else if (vPoint.Y >= ClientSize.Height - 5)
|
||||
m.Result = (IntPtr)HTBOTTOMLEFT;
|
||||
else m.Result = (IntPtr)HTLEFT;
|
||||
else if (vPoint.X >= ClientSize.Width - 5)
|
||||
if (vPoint.Y <= 5)
|
||||
m.Result = (IntPtr)HTTOPRIGHT;
|
||||
else if (vPoint.Y >= ClientSize.Height - 5)
|
||||
m.Result = (IntPtr)HTBOTTOMRIGHT;
|
||||
else m.Result = (IntPtr)HTRIGHT;
|
||||
else if (vPoint.Y <= 5)
|
||||
m.Result = (IntPtr)HTTOP;
|
||||
else if (vPoint.Y >= ClientSize.Height - 5)
|
||||
m.Result = (IntPtr)HTBOTTOM;
|
||||
break;
|
||||
default:
|
||||
base.WndProc(ref m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public BaseForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
|
||||
if (FileBase.Exists(BaseClass.ProgromLogoIco))
|
||||
{
|
||||
Image img = Image.FromFile(BaseClass.ProgromLogoIco);
|
||||
pictureBox3.Image = img;
|
||||
}
|
||||
}
|
||||
|
||||
private void LcBaseForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (BaseClass.Ico != null)
|
||||
Iconx = Icon = BaseClass.Ico;
|
||||
else
|
||||
Iconx = Icon = BaseClass.Ico = ImageBuild.ConvertToIcon(Properties.Resources.icon);
|
||||
|
||||
|
||||
if (this.IsShowMax)
|
||||
{
|
||||
if (this.WindowState == FormWindowState.Maximized)
|
||||
{
|
||||
this.pbMaxBase.Visible = false;
|
||||
this.pbNormalBase.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pbMaxBase.Visible = true;
|
||||
this.pbNormalBase.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PictureBox2_Click(object sender, EventArgs e)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
}
|
||||
|
||||
public virtual void PictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
//pictureBox3.Image?.Dispose();
|
||||
Close();
|
||||
}
|
||||
|
||||
private Icon _iconx;
|
||||
public Icon Iconx
|
||||
{
|
||||
set
|
||||
{
|
||||
_iconx = value;
|
||||
if (_iconx == null) return;
|
||||
|
||||
using (MemoryStream mStream = new MemoryStream())
|
||||
{
|
||||
_iconx.Save(mStream);
|
||||
Image image = Image.FromStream(mStream);
|
||||
pictureBox3.Image = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isShowMax = false;
|
||||
public bool IsShowMax
|
||||
{
|
||||
get { return isShowMax; }
|
||||
set
|
||||
{
|
||||
isShowMax = value;
|
||||
if (isShowMax)
|
||||
{
|
||||
if (this.WindowState == FormWindowState.Maximized)
|
||||
{
|
||||
this.pbMaxBase.Visible = false;
|
||||
this.pbNormalBase.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pbMaxBase.Visible = true;
|
||||
this.pbNormalBase.Visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pbMaxBase.Visible = false;
|
||||
this.pbNormalBase.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string TitleText
|
||||
public bool IsSetFontScaleNone { get; set; } = true;
|
||||
public float FormDpi
|
||||
{
|
||||
get
|
||||
{
|
||||
return Text;
|
||||
return dpi;
|
||||
}
|
||||
set
|
||||
}
|
||||
private float dpi = 96;
|
||||
|
||||
public BaseForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void BaseForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
setSkinColor(this);
|
||||
|
||||
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
|
||||
{
|
||||
Text = lbTitle.Text = value;
|
||||
}
|
||||
}
|
||||
private Point mouseOffset;//记录鼠标指针的坐标
|
||||
private bool isMouseDown;//记录鼠标左键是否按下
|
||||
private void Panel1_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (isMouseDown)
|
||||
{//获取鼠标的位置
|
||||
Point mousePos = MousePosition;
|
||||
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
|
||||
Location = mousePos;
|
||||
dpi = graphics.DpiX;
|
||||
// 或者使用 graphics.DpiY 获取垂直方向的DPI
|
||||
// float dpi = graphics.DpiY;
|
||||
// Console.WriteLine("Screen DPI: " + dpi); // winform程序会闪退
|
||||
|
||||
if (IsSetFontScaleNone)
|
||||
SetFont(this, dpi);
|
||||
}
|
||||
}
|
||||
|
||||
private void Panel1_MouseDown(object sender, MouseEventArgs e)
|
||||
public void SetFont(Control control, float dpi)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
foreach (Control c in control.Controls)
|
||||
{
|
||||
mouseOffset = new Point(-e.X, -e.Y);
|
||||
isMouseDown = true;
|
||||
SetFont(c, dpi);
|
||||
|
||||
Font of = c.Font;
|
||||
Font nf = new Font(of.FontFamily, (of.Size * 96.0 / dpi).ParseToFloat(), of.Style, of.Unit, of.GdiCharSet, of.Bold);
|
||||
c.Font = nf;
|
||||
|
||||
if (c is DevComponents.DotNetBar.PanelEx)
|
||||
{
|
||||
var pEx = (c as DevComponents.DotNetBar.PanelEx);
|
||||
if (pEx.Style.Font != null)
|
||||
{
|
||||
Font osf = pEx.Style.Font;
|
||||
Font nsf = new Font(osf.FontFamily, (osf.Size * 96.0 / dpi).ParseToFloat(), osf.Style, osf.Unit, osf.GdiCharSet, osf.Bold);
|
||||
pEx.Style.Font = nsf;
|
||||
}
|
||||
|
||||
if (pEx.StyleMouseOver.Font != null)
|
||||
{
|
||||
Font oof = pEx.StyleMouseOver.Font;
|
||||
Font nof = new Font(oof.FontFamily, (oof.Size * 96.0 / dpi).ParseToFloat(), oof.Style, oof.Unit, oof.GdiCharSet, oof.Bold);
|
||||
pEx.StyleMouseOver.Font = nof;
|
||||
}
|
||||
|
||||
if (pEx.StyleMouseDown.Font != null)
|
||||
{
|
||||
Font odf = pEx.StyleMouseDown.Font;
|
||||
Font ndf = new Font(odf.FontFamily, (odf.Size * 96.0 / dpi).ParseToFloat(), odf.Style, odf.Unit, odf.GdiCharSet, odf.Bold);
|
||||
pEx.StyleMouseDown.Font = ndf;
|
||||
}
|
||||
}
|
||||
if (c is UserComponents.UcTreeView)
|
||||
{
|
||||
var tree = c as UserComponents.UcTreeView;
|
||||
Font ogf = tree.GroupFont;
|
||||
Font ngf = new Font(ogf.FontFamily, (ogf.Size * 96.0 / dpi).ParseToFloat(), ogf.Style, ogf.Unit, ogf.GdiCharSet, ogf.Bold);
|
||||
tree.GroupFont = ngf;
|
||||
}
|
||||
|
||||
if (c.Name == "pnlSA")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Panel1_MouseUp(object sender, MouseEventArgs e)
|
||||
public void setSkinColor(Control control)
|
||||
{
|
||||
isMouseDown = false;
|
||||
}
|
||||
|
||||
private void PictureBox1_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
this.pbCloseBase.Image = global::Work.Properties.Resources.close_hover;
|
||||
this.Cursor = Cursors.Hand;
|
||||
|
||||
}
|
||||
|
||||
private void PictureBox1_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
this.pbCloseBase.Image = global::Work.Properties.Resources.close;
|
||||
this.Cursor = Cursors.Default;
|
||||
|
||||
}
|
||||
|
||||
private void PictureBox2_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
this.pbMinBase.Image = global::Work.Properties.Resources.min_hover;
|
||||
this.Cursor = Cursors.Hand;
|
||||
|
||||
}
|
||||
|
||||
private void PictureBox2_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
this.pbMinBase.Image = global::Work.Properties.Resources.min;
|
||||
this.Cursor = Cursors.Default;
|
||||
|
||||
}
|
||||
|
||||
public virtual void HideTitle()
|
||||
{
|
||||
// this.panel1.Visible = false;
|
||||
}
|
||||
|
||||
#region 窗体提交数据完成事件
|
||||
public event Action<object> SaveComplete;
|
||||
protected virtual void OnSaveComplete(object param)
|
||||
{
|
||||
this.SaveComplete?.Invoke(param);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void pbNormalBase_Click(object sender, EventArgs e)
|
||||
{
|
||||
WindowState = FormWindowState.Normal;
|
||||
this.pbMaxBase.Visible = true;
|
||||
this.pbNormalBase.Visible = false;
|
||||
}
|
||||
|
||||
private void pbNormalBase_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
this.pbNormalBase.Image = global::Work.Properties.Resources.normal_hover;
|
||||
this.Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
private void pbNormalBase_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
this.pbNormalBase.Image = global::Work.Properties.Resources.normal;
|
||||
this.Cursor = Cursors.Default;
|
||||
}
|
||||
|
||||
private void pbMaxBase_Click(object sender, EventArgs e)
|
||||
{
|
||||
WindowState = FormWindowState.Maximized;
|
||||
this.pbMaxBase.Visible = false;
|
||||
this.pbNormalBase.Visible = true;
|
||||
}
|
||||
|
||||
private void pbMaxBase_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
this.pbMaxBase.Image = global::Work.Properties.Resources.max_hover;
|
||||
this.Cursor = Cursors.Hand;
|
||||
}
|
||||
|
||||
private void pbMaxBase_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
this.pbMaxBase.Image = global::Work.Properties.Resources.max;
|
||||
this.Cursor = Cursors.Default;
|
||||
}
|
||||
private Point mPoint;
|
||||
private void panel2_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
mPoint = new Point(e.X, e.Y);
|
||||
}
|
||||
|
||||
private void panel2_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
foreach (Control c in control.Controls)
|
||||
{
|
||||
this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
|
||||
setSkinColor(c);
|
||||
|
||||
// pdd皮肤颜色
|
||||
if (BaseClass.MainPath == "29pdd" || BaseClass.MainPath == "29wx")
|
||||
{
|
||||
if (c is Panel && c.BackColor == GlobalConfig.DefaultMainColor)
|
||||
{
|
||||
c.BackColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is PanelEx && c.Name.StartsWith("btn"))
|
||||
{
|
||||
var pnl = c as PanelEx;
|
||||
if (pnl.Style.BackColor1.Color == GlobalConfig.DefaultMainColor)
|
||||
{
|
||||
pnl.Style.BackColor1.Color = GlobalConfig.MainColor;
|
||||
pnl.Style.BackColor2.Color = GlobalConfig.MainColor;
|
||||
pnl.StyleMouseOver.BackColor1.Color = GlobalConfig.BorderColor;
|
||||
pnl.StyleMouseOver.BackColor2.Color = GlobalConfig.BorderColor;
|
||||
}
|
||||
else if (pnl.Style.BackColor1.Color == GlobalConfig.DefaultMainColorLight || pnl.Style.BorderColor.Color == GlobalConfig.DefaultMainColor)
|
||||
{
|
||||
pnl.Style.BorderColor.Color = GlobalConfig.MainColor;
|
||||
pnl.Style.BackColor1.Color = GlobalConfig.MainColorLight;
|
||||
pnl.Style.BackColor2.Color = GlobalConfig.MainColorLight;
|
||||
pnl.Style.ForeColor.Color = GlobalConfig.BorderColor;
|
||||
pnl.StyleMouseOver.BackColor1.Color = GlobalConfig.BorderColor;
|
||||
pnl.StyleMouseOver.BackColor2.Color = GlobalConfig.BorderColor;
|
||||
}
|
||||
}
|
||||
else if (c is ButtonEx)
|
||||
{
|
||||
c.BackColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is SplitContainer && c.BackColor == GlobalConfig.DefaultMainColor)
|
||||
{
|
||||
c.BackColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is UserComponents.UcTreeView)
|
||||
{
|
||||
var tv = c as UserComponents.UcTreeView;
|
||||
tv.ChildNodeSelectedBgColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is UserComponents.UcGroupBoxEx && (c as UserComponents.UcGroupBoxEx).BorderColor == GlobalConfig.DefaultMainColor)
|
||||
{
|
||||
var gb = c as UserComponents.UcGroupBoxEx;
|
||||
gb.BorderColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is UserComponents.DataGridViewEx)
|
||||
{
|
||||
var dgv = c as UserComponents.DataGridViewEx;
|
||||
dgv.BorderColor = GlobalConfig.MainColor;
|
||||
dgv.DefaultCellStyle.SelectionBackColor = GlobalConfig.MainColor;
|
||||
|
||||
dgv.CheckBoxRowBoxCheckColor = GlobalConfig.MainColor;
|
||||
dgv.CheckBoxRowBoxBorderColor = GlobalConfig.BorderColor;
|
||||
}
|
||||
else if (c is UserComponents.UcCheckBox)
|
||||
{
|
||||
var chk = c as UserComponents.UcCheckBox;
|
||||
chk.CheckBoxCheckColor = GlobalConfig.MainColor;
|
||||
chk.CheckBoxBorderColor = GlobalConfig.BorderColor;
|
||||
}
|
||||
else if (c is UserComponents.UcTabControl)
|
||||
{
|
||||
var tc = c as UserComponents.UcTabControl;
|
||||
tc.TabSelectColor = GlobalConfig.MainColor;
|
||||
tc.TabSelectTextColor = GlobalConfig.MainColor;
|
||||
}
|
||||
else if (c is UserComponents.UcTabControlMetro)
|
||||
{
|
||||
var tc = c as UserComponents.UcTabControlMetro;
|
||||
tc.BorderColor = GlobalConfig.BorderColor;
|
||||
tc.TabSelectColor = GlobalConfig.MainColor;
|
||||
tc.TabSelectTextColor = GlobalConfig.MainColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Work.BaseForms
|
||||
{
|
||||
public partial class BaseGeneralForm : Form
|
||||
public partial class BaseGeneralForm : BaseForm
|
||||
{
|
||||
const int WM_NCHITTEST = 0x0084;
|
||||
const int HTLEFT = 10; //左边界
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
class ButtonLc:Button
|
||||
{
|
||||
///不显示控件获焦提示
|
||||
protected override bool ShowFocusCues
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
|
||||
class LinkLabelLc : LinkLabel
|
||||
{
|
||||
///不显示控件获焦提示
|
||||
protected override bool ShowFocusCues
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// 带表头全选的选择框列
|
||||
/// </summary>
|
||||
public class DataGridViewCheckBoxColumnSelectAll : DataGridViewCheckBoxColumn
|
||||
{
|
||||
private DatagridViewCheckBoxHeaderCell headerCell;
|
||||
private bool loaded;
|
||||
|
||||
public event CheckBoxClickedHandler OnCheckBoxClicked;
|
||||
int TotalCheckedCheckBoxes = 0;
|
||||
bool IsHeaderCheckBoxClicked = false;
|
||||
|
||||
public DataGridViewCheckBoxColumnSelectAll()
|
||||
{
|
||||
this.headerCell = new DatagridViewCheckBoxHeaderCell();
|
||||
base.HeaderCell = this.headerCell;
|
||||
|
||||
this.headerCell.OnCheckBoxClicked += new CheckBoxClickedHandler(this.headerCell_OnCheckBoxClicked);
|
||||
this.loaded = false;
|
||||
|
||||
}
|
||||
|
||||
public DataGridViewCheckBoxColumnSelectAll(bool threeState)
|
||||
: base(threeState)
|
||||
{
|
||||
this.headerCell = new DatagridViewCheckBoxHeaderCell();
|
||||
base.HeaderCell = this.headerCell;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在DataGridView改变时进行事件的绑定
|
||||
/// </summary>
|
||||
protected override void OnDataGridViewChanged()
|
||||
{
|
||||
if (this.DataGridView != null)
|
||||
{
|
||||
this.DataGridView.CellValueChanged -= DataGridView_CellValueChanged;
|
||||
this.DataGridView.CellValueChanged += DataGridView_CellValueChanged;
|
||||
this.DataGridView.CurrentCellDirtyStateChanged -= DataGridView_CurrentCellDirtyStateChanged;
|
||||
this.DataGridView.CurrentCellDirtyStateChanged += DataGridView_CurrentCellDirtyStateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在复选的时候进行判断.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void DataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
|
||||
{
|
||||
if (!IsHeaderCheckBoxClicked)
|
||||
RowCheckBoxClick((DataGridViewCheckBoxCell)this.DataGridView[e.ColumnIndex, e.RowIndex]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在复选框被选中的时候触发该事件, 该事件用于触发ValueChanged事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void DataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (this.DataGridView.CurrentCell is DataGridViewCheckBoxCell)
|
||||
this.DataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复选框被点击时所需要做的操作
|
||||
/// </summary>
|
||||
/// <param name="checkBox"></param>
|
||||
private void RowCheckBoxClick(DataGridViewCheckBoxCell checkBox)
|
||||
{
|
||||
var head = this.headerCell as DatagridViewCheckBoxHeaderCell;
|
||||
if (checkBox != null)
|
||||
{
|
||||
//计算所有被选中的行的数量
|
||||
if ((bool)checkBox.Value && TotalCheckedCheckBoxes < this.DataGridView.RowCount)
|
||||
TotalCheckedCheckBoxes++;
|
||||
else if (TotalCheckedCheckBoxes > 0)
|
||||
TotalCheckedCheckBoxes--;
|
||||
|
||||
//当所有复选框都被选中的时候,列的头上的复选框被选中, 反之则不被选中.
|
||||
if (TotalCheckedCheckBoxes < this.DataGridView.RowCount)
|
||||
head.IsChecked = false;
|
||||
else if (TotalCheckedCheckBoxes == this.DataGridView.RowCount)
|
||||
head.IsChecked = true;
|
||||
//强制repained
|
||||
head.DataGridView.InvalidateCell(head);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 头被选中时触发OnCheckBoxClicked事件.
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
private void headerCell_OnCheckBoxClicked(bool state)
|
||||
{
|
||||
if (this.OnCheckBoxClicked != null)
|
||||
{
|
||||
this.OnCheckBoxClicked(state);
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void CheckBoxClickedHandler(bool state);
|
||||
|
||||
internal class DatagridViewCheckBoxHeaderCell : DataGridViewColumnHeaderCell
|
||||
{
|
||||
private CheckBoxState _cbState = CheckBoxState.UncheckedNormal;
|
||||
private Point _cellLocation = new Point();
|
||||
private bool _checked;
|
||||
private Point checkBoxLocation;
|
||||
private Size checkBoxSize;
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _checked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_checked = value;
|
||||
if (this._checked)
|
||||
{
|
||||
this._cbState = CheckBoxState.CheckedNormal;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._cbState = CheckBoxState.UncheckedNormal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event CheckBoxClickedHandler OnCheckBoxClicked;
|
||||
|
||||
/// <summary>
|
||||
/// 点击列头的时候触发的事件,这里有个判断, 如果点击的位置是复选框则触发OnCheckBoxClicked事件.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
Point point = new Point(e.X + this._cellLocation.X, e.Y + this._cellLocation.Y);
|
||||
if (((point.X >= this.checkBoxLocation.X) && (point.X <= (this.checkBoxLocation.X + this.checkBoxSize.Width))) && ((point.Y >= this.checkBoxLocation.Y) && (point.Y <= (this.checkBoxLocation.Y + this.checkBoxSize.Height))))
|
||||
{
|
||||
this._checked = !this._checked;
|
||||
bool temp = this._checked;
|
||||
if (this.OnCheckBoxClicked != null)
|
||||
{
|
||||
this.OnCheckBoxClicked(this._checked);
|
||||
base.DataGridView.InvalidateCell(this);
|
||||
}
|
||||
foreach (DataGridViewRow row in base.DataGridView.Rows)
|
||||
{
|
||||
((DataGridViewCheckBoxCell)row.Cells[e.ColumnIndex]).Value = temp;
|
||||
}
|
||||
base.DataGridView.RefreshEdit();
|
||||
}
|
||||
base.OnMouseClick(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制一个CheckBox
|
||||
/// </summary>
|
||||
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
|
||||
{
|
||||
base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
|
||||
Point point = new Point();
|
||||
Size glyphSize = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal);
|
||||
point.X = (cellBounds.Location.X + (cellBounds.Width / 2)) - (glyphSize.Width / 2) - 1; // x位置补偿一个像素(否则在win11中偏右)
|
||||
point.Y = (cellBounds.Location.Y + (cellBounds.Height / 2)) - (glyphSize.Height / 2);
|
||||
//point.X = cellBounds.Location.X + (cellBounds.Width - glyphSize.Width) / 2; // 放一块以后除以2会有抖动
|
||||
//point.Y = cellBounds.Location.Y + (cellBounds.Height - glyphSize.Height) / 2;
|
||||
this._cellLocation = cellBounds.Location;
|
||||
this.checkBoxLocation = point;
|
||||
this.checkBoxSize = glyphSize;
|
||||
if (this._checked)
|
||||
{
|
||||
this._cbState = CheckBoxState.CheckedNormal;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._cbState = CheckBoxState.UncheckedNormal;
|
||||
}
|
||||
CheckBoxRenderer.DrawCheckBox(graphics, this.checkBoxLocation, this._cbState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Controls;
|
||||
using NaiBa.Util.Extension;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public class DataGridViewEx : DataGridView
|
||||
{
|
||||
Form parentForm = null;
|
||||
public DataGridViewEx()
|
||||
{
|
||||
BackgroundColor = Color.White;
|
||||
AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(249, 249, 249);
|
||||
RowPostPaint += DataGridViewEx_RowPostPaint;
|
||||
this.CellContentClick += DataGridViewEx_CellContentClick;
|
||||
|
||||
this.SetStyle(
|
||||
ControlStyles.OptimizedDoubleBuffer |
|
||||
ControlStyles.EnableNotifyMessage |
|
||||
ControlStyles.ResizeRedraw |
|
||||
ControlStyles.AllPaintingInWmPaint,
|
||||
true);
|
||||
|
||||
this.CellPainting += DataGridViewEx_CellPainting;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
parentForm = FindForm();
|
||||
if (parentForm != null)
|
||||
{
|
||||
parentForm.KeyPreview = true;
|
||||
parentForm.KeyDown += ParentForm_KeyDown;
|
||||
parentForm.KeyUp += ParentForm_KeyUp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void DataGridViewEx_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0)
|
||||
return;
|
||||
|
||||
var chkCol = this.Columns.Cast<DataGridViewColumn>().FirstOrDefault(c => c is DataGridViewCheckBoxColumn);
|
||||
if (chkCol == null)
|
||||
return;
|
||||
var colIndex = chkCol.Index;
|
||||
if (colIndex < 0 || e.ColumnIndex != colIndex)
|
||||
return;
|
||||
|
||||
rowIndex1 = rowIndex2;
|
||||
rowIndex2 = e.RowIndex;
|
||||
if (IsShiftDown && MultiSelectCheckBox)
|
||||
{
|
||||
if (rowIndex1 > -1 && rowIndex2 > -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (rowIndex1 > rowIndex2)
|
||||
{
|
||||
for (int i = rowIndex2; i <= rowIndex1 - 1; i++)
|
||||
{
|
||||
this.Rows[i].Cells[colIndex].Value = this.Rows[rowIndex1].Cells[colIndex].Value;
|
||||
}
|
||||
if (this.Rows[rowIndex2].Cells[colIndex].Value == this.Rows[rowIndex1].Cells[colIndex].Value && rowIndex1 != rowIndex2)
|
||||
this.Rows[rowIndex2].Cells[colIndex].Value = !this.Rows[rowIndex2].Cells[colIndex].Value.ParseToBool();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = rowIndex1; i <= rowIndex2 - 1; i++)
|
||||
{
|
||||
this.Rows[i].Cells[colIndex].Value = this.Rows[rowIndex1].Cells[colIndex].Value;
|
||||
}
|
||||
if (this.Rows[rowIndex2].Cells[colIndex].Value == this.Rows[rowIndex1].Cells[colIndex].Value && rowIndex1 != rowIndex2)
|
||||
this.Rows[rowIndex2].Cells[colIndex].Value = !this.Rows[rowIndex2].Cells[colIndex].Value.ParseToBool();
|
||||
}
|
||||
//this.ClearSelection();
|
||||
//this.SetSelectedCellCore(colIndex, rowIndex2, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
//rowIndex1 = -1;
|
||||
//rowIndex2 = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rowIndex1 = -1;
|
||||
int rowIndex2 = -1;
|
||||
bool IsShiftDown = false;
|
||||
private void ParentForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Shift:
|
||||
case Keys.ShiftKey:
|
||||
case Keys.LShiftKey:
|
||||
case Keys.RShiftKey:
|
||||
IsShiftDown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void ParentForm_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Shift:
|
||||
case Keys.ShiftKey:
|
||||
case Keys.LShiftKey:
|
||||
case Keys.RShiftKey:
|
||||
IsShiftDown = false;
|
||||
rowIndex1 = -1;
|
||||
rowIndex2 = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Color _BorderColor = Color.FromArgb(63, 126, 255);
|
||||
/// <summary>
|
||||
/// 边框颜色
|
||||
/// </summary>
|
||||
[Description("边框颜色"), Category("UserProperty")]
|
||||
public Color BorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _BorderColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_BorderColor != value)
|
||||
{
|
||||
_BorderColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool autoRowNumber = true;
|
||||
/// <summary>
|
||||
/// 边框颜色
|
||||
/// </summary>
|
||||
[Description("自动行号"), Category("UserProperty")]
|
||||
public bool AutoRowNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return autoRowNumber;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (autoRowNumber != value)
|
||||
{
|
||||
autoRowNumber = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动生成行号
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void DataGridViewEx_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||||
{
|
||||
if (AutoRowNumber)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, RowHeadersWidth - 4, e.RowBounds.Height);
|
||||
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), RowHeadersDefaultCellStyle.Font, rectangle, Color.DarkGray, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制边框颜色
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
e.Graphics.DrawRectangle(new Pen(this.BackgroundColor), new Rectangle(1, 1, this.Width - 2, this.Height - 2));
|
||||
e.Graphics.DrawRectangle(new Pen(this.BorderColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1));
|
||||
}
|
||||
|
||||
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
|
||||
{
|
||||
//if (e.ColumnIndex == yourCheckBoxColumnIndex && e.RowIndex >= 0)
|
||||
//{
|
||||
// bool isChecked = (bool)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
|
||||
// Rectangle checkBoxBounds = new Rectangle(e.CellBounds.Location.X + 10, e.CellBounds.Location.Y + (e.CellBounds.Height - 20) / 2, 20, 20); // 自定义大小和位置
|
||||
// ControlPaint.DrawCheckBox(e.Graphics, checkBoxBounds, DataGridViewState.Default, isChecked); // 绘制复选框
|
||||
// e.Handled = true; // 阻止默认绘制
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
private int checkBoxSize = 12;
|
||||
public Color CheckBoxColor = Color.White;
|
||||
public Color CheckBoxRowBoxCheckColor = Color.Blue;
|
||||
public Color CheckBoxRowBoxBorderColor = Color.Blue;
|
||||
|
||||
private void DataGridViewEx_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
|
||||
{
|
||||
var cellTmp = this.Rows[e.RowIndex].Cells[e.ColumnIndex];
|
||||
if (cellTmp is DataGridViewCheckBoxCell)
|
||||
{
|
||||
e.PaintBackground(e.CellBounds, true);
|
||||
|
||||
bool isChecked = (bool)cellTmp.Value;
|
||||
var locationX = e.CellBounds.Location.X + e.CellBounds.Width / 2 - checkBoxSize / 2 - 1;
|
||||
var locationY = e.CellBounds.Location.Y + e.CellBounds.Height / 2 - checkBoxSize / 2;
|
||||
Rectangle checkBoxBounds = new Rectangle(locationX, locationY, checkBoxSize, checkBoxSize); // 自定义大小和位置
|
||||
//ControlPaint.DrawCheckBox(e.Graphics, checkBoxBounds, isChecked ? ButtonState.Checked : ButtonState.Normal); // 绘制复选框
|
||||
UcCheckBox.DrawCheckBoxIcon(e.Graphics, checkBoxBounds, isChecked, CheckBoxColor, CheckBoxRowBoxCheckColor, CheckBoxRowBoxBorderColor);
|
||||
|
||||
e.Handled = true; // 阻止默认绘制
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool multiSelectCheckBox = true;
|
||||
/// <summary>
|
||||
/// 选择框批量选中(使用Shift按键)
|
||||
/// </summary>
|
||||
[Description("选择框批量选中(Shift)"), Category("UserProperty")]
|
||||
public bool MultiSelectCheckBox
|
||||
{
|
||||
get
|
||||
{
|
||||
return multiSelectCheckBox;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (multiSelectCheckBox != value)
|
||||
{
|
||||
multiSelectCheckBox = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Controls;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public class DataGridViewXEx : DataGridViewX
|
||||
{
|
||||
public DataGridViewXEx()
|
||||
{
|
||||
BackgroundColor = Color.White;
|
||||
AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(249, 249, 249);
|
||||
RowPostPaint += DataGridViewXEx_RowPostPaint;
|
||||
}
|
||||
|
||||
private void DataGridViewXEx_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, RowHeadersWidth - 4, e.RowBounds.Height);
|
||||
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), RowHeadersDefaultCellStyle.Font, rectangle, Color.DarkGray, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TemuKJD.UserComponent
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public partial class UcCheckBox : CheckBox
|
||||
{
|
||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
namespace TemuKJD.UserComponent
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcCheckBox
|
||||
{
|
||||
@@ -0,0 +1,231 @@
|
||||
using DevComponents.DotNetBar.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义combobox控件
|
||||
/// 增加边框,
|
||||
/// </summary>
|
||||
#region 需要注意的地方
|
||||
//DrawMode=OwnerDrawVariale
|
||||
//DropDownStyle=DropDownList
|
||||
#endregion
|
||||
class UcComboBoxBase : ComboBoxEx
|
||||
{
|
||||
#region 自定义属性
|
||||
private Color _BorderColor = Color.FromArgb(87, 100, 108);
|
||||
private Color _BoxCenterColor = Color.FromArgb(232, 233, 237);
|
||||
private Color _BoxBackColor = Color.FromArgb(212, 213, 217);
|
||||
private ButtonBorderStyle _BorderStyle = ButtonBorderStyle.Solid;
|
||||
private int _ArrowWidth = 2;
|
||||
private Color _ArrowColor = Color.FromArgb(87, 100, 108);
|
||||
private bool _ArrowFlag = true;
|
||||
private Color _FontColor = Color.FromArgb(0, 0, 0);
|
||||
[Description("边框颜色"), Category("Set")]
|
||||
public Color BorderColor
|
||||
{
|
||||
set { this._BorderColor = value; }
|
||||
get { return _BorderColor; }
|
||||
}
|
||||
[Description("框外颜色"), Category("Set")]
|
||||
public Color BoxBackColor
|
||||
{
|
||||
set { this._BoxBackColor = value; }
|
||||
get { return this._BoxBackColor; }
|
||||
}
|
||||
[Description("框内颜色"), Category("Set")]
|
||||
public Color BoxCenterColor
|
||||
{
|
||||
set { this._BoxCenterColor = value; this.BackColor = value; }
|
||||
get { return this._BoxCenterColor; }
|
||||
}
|
||||
[Description("边框样式"), Category("Set")]
|
||||
public ButtonBorderStyle BoxBorderStyle
|
||||
{
|
||||
set { this._BorderStyle = value; }
|
||||
get { return this._BorderStyle; }
|
||||
}
|
||||
[Description("下拉箭头宽度"), Category("Set")]
|
||||
public int ArrowWidth
|
||||
{
|
||||
set { this._ArrowWidth = value; }
|
||||
get { return this._ArrowWidth; }
|
||||
}
|
||||
[Description("下拉箭头颜色"), Category("Set")]
|
||||
public Color ArrowColor
|
||||
{
|
||||
set { this._ArrowColor = value; }
|
||||
get { return this._ArrowColor; }
|
||||
}
|
||||
[Description("是否绘制下拉箭头"), Category("Set")]
|
||||
public bool ArrowEnabled
|
||||
{
|
||||
set { this._ArrowFlag = value; }
|
||||
get { return this._ArrowFlag; }
|
||||
}
|
||||
[Description("字体颜色"), Category("UserSet")]
|
||||
public Color FontColor
|
||||
{
|
||||
set { this._FontColor = value; }
|
||||
get { return this._FontColor; }
|
||||
}
|
||||
#endregion
|
||||
public UcComboBoxBase()
|
||||
{
|
||||
this.UseCustomBackColor = true;
|
||||
|
||||
// 开启双缓冲等
|
||||
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.EnableNotifyMessage | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.DrawMode = DrawMode.OwnerDrawFixed;
|
||||
this.UpdateStyles();
|
||||
}
|
||||
|
||||
//导入API函数
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll ")]
|
||||
static extern IntPtr GetWindowDC(IntPtr hWnd); // 返回hWnd参数所指定的窗口的设备环境。
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll ")]
|
||||
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); // 函数释放设备上下文环境(DC)
|
||||
|
||||
protected override void OnDrawItem(DrawItemEventArgs e)
|
||||
{
|
||||
//int ItemsCount = Items.Count;
|
||||
//Rectangle rect = new Rectangle(0, 0, e.Bounds.Width, e.Bounds.Height * ItemsCount);
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
|
||||
//// 绘制下拉框背景
|
||||
//e.Graphics.FillRectangle(new SolidBrush(_BoxCenterColor), rect);
|
||||
//// 绘制下拉框边框
|
||||
//e.Graphics.DrawRectangle(new Pen(new SolidBrush(_BorderColor)), rect);
|
||||
//// 绘制选中文字背景
|
||||
//for (int i = 0; i < Items.Count; i++)
|
||||
//{
|
||||
// if (SelectedItem != null)
|
||||
// {
|
||||
// if (SelectedItem.ToString() == Items[i].ToString())
|
||||
// {
|
||||
// Rectangle rectSel = new Rectangle(1, e.Bounds.Height * (SelectedIndex), e.Bounds.Width - 2, e.Bounds.Height - 2);
|
||||
// e.Graphics.FillRectangle(new SolidBrush(Color.White), rectSel);
|
||||
// }
|
||||
// }
|
||||
// // 绘制文字
|
||||
// e.Graphics.DrawString(Items[i].ToString(), Font, new SolidBrush(_FontColor), new PointF(0, i * (e.Bounds.Height == 0 ? 16 : e.Bounds.Height)));
|
||||
//}
|
||||
|
||||
if (e.Index >= 0)
|
||||
{
|
||||
e.Graphics.FillRectangle(new SolidBrush(_BoxCenterColor), e.Bounds);
|
||||
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus || (e.State & DrawItemState.Selected) == DrawItemState.Selected)
|
||||
{
|
||||
// 设置鼠标悬浮ComboBox的item的背景色
|
||||
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
|
||||
}
|
||||
else if (((e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit))
|
||||
{
|
||||
// 默认背景
|
||||
e.Graphics.FillRectangle(new SolidBrush(e.BackColor), e.Bounds);
|
||||
}
|
||||
// 绘制文字
|
||||
e.Graphics.DrawString(Items[e.Index].ToString(), Font, new SolidBrush(_FontColor), new PointF(e.Bounds.X, e.Bounds.Y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
try
|
||||
{
|
||||
// WM_PAINT = 0xf; 要求一个窗口重画自己,即Paint事件时
|
||||
// WM_CTLCOLOREDIT = 0x133; 当一个编辑型控件将要被绘制时发送此消息给它的父窗口;
|
||||
// 通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置编辑框的文本和背景颜色
|
||||
// windows消息值表,可参考:http://hi.baidu.com/dooy/blog/item/0e770a24f70e3b2cd407421b.html
|
||||
if (m.Msg == 0xf || m.Msg == 0x133)
|
||||
{
|
||||
IntPtr hDC = GetWindowDC(m.HWnd);
|
||||
if (hDC.ToInt32() == 0) //如果取设备上下文失败则返回
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 建立Graphics对像
|
||||
Graphics g = Graphics.FromHdc(hDC);
|
||||
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
|
||||
Rectangle rectCenter = new Rectangle(1, 1, Width - 3, Height - 2);
|
||||
Color boxBackColor = Enabled ? _BoxBackColor : Color.FromArgb(255, 200, 200, 200);
|
||||
Color boxCenterColor = Enabled ? _BoxCenterColor : Color.FromArgb(255, 200, 200, 200);
|
||||
Color fontColor = Enabled ? _FontColor : Color.FromArgb(255, 127, 127, 127);
|
||||
Color arrorColor = Enabled ? _ArrowColor : Color.FromArgb(255, 127, 127, 127);
|
||||
// 填充框外颜色(预留,可扩展为带圆角矩形的阴影特效)
|
||||
g.DrawRectangle(new Pen(_BoxBackColor), rect);
|
||||
// 填充框内颜色
|
||||
if (this.DropDownStyle == ComboBoxStyle.DropDownList)
|
||||
{
|
||||
g.FillRectangle(new SolidBrush(boxCenterColor), rectCenter);
|
||||
}
|
||||
// 填充下拉按钮
|
||||
g.FillRectangle(new SolidBrush(boxCenterColor), Width - Height + 2, 1, Height - 3, Height - 2);
|
||||
// 绘制边框
|
||||
//ControlPaint.DrawBorder(g, rect, _BorderColor, _BorderStyle);
|
||||
g.DrawPolygon(new Pen(new SolidBrush(_BorderColor), 1), new Point[] {
|
||||
new Point(0, 0), new Point(Width, 0), new Point(Width, Height), new Point(0, Height), new Point(0, 1) });
|
||||
// 绘制下拉按钮边框
|
||||
//ControlPaint.DrawBorder(g, new Rectangle(Width - Height + 3, 0, Height - 3, Height), Color.Red, ButtonBorderStyle.Solid);
|
||||
// 绘制下拉按钮坚线
|
||||
g.DrawLine(new Pen(_BorderColor, 1), new PointF(this.Width - this.Height + 3, 0), new PointF(this.Width - this.Height + 3, this.Height));
|
||||
string selValue = this.Text;
|
||||
//string text = Enabled ? selValue : "";
|
||||
string text = selValue;
|
||||
// 绘制下拉按钮箭头
|
||||
if (_ArrowFlag)
|
||||
{
|
||||
g.DrawLines(new Pen(arrorColor, _ArrowWidth), new PointF[] {
|
||||
new PointF(this.Width - 6, this.Height / 2 - 2),
|
||||
new PointF(this.Width - 10, this.Height / 2 + 2),
|
||||
new PointF(this.Width - 14, this.Height / 2 - 2)
|
||||
});
|
||||
}
|
||||
if (this.DropDownStyle == ComboBoxStyle.DropDownList)
|
||||
{
|
||||
// 绘制文本
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
g.DrawString(text, Font, new SolidBrush(fontColor), 1, 3);
|
||||
//// 绘制选中文本及背景 // 废弃
|
||||
//if (this.SelectionLength > 0 && SelectionStart >= 0 && SelectionStart + SelectionLength <= text.Length)
|
||||
//{
|
||||
// var sizeLeft = g.MeasureString(text.Substring(0, SelectionStart), Font);
|
||||
// var sizeSelect = g.MeasureString(text.Substring(SelectionStart, SelectionLength), Font);
|
||||
// var left = sizeLeft.Width == 0 ? 3 : sizeLeft.Width - 1;
|
||||
// var width = sizeSelect.Width - 3;
|
||||
// Rectangle selectRect = new Rectangle((int)left, 3, (int)width, (int)sizeSelect.Height - 1);
|
||||
// g.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), selectRect);
|
||||
// g.DrawString((text.Substring(SelectionStart, SelectionLength)), Font, new SolidBrush(Color.White), left - 2, 3);
|
||||
//}
|
||||
}
|
||||
ReleaseDC(m.HWnd, hDC);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
|
||||
//if (m.Msg == 0x0014) // 禁掉清除背景消息
|
||||
// return;
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Work.Extension;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public partial class UcComboBoxMutiSelect : ComboBox
|
||||
{
|
||||
//private bool _IsMultiSelect;
|
||||
//public bool IsMultiSelect { get => _IsMultiSelect; set => _IsMultiSelect = value; }
|
||||
|
||||
string defaultText = "全部";
|
||||
[Browsable(true), Description("默认文本"), Category("自定义分组")]
|
||||
public string DefaultText
|
||||
{
|
||||
get { return defaultText; }
|
||||
set
|
||||
{
|
||||
defaultText = value;
|
||||
this.Text = defaultText;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public List<object> SelectItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.checkedListBox == null)
|
||||
return this.Items.Cast<object>().ToList();
|
||||
|
||||
List<object> lstObj = new List<object>();
|
||||
for (int i = 0; i < checkedListBox.Items.Count; i++)
|
||||
{
|
||||
if (checkedListBox.GetItemChecked(i))
|
||||
{
|
||||
lstObj.Add(checkedListBox.Items[i]);
|
||||
}
|
||||
}
|
||||
return lstObj;
|
||||
}
|
||||
}
|
||||
|
||||
Label lblX = null;
|
||||
CheckedListBox checkedListBox = null;
|
||||
public UcComboBoxMutiSelect()
|
||||
{
|
||||
SetStyle(ControlStyles.DoubleBuffer |
|
||||
ControlStyles.OptimizedDoubleBuffer |
|
||||
ControlStyles.AllPaintingInWmPaint, true);
|
||||
UpdateStyles();
|
||||
|
||||
this.Text = DefaultText;
|
||||
this.DropDownWidth = 1;
|
||||
this.DropDownHeight = 1;
|
||||
this.DropDown += UcComboBoxMutiSelect_DropDown;
|
||||
this.DropDownClosed += UcComboBoxMutiSelect_DropDownClosed;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
var parentForm = FindForm();
|
||||
if (parentForm != null && parentForm.Visible == true)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
UpdateClearLabel();
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.Move += UcComboBoxMutiSelect_Move;
|
||||
this.Resize += UcComboBoxMutiSelect_Resize;
|
||||
this.SizeChanged += UcComboBoxMutiSelect_SizeChanged;
|
||||
this.VisibleChanged += UcComboBoxMutiSelect_VisibleChanged;
|
||||
|
||||
this.ParentChanged += UcComboBoxMutiSelect_ParentChanged;
|
||||
this.Disposed += UcComboBoxMutiSelect_Disposed;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_Disposed(object sender, EventArgs e)
|
||||
{
|
||||
if (lblX != null)
|
||||
lblX.Dispose();
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_ParentChanged(object sender, EventArgs e)
|
||||
{
|
||||
//lblX.Parent.Controls.Remove(lblX);
|
||||
//lblX.Dispose();
|
||||
//lblX = null;
|
||||
if (this != null && !this.IsDisposed && this.Parent != null)
|
||||
{
|
||||
this.GetParentNotTable().Controls.Add(lblX);
|
||||
UpdateClearLabel();
|
||||
}
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (lblX != null && lblX.Visible != this.Visible)
|
||||
lblX.Visible = this.Visible;
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateClearLabel();
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_Resize(object sender, EventArgs e)
|
||||
{
|
||||
UpdateClearLabel();
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_Move(object sender, EventArgs e)
|
||||
{
|
||||
UpdateClearLabel();
|
||||
}
|
||||
|
||||
private void UpdateClearLabel()
|
||||
{
|
||||
if (lblX == null || lblX.Disposing || lblX.IsDisposed)
|
||||
{
|
||||
lblX = new Label();
|
||||
lblX.Click += LblX_Click;
|
||||
//lblX.BorderStyle = BorderStyle.FixedSingle;
|
||||
lblX.Text = "×";
|
||||
lblX.ForeColor = Color.FromArgb(63, 126, 255);
|
||||
lblX.BackColor = this.BackColor;
|
||||
lblX.AutoSize = false;
|
||||
//lblX.AutoSize = true;
|
||||
//lblX.Width = 17;
|
||||
lblX.Width = 15;
|
||||
lblX.Height = 19;
|
||||
lblX.SendToBack();
|
||||
//Form form = this.FindForm();
|
||||
//form.Controls.Add(lblX);
|
||||
var p = this.GetParentNotTable();
|
||||
if (p != null)
|
||||
p.Controls.Add(lblX);
|
||||
}
|
||||
Point relativeLocation = this.GetRelativePosition(this.GetParentNotTable());
|
||||
lblX.Location = new Point(relativeLocation.X + this.Width - 19 - lblX.Width, relativeLocation.Y + (this.Height - lblX.Height) / 2);
|
||||
lblX.Visible = this.Visible;
|
||||
lblX.BringToFront();
|
||||
}
|
||||
|
||||
private void LblX_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.lblX.Text == "×")
|
||||
{
|
||||
this.lblX.Text = "↶";
|
||||
this.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lblX.Text = "×";
|
||||
this.Text = DefaultText;
|
||||
}
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_DropDownClosed(object sender, EventArgs e)
|
||||
{
|
||||
if (checkedListBox != null)
|
||||
{
|
||||
var parentForm = this.FindForm();
|
||||
Point mousePosition = parentForm.PointToClient(Cursor.Position);
|
||||
Point relativeLocation = checkedListBox.GetRelativePosition();
|
||||
|
||||
if (mousePosition.X < relativeLocation.X || mousePosition.X > relativeLocation.X + checkedListBox.Width ||
|
||||
mousePosition.Y < relativeLocation.Y || mousePosition.Y > relativeLocation.Y + checkedListBox.Height)
|
||||
{
|
||||
checkedListBox.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UcComboBoxMutiSelect_DropDown(object sender, EventArgs e)
|
||||
{
|
||||
var parentForm = this.FindForm();
|
||||
|
||||
if (checkedListBox == null)
|
||||
{
|
||||
checkedListBox = new CheckedListBox();
|
||||
checkedListBox.Visible = false;
|
||||
checkedListBox.CheckOnClick = true;
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
checkedListBox.MouseLeave += checkedListBox_MouseLeave;
|
||||
checkedListBox.MouseEnter += CheckedListBox_MouseEnter;
|
||||
checkedListBox.MouseMove += CheckedListBox_MouseMove;
|
||||
//checkedListBox.MouseUp += new MouseEventHandler(checkedListBox_MouseUp);
|
||||
|
||||
parentForm.Controls.Add(checkedListBox);
|
||||
}
|
||||
|
||||
string str1 = string.Join(",", this.Items.Cast<object>().Select(o => o.ParseToString()));
|
||||
string str2 = string.Join(",", this.checkedListBox.Items.Cast<object>().Select(o => o.ParseToString()));
|
||||
if (str1 != str2)
|
||||
{
|
||||
checkedListBox.Items.Clear();
|
||||
if (Items.Count > 0)
|
||||
checkedListBox.ItemCheck -= checkedListBox_ItemCheck;
|
||||
foreach (var item in this.Items)
|
||||
{
|
||||
if (Items[Items.Count - 1] == item)
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
|
||||
checkedListBox.Items.Add(item.ParseToString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// 防止一起设置每次都要重新拼接字符串
|
||||
if (checkedListBox.Items.Count > 0)
|
||||
checkedListBox.ItemCheck -= checkedListBox_ItemCheck;
|
||||
for (int index = 0; index < checkedListBox.Items.Count; index++)
|
||||
{
|
||||
if (index == checkedListBox.Items.Count - 1)
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
|
||||
var item = checkedListBox.Items[index];
|
||||
if (this.Text == DefaultText || this.Text.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList().Contains(item.ParseToString()))
|
||||
checkedListBox.SetItemChecked(index, true);
|
||||
else
|
||||
checkedListBox.SetItemChecked(index, false);
|
||||
}
|
||||
|
||||
// 计算宽度
|
||||
int maxItemWidth = 0;
|
||||
for (int index = 0; index < checkedListBox.Items.Count; index++)
|
||||
{
|
||||
var wth = TextRenderer.MeasureText(checkedListBox.Items[index].ToString(), checkedListBox.Font).Width + 40;
|
||||
if (wth > maxItemWidth)
|
||||
maxItemWidth = wth;
|
||||
}
|
||||
|
||||
checkedListBox.SendToBack();
|
||||
checkedListBox.Visible = true;
|
||||
// 确定弹出列表框的大小和位置
|
||||
//checkedListBox.Size = new Size(Math.Max(80, this.Width), Math.Min(300, checkedListBox.PreferredHeight));
|
||||
checkedListBox.Size = new Size(Math.Max(this.Width, maxItemWidth), Math.Min(300, checkedListBox.PreferredHeight));
|
||||
Point relativeLocation = this.GetRelativePosition();
|
||||
if (parentForm.Height - relativeLocation.Y >= this.Height + checkedListBox.Size.Height + 20)
|
||||
relativeLocation = new Point(relativeLocation.X, relativeLocation.Y + this.Height);
|
||||
else
|
||||
relativeLocation = new Point(relativeLocation.X, relativeLocation.Y - checkedListBox.Size.Height);
|
||||
checkedListBox.Location = relativeLocation;
|
||||
checkedListBox.BringToFront();
|
||||
|
||||
//parentForm.ActiveControl = checkedListBox;
|
||||
//checkedListBox.Focus();
|
||||
|
||||
}
|
||||
|
||||
private void CheckedListBox_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
//this.DropDownClosed -= UcComboBoxMutiSelect_DropDownClosed;
|
||||
}
|
||||
|
||||
private void CheckedListBox_MouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
//this.DropDownClosed -= UcComboBoxMutiSelect_DropDownClosed;
|
||||
}
|
||||
|
||||
private void checkedListBox_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
////this.DropDownClosed += UcComboBoxMutiSelect_DropDownClosed;
|
||||
////统计选取的项目
|
||||
//string str = "";
|
||||
//for (int i = 0; i < checkedListBox.Items.Count; i++)
|
||||
//{
|
||||
// if (checkedListBox.GetItemChecked(i))
|
||||
// {
|
||||
// str += $"{checkedListBox.Items[i].ParseToString()};";
|
||||
// }
|
||||
//}
|
||||
//this.Text = str;
|
||||
checkedListBox.Visible = false;
|
||||
this.OnDropDownClosed(null);
|
||||
}
|
||||
|
||||
private void checkedListBox_ItemCheck(object sender, EventArgs e)
|
||||
{
|
||||
//统计选取的项目
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
string str = "";
|
||||
for (int i = 0; i < checkedListBox.Items.Count; i++)
|
||||
{
|
||||
if (checkedListBox.GetItemChecked(i))
|
||||
{
|
||||
str += $"{checkedListBox.Items[i].ParseToString()};";
|
||||
}
|
||||
}
|
||||
this.Text = str.Trim(';');
|
||||
|
||||
|
||||
string str1 = string.Join(";", this.Items.Cast<object>().Select(o => o.ParseToString()));
|
||||
if (this.Text.Trim(';') == str1)
|
||||
{
|
||||
this.Text = this.DefaultText;
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcComboBoxMutiSelect
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public partial class UcDataGridViewCheckBoxColumn : DataGridViewCheckBoxColumn
|
||||
{
|
||||
public UcDataGridViewCheckBoxColumn()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public UcDataGridViewCheckBoxColumn(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcDataGridViewCheckBoxColumn
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// 可以改变边框颜色的groupbox
|
||||
/// </summary>
|
||||
public partial class UcGroupBoxEx : GroupBox
|
||||
{
|
||||
private Color _BorderColor = Color.FromArgb(33, 202, 99);
|
||||
private GroupBoxBorderStyle _BorderStyle = GroupBoxBorderStyle.ROUND;
|
||||
|
||||
[Browsable(true), Description("边框颜色"), Category("自定义分组")]
|
||||
public Color BorderColor
|
||||
{
|
||||
get { return _BorderColor; }
|
||||
set
|
||||
{
|
||||
_BorderColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(true), Description("边框样式"), Category("自定义分组")]
|
||||
public GroupBoxBorderStyle BorderStyle
|
||||
{
|
||||
get { return _BorderStyle; }
|
||||
set
|
||||
{
|
||||
_BorderStyle = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public UcGroupBoxEx()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public UcGroupBoxEx(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写OnPaint绘制自定义效果
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
e.Graphics.Clear(this.BackColor);
|
||||
// 绘制字体
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // 或者 AntiAliasGridFit // 平滑字体
|
||||
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), 10, 1);
|
||||
// 计算文本大小
|
||||
var vSize = e.Graphics.MeasureString(this.Text, this.Font);
|
||||
Pen vPen = new Pen(this._BorderColor);
|
||||
// 绘制矩形
|
||||
if (_BorderStyle == GroupBoxBorderStyle.SQUARE)
|
||||
{
|
||||
e.Graphics.DrawLine(vPen, 2, vSize.Height / 2, 8, vSize.Height / 2); // 标题左侧
|
||||
e.Graphics.DrawLine(vPen, vSize.Width + 8, vSize.Height / 2, this.Width - 3, vSize.Height / 2); // 标题右侧
|
||||
e.Graphics.DrawLine(vPen, 2, vSize.Height / 2, 2, this.Height - 3); // 左侧
|
||||
e.Graphics.DrawLine(vPen, 2, this.Height - 3, this.Width - 3, this.Height - 3); // 底部
|
||||
e.Graphics.DrawLine(vPen, this.Width - 3, vSize.Height / 2, this.Width - 3, this.Height - 3); // 右侧
|
||||
}
|
||||
// 绘制圆角矩形
|
||||
else
|
||||
{
|
||||
e.Graphics.DrawLine(vPen, 4, vSize.Height / 2, 8, vSize.Height / 2); // 标题左侧
|
||||
e.Graphics.DrawLine(vPen, vSize.Width + 8, vSize.Height / 2, this.Width - 5, vSize.Height / 2); // 标题右侧
|
||||
e.Graphics.DrawLine(vPen, 2, vSize.Height / 2 + 2, 2, this.Height - 5); // 左侧
|
||||
e.Graphics.DrawLine(vPen, 4, this.Height - 3, this.Width - 5, this.Height - 3); // 底部
|
||||
e.Graphics.DrawLine(vPen, this.Width - 3, vSize.Height / 2 + 2, this.Width - 3, this.Height - 5); // 右侧
|
||||
// 边角直线模拟圆角
|
||||
e.Graphics.DrawLine(vPen, 2, vSize.Height / 2 + 2, 4, vSize.Height / 2); // 左上角
|
||||
e.Graphics.DrawLine(vPen, this.Width - 5, vSize.Height / 2, this.Width - 3, vSize.Height / 2 + 2); // 右上角
|
||||
e.Graphics.DrawLine(vPen, this.Width - 3, this.Height - 5, this.Width - 5, this.Height - 3); // 右下角
|
||||
e.Graphics.DrawLine(vPen, 4, this.Height - 3, 2, this.Height - 5); // 左下角
|
||||
}
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
|
||||
try
|
||||
{
|
||||
// WM_NCCALCSIZE 0x0083 当计算某个窗口的客户区大小和位置时发送此消息
|
||||
// windows消息值表,可参考:http://hi.baidu.com/dooy/blog/item/0e770a24f70e3b2cd407421b.html
|
||||
if (m.Msg == 0x83)
|
||||
{
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public enum GroupBoxBorderStyle
|
||||
{
|
||||
ROUND,
|
||||
SQUARE,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcGroupBoxEx
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public partial class UcTabControl : TabControl
|
||||
{
|
||||
public UcTabControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
base.SetStyle(
|
||||
ControlStyles.UserPaint | // 控件将自行绘制,而不是通过操作系统来绘制
|
||||
ControlStyles.OptimizedDoubleBuffer | // 该控件首先在缓冲区中绘制,而不是直接绘制到屏幕上,这样可以减少闪烁
|
||||
ControlStyles.AllPaintingInWmPaint | // 控件将忽略 WM_ERASEBKGND 窗口消息以减少闪烁
|
||||
ControlStyles.ResizeRedraw | // 在调整控件大小时重绘控件
|
||||
ControlStyles.SupportsTransparentBackColor, // 控件接受 alpha 组件小于 255 的 BackColor 以模拟透明
|
||||
true); // 设置以上值为 true
|
||||
base.UpdateStyles();
|
||||
//this.SizeMode = TabSizeMode.Fixed;
|
||||
|
||||
this.MouseDown += UcTabControl_MouseDown;
|
||||
}
|
||||
|
||||
private void UcTabControl_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (this.TabCount == 0)
|
||||
return;
|
||||
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (!showCloseButton)
|
||||
return;
|
||||
|
||||
int x = e.X, y = e.Y;
|
||||
Rectangle rect = this.GetTabRect(this.SelectedIndex);
|
||||
Rectangle closeRect = new Rectangle(rect.X + rect.Width - 16, rect.Y + rect.Height / 2 - 4, 8, 8);
|
||||
|
||||
if (x >= closeRect.X && y >= closeRect.Y && x <= closeRect.X + closeRect.Width && y <= closeRect.Y + closeRect.Height)
|
||||
{
|
||||
this.TabPages.Remove(this.SelectedTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color backgroundColor = Color.FromArgb(251, 251, 251);
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab控件背景")]
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return backgroundColor; }
|
||||
set
|
||||
{
|
||||
backgroundColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabSelectColor = Color.Red;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab选中颜色")]
|
||||
public Color TabSelectColor
|
||||
{
|
||||
get { return tabSelectColor; }
|
||||
set
|
||||
{
|
||||
tabSelectColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabTextColor = Color.Gray;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab选中颜色")]
|
||||
public Color TabTextColor
|
||||
{
|
||||
get { return tabTextColor; }
|
||||
set
|
||||
{
|
||||
tabTextColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabSelectTextColor = Color.Gray;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab选中颜色")]
|
||||
public Color TabSelectTextColor
|
||||
{
|
||||
get { return tabSelectTextColor; }
|
||||
set
|
||||
{
|
||||
tabSelectTextColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool showCloseButton = false;
|
||||
[Browsable(true), Category("自定义分组"), Description("显示关闭页面按钮")]
|
||||
public bool ShowCloseButton
|
||||
{
|
||||
get { return showCloseButton; }
|
||||
set
|
||||
{
|
||||
showCloseButton = value;
|
||||
|
||||
if (showCloseButton)
|
||||
this.Padding = new Point(10, this.Padding.Y);
|
||||
else
|
||||
this.Padding = new Point(6, this.Padding.Y);
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
#region 去掉或减小TabControl的边框(去掉的话+-3)
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if ((m.Msg == TCM_ADJUSTRECT))
|
||||
{
|
||||
RECT rc = (RECT)m.GetLParam(typeof(RECT));
|
||||
//Adjust these values to suit, dependant upon Appearance
|
||||
rc.Left -= 2;
|
||||
rc.Right += 0;
|
||||
rc.Top -= 0;
|
||||
rc.Bottom += 0;
|
||||
Marshal.StructureToPtr(rc, m.LParam, true);
|
||||
}
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
private const Int32 TCM_FIRST = 0x1300;
|
||||
private const Int32 TCM_ADJUSTRECT = (TCM_FIRST + 40);
|
||||
private struct RECT
|
||||
{
|
||||
public Int32 Left;
|
||||
public Int32 Top;
|
||||
public Int32 Right;
|
||||
public Int32 Bottom;
|
||||
}
|
||||
#endregion
|
||||
|
||||
Size oldSize = new Size();
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (TabPages.Count > 0 && oldSize.Width != this.Size.Width && this.SizeMode == TabSizeMode.Fixed)
|
||||
{
|
||||
//this.SizeMode = TabSizeMode.Fixed;
|
||||
this.ItemSize = new Size((int)Math.Floor(1.0 * (this.Width - 4) / TabPages.Count), 40);
|
||||
oldSize.Width = this.Size.Width;
|
||||
}
|
||||
|
||||
// 绘制背景
|
||||
e.Graphics.FillRectangle(new SolidBrush(backgroundColor), new RectangleF(0, 0, this.Width, this.Height));
|
||||
|
||||
// 绘制边框
|
||||
//e.Graphics.DrawRectangle(new Pen(backgroundColor), 0, 0, this.Width, this.Height);
|
||||
//e.Graphics.DrawLine(new Pen(tabSelectColor), 2, this.GetTabRect(0).Bottom, this.Width - 6, this.GetTabRect(0).Bottom);
|
||||
|
||||
// 绘制tab控件
|
||||
for (int i = 0; i < this.TabCount; i++)
|
||||
{
|
||||
// Calculate text position
|
||||
Rectangle bounds = this.GetTabRect(i);
|
||||
PointF textPoint = new PointF();
|
||||
SizeF textSize = TextRenderer.MeasureText(this.TabPages[i].Text, this.Font);
|
||||
// 加上每个标签的左偏移量X
|
||||
textPoint.X = bounds.X + (bounds.Width - textSize.Width) / 2;
|
||||
textPoint.Y = bounds.Y + (bounds.Height - textSize.Height) / 2;
|
||||
if (showCloseButton)
|
||||
textPoint.X -= 5;
|
||||
// 绘制标题
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
if (this.SelectedIndex == i)
|
||||
e.Graphics.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(TabSelectTextColor), textPoint.X, textPoint.Y);
|
||||
else
|
||||
e.Graphics.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(tabTextColor), textPoint.X, textPoint.Y);
|
||||
|
||||
// 绘制tab框
|
||||
//e.Graphics.DrawRectangle(Pens.Red, this.GetTabRect(i));
|
||||
if (this.SelectedIndex == i)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
e.Graphics.DrawLine(new Pen(tabSelectColor),
|
||||
new Point(this.GetTabRect(i).Left + 0, this.GetTabRect(i).Bottom - j),
|
||||
new Point(this.GetTabRect(i).Right - 5, this.GetTabRect(i).Bottom - j));
|
||||
}
|
||||
|
||||
// 绘制关闭按钮
|
||||
if (showCloseButton)
|
||||
{
|
||||
using (Pen pen = new Pen(Color.Gray, 1.4f))
|
||||
{
|
||||
Point p1 = new Point(bounds.X + bounds.Width - 15, bounds.Y + bounds.Height / 2 - 3);
|
||||
Point p2 = new Point(bounds.X + bounds.Width - 9, bounds.Y + bounds.Height / 2 + 3);
|
||||
e.Graphics.DrawLine(pen, p1, p2);
|
||||
|
||||
Point p3 = new Point(bounds.X + bounds.Width - 9, bounds.Y + bounds.Height / 2 - 3);
|
||||
Point p4 = new Point(bounds.X + bounds.Width - 15, bounds.Y + bounds.Height / 2 + 3);
|
||||
e.Graphics.DrawLine(pen, p3, p4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcTabControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
public partial class UcTabControlMetro : TabControl
|
||||
{
|
||||
public UcTabControlMetro()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
base.SetStyle(
|
||||
ControlStyles.UserPaint | // 控件将自行绘制,而不是通过操作系统来绘制
|
||||
ControlStyles.OptimizedDoubleBuffer | // 该控件首先在缓冲区中绘制,而不是直接绘制到屏幕上,这样可以减少闪烁
|
||||
ControlStyles.AllPaintingInWmPaint | // 控件将忽略 WM_ERASEBKGND 窗口消息以减少闪烁
|
||||
ControlStyles.ResizeRedraw | // 在调整控件大小时重绘控件
|
||||
ControlStyles.SupportsTransparentBackColor, // 控件接受 alpha 组件小于 255 的 BackColor 以模拟透明
|
||||
true); // 设置以上值为 true
|
||||
base.UpdateStyles();
|
||||
//this.SizeMode = TabSizeMode.Fixed;
|
||||
}
|
||||
|
||||
private Color backgroundColor = Color.FromArgb(251, 251, 251);
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab控件背景")]
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return backgroundColor; }
|
||||
set
|
||||
{
|
||||
backgroundColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color borderColor = Color.FromArgb(0, 174, 157);
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab控件边框颜色")]
|
||||
public Color BorderColor
|
||||
{
|
||||
get { return borderColor; }
|
||||
set
|
||||
{
|
||||
borderColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabSelectColor = Color.Red;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab选中颜色")]
|
||||
public Color TabSelectColor
|
||||
{
|
||||
get { return tabSelectColor; }
|
||||
set
|
||||
{
|
||||
tabSelectColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabSelectTextColor = Color.Gray;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab选中文字颜色")]
|
||||
public Color TabSelectTextColor
|
||||
{
|
||||
get { return tabSelectTextColor; }
|
||||
set
|
||||
{
|
||||
tabSelectTextColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color tabUnSelectTextColor = Color.White;
|
||||
[Browsable(true), Category("自定义分组"), Description("Tab未选中文字颜色")]
|
||||
public Color TabUnSelectTextColor
|
||||
{
|
||||
get { return tabUnSelectTextColor; }
|
||||
set
|
||||
{
|
||||
tabUnSelectTextColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool showCloseButton = false;
|
||||
[Browsable(true), Category("自定义分组"), Description("显示关闭页面按钮")]
|
||||
public bool ShowCloseButton
|
||||
{
|
||||
get { return showCloseButton; }
|
||||
set
|
||||
{
|
||||
showCloseButton = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
Size oldSize = new Size();
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (TabPages.Count > 0 && oldSize.Width != this.Size.Width && this.SizeMode == TabSizeMode.Fixed)
|
||||
{
|
||||
//this.SizeMode = TabSizeMode.Fixed;
|
||||
this.ItemSize = new Size((int)Math.Floor(1.0 * (this.Width - 4) / TabPages.Count), 40);
|
||||
oldSize.Width = this.Size.Width;
|
||||
}
|
||||
|
||||
// 绘制背景
|
||||
e.Graphics.FillRectangle(new SolidBrush(backgroundColor), new RectangleF(0, 0, this.Width, this.Height));
|
||||
|
||||
// 绘制边框
|
||||
int startX = this.Margin.Left;
|
||||
int startY = this.Margin.Top;
|
||||
if (this.TabCount > 0)
|
||||
{
|
||||
startX = this.GetTabRect(0).Top;
|
||||
startY = this.GetTabRect(0).Bottom;
|
||||
}
|
||||
e.Graphics.DrawRectangle(new Pen(tabSelectColor), startX, startY, this.Width - this.Margin.Right - startX, this.Height - this.Margin.Bottom - startY);
|
||||
|
||||
// 绘制tab控件
|
||||
for (int i = 0; i < this.TabCount; i++)
|
||||
{
|
||||
// 计算tab标题位置
|
||||
Rectangle bounds = this.GetTabRect(i);
|
||||
PointF textPoint = new PointF();
|
||||
SizeF textSize = TextRenderer.MeasureText(this.TabPages[i].Text, this.Font);
|
||||
// 加上每个标签的左偏移量X
|
||||
textPoint.X = bounds.X + (bounds.Width - textSize.Width) / 2;
|
||||
textPoint.Y = bounds.Y + (bounds.Height - textSize.Height) / 2;
|
||||
|
||||
// 当前选中的tab
|
||||
if (this.SelectedIndex == i)
|
||||
{
|
||||
// 绘制tab框
|
||||
var rect = this.GetTabRect(i);
|
||||
// 底部和背景色相同
|
||||
e.Graphics.DrawLine(new Pen(backgroundColor), new Point(rect.Left, rect.Bottom), new Point(rect.Right, rect.Bottom));
|
||||
e.Graphics.DrawLine(new Pen(tabSelectColor), new Point(rect.Left, rect.Bottom), new Point(rect.Left, rect.Top));
|
||||
e.Graphics.DrawLine(new Pen(tabSelectColor), new Point(rect.Left, rect.Top), new Point(rect.Right, rect.Top));
|
||||
e.Graphics.DrawLine(new Pen(tabSelectColor), new Point(rect.Right, rect.Top), new Point(rect.Right, rect.Bottom));
|
||||
// 绘制tab标题文字
|
||||
//e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
e.Graphics.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(tabSelectTextColor), textPoint.X, textPoint.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 绘制tab框
|
||||
e.Graphics.FillRectangle(new SolidBrush(tabSelectColor), this.GetTabRect(i));
|
||||
// 绘制tab标题文字
|
||||
//e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
e.Graphics.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(tabUnSelectTextColor), textPoint.X, textPoint.Y);
|
||||
}
|
||||
|
||||
// 绘制关闭按钮
|
||||
if (showCloseButton)
|
||||
{
|
||||
using (Pen pen = new Pen(Color.Gray, 1f))
|
||||
{
|
||||
Point p1 = new Point(bounds.X + 10, bounds.Y + 10);
|
||||
Point p2 = new Point(bounds.X + bounds.Width - 10, bounds.Y + bounds.Height - 10);
|
||||
e.Graphics.DrawLine(pen, p1, p2);
|
||||
|
||||
Point p3 = new Point(bounds.X + 10, bounds.Y + bounds.Height - 10);
|
||||
Point p4 = new Point(bounds.X + bounds.Width - 10, bounds.Y + 10);
|
||||
e.Graphics.DrawLine(pen, p3, p4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcTabControlMetro
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,769 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Threading;
|
||||
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// 基于树视图的任务控件
|
||||
/// </summary>
|
||||
public partial class UcTreeView : TreeView
|
||||
{
|
||||
#region //construckor
|
||||
/// <summary>
|
||||
/// 自定义树视图控件构造函数
|
||||
/// </summary>
|
||||
public UcTreeView()
|
||||
{
|
||||
FullRowSelect = true;
|
||||
ShowLines = true;
|
||||
// 开启双缓冲等
|
||||
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.EnableNotifyMessage | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.DrawMode = TreeViewDrawMode.OwnerDrawAll;
|
||||
this.ItemHeight = 32;
|
||||
this.ShowLines = true;
|
||||
this.AfterExpand += UserTreeView_AfterExpand;
|
||||
this.AfterSelect += UserTreeView_AfterSelect;
|
||||
this.Layout += UserTreeView_Layout;
|
||||
if (Properties.Resources.ResourceManager.GetObject("tree_default_icon_select") != null)
|
||||
defaultNodeImageSelect = (Bitmap)Properties.Resources.ResourceManager.GetObject("tree_default_icon_select");
|
||||
if (Properties.Resources.ResourceManager.GetObject("tree_default_icon") != null)
|
||||
defaultNodeImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("tree_default_icon");
|
||||
}
|
||||
|
||||
protected override void OnNotifyMessage(Message m)
|
||||
{
|
||||
if (m.Msg != 0x14)
|
||||
{
|
||||
base.OnNotifyMessage(m);
|
||||
}
|
||||
}
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams cp = base.CreateParams;
|
||||
cp.ExStyle |= 0x02000000;
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
|
||||
private void UserTreeView_AfterSelect(object sender, TreeViewEventArgs e)
|
||||
{
|
||||
if (e.Node.Parent != null)
|
||||
dicSelectNodeId[e.Node.Parent] = e.Node;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region //event
|
||||
// 定义委托
|
||||
public delegate void NodeGroupClickHandle(object sender, TreeViewEventArgs e);
|
||||
|
||||
// 定义事件
|
||||
public event NodeGroupClickHandle NodeGroupClick;
|
||||
|
||||
// 执行事件
|
||||
protected virtual void OnNodeGroupClick(TreeViewEventArgs e)
|
||||
{
|
||||
if (NodeGroupClick != null)
|
||||
{
|
||||
NodeGroupClick(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UserTreeView_Layout(object sender, LayoutEventArgs e)
|
||||
{
|
||||
if (!DesignMode)
|
||||
{
|
||||
foreach (TreeNode node in this.Nodes)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
if (allNodes.Contains(node) == false)
|
||||
allNodes.Add(node);
|
||||
}
|
||||
foreach (TreeNode childNode in node.Nodes)
|
||||
{
|
||||
if (node == null)
|
||||
continue;
|
||||
if (!dicNodeImageSelect.Keys.Contains(childNode))
|
||||
{
|
||||
// 获取图标
|
||||
if (Properties.Resources.ResourceManager.GetObject("tree_" + childNode.Text + "_select") != null)
|
||||
{
|
||||
var bitmap = (Bitmap)Properties.Resources.ResourceManager.GetObject("tree_" + childNode.Text + "_select");
|
||||
dicNodeImageSelect[childNode] = bitmap;
|
||||
}
|
||||
}
|
||||
if (!dicNodeImage.Keys.Contains(childNode))
|
||||
{
|
||||
// 获取图标
|
||||
if (Properties.Resources.ResourceManager.GetObject("tree_" + childNode.Text) != null)
|
||||
{
|
||||
var bitmap = (Bitmap)Properties.Resources.ResourceManager.GetObject("tree_" + childNode.Text);
|
||||
dicNodeImage[childNode] = bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UserTreeView_AfterExpand(object sender, TreeViewEventArgs e)
|
||||
{
|
||||
BeginUpdate();
|
||||
if (HideCollapsedGroup && !DesignMode)
|
||||
{
|
||||
for (int i = 0; i < this.Nodes.Count; i++)
|
||||
{
|
||||
if (e.Node != this.Nodes[i])
|
||||
{
|
||||
this.Nodes.Remove(this.Nodes[i]);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (TreeNode node in this.AllNodes)
|
||||
{
|
||||
if (node == null)
|
||||
continue;
|
||||
|
||||
if (node != e.Node)
|
||||
{
|
||||
node.Collapse(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.SelectedNode == null || this.SelectedNode.Parent == node)
|
||||
continue;
|
||||
else if (dicSelectNodeId.Keys.Contains(node))
|
||||
this.SelectedNode = dicSelectNodeId[node];
|
||||
else if (node.Nodes.Count > 0)
|
||||
this.SelectedNode = node.Nodes[0];
|
||||
}
|
||||
}
|
||||
EndUpdate();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region //field & property
|
||||
private Bitmap defaultNodeImage;
|
||||
private Bitmap defaultNodeImageSelect;
|
||||
private List<TreeNode> lstTreeNode = new List<TreeNode>();
|
||||
private Dictionary<TreeNode, TreeNode> dicSelectNodeId = new Dictionary<TreeNode, TreeNode>();
|
||||
private Dictionary<TreeNode, Bitmap> dicNodeImage = new Dictionary<TreeNode, Bitmap>();
|
||||
private Dictionary<TreeNode, Bitmap> dicNodeImageSelect = new Dictionary<TreeNode, Bitmap>();
|
||||
/// <summary>
|
||||
/// 展开按扭的大小
|
||||
/// </summary>
|
||||
private Size ExpandButtonSize = new Size(16, 16);
|
||||
private Color _ExpandButtonColor = Color.FromArgb(255, 255, 255);
|
||||
/// <summary>
|
||||
/// 展开按扭颜色
|
||||
/// </summary>
|
||||
[Description("展开按扭颜色"), Category("UserProperty")]
|
||||
public Color ExpandButtonColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ExpandButtonColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_ExpandButtonColor != value)
|
||||
{
|
||||
_ExpandButtonColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
private Color _GroupBgColor = Color.FromArgb(249, 249, 249);
|
||||
/// <summary>
|
||||
/// 分组栏背景色
|
||||
/// </summary>
|
||||
[Description("分组栏背景色"), Category("UserProperty")]
|
||||
public Color GroupBgColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _GroupBgColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_GroupBgColor != value)
|
||||
{
|
||||
_GroupBgColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _ChildNodeSelectedBgColor = Color.FromArgb(34, 148, 203);
|
||||
/// <summary>
|
||||
/// 子节点选中背景色
|
||||
/// </summary>
|
||||
[Description("子节点选中背景色"), Category("UserProperty")]
|
||||
public Color ChildNodeSelectedBgColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._ChildNodeSelectedBgColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_ChildNodeSelectedBgColor != value)
|
||||
{
|
||||
_ChildNodeSelectedBgColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _GroupTitleColor = Color.FromArgb(80, 80, 80);
|
||||
/// <summary>
|
||||
/// 分组栏标题色
|
||||
/// </summary>
|
||||
[Description("分组栏标题色"), Category("UserProperty")]
|
||||
public Color GroupTitleColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _GroupTitleColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_GroupTitleColor != value)
|
||||
{
|
||||
_GroupTitleColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _OverForeColor = Color.FromArgb(235, 235, 235);
|
||||
/// <summary>
|
||||
/// 鼠标悬停色
|
||||
/// </summary>
|
||||
[Description("鼠标悬停色"), Category("UserProperty")]
|
||||
public Color OverForeColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _OverForeColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_OverForeColor != value)
|
||||
{
|
||||
_OverForeColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Font groupFont = new Font("宋体", 10.5f);
|
||||
/// <summary>
|
||||
/// 组标题字体样式
|
||||
/// </summary>
|
||||
[Description("组标题字体样式"), Category("UserProperty")]
|
||||
public Font GroupFont
|
||||
{
|
||||
get
|
||||
{
|
||||
return groupFont;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (groupFont != value)
|
||||
{
|
||||
groupFont = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _HideCollpasedGroup = false;
|
||||
[Description("隐藏折叠的组"), Category("UserProperty")]
|
||||
public bool HideCollapsedGroup
|
||||
{
|
||||
get
|
||||
{
|
||||
return _HideCollpasedGroup;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_HideCollpasedGroup != value)
|
||||
{
|
||||
_HideCollpasedGroup = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 节点高度
|
||||
/// </summary>
|
||||
public new int ItemHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.ItemHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (base.ItemHeight != value && value >= 20)
|
||||
{
|
||||
base.ItemHeight = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<TreeNode> allNodes = new List<TreeNode>();
|
||||
/// <summary>
|
||||
/// 所有节点列表
|
||||
/// </summary>
|
||||
public List<TreeNode> AllNodes { get { return allNodes; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region //override
|
||||
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
|
||||
{
|
||||
//base.OnDrawNode(e);
|
||||
DrawNodeItem(e);
|
||||
}
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if (m.Msg == 0x0201)//单击
|
||||
{
|
||||
int wparam = m.LParam.ToInt32();
|
||||
Point point = new Point(
|
||||
LOWORD(wparam),
|
||||
HIWORD(wparam));
|
||||
//point = PointToClient(point);
|
||||
TreeNode tn = this.GetNodeAt(point);
|
||||
if (tn == null)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
return;
|
||||
}
|
||||
if (tn.Level == 0)
|
||||
{
|
||||
if (tn.IsExpanded)
|
||||
{
|
||||
//tn.Collapse();
|
||||
}
|
||||
else
|
||||
{
|
||||
tn.Expand();
|
||||
}
|
||||
m.Result = IntPtr.Zero;
|
||||
OnNodeGroupClick(new TreeViewEventArgs(tn, TreeViewAction.ByMouse));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
//tn.IsSelected = true;
|
||||
//this.SelectedNode = tn;
|
||||
}
|
||||
this.SelectedNode = tn;
|
||||
}
|
||||
else if (m.Msg == 0x0203)//双击
|
||||
{
|
||||
int wparam = m.LParam.ToInt32();
|
||||
Point point = new Point(
|
||||
LOWORD(wparam),
|
||||
HIWORD(wparam));
|
||||
//point = PointToClient(point);
|
||||
TreeNode tn = this.GetNodeAt(point);
|
||||
if (tn == null)
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
return;
|
||||
}
|
||||
if (tn.Level == 0)
|
||||
{
|
||||
m.Result = IntPtr.Zero;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
this.SelectedNode = tn;
|
||||
}
|
||||
else if (m.Msg == 0x0200)//鼠标移动
|
||||
{
|
||||
try
|
||||
{
|
||||
int wparam = m.LParam.ToInt32();
|
||||
Point point = new Point(
|
||||
LOWORD(wparam),
|
||||
HIWORD(wparam));
|
||||
//point = PointToClient(point);
|
||||
TreeNode tn = this.GetNodeAt(point);
|
||||
if (tn == null)
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
// this.SelectedNode = null;
|
||||
base.WndProc(ref m);
|
||||
return;
|
||||
}
|
||||
Cursor = Cursors.Hand;
|
||||
//this.SelectedNode = tn;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (m.Msg == 0x02A3)//鼠标移出 WM_MOUSELEAVE = $02A3;
|
||||
{
|
||||
// this.SelectedNode = null;
|
||||
base.WndProc(ref m);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
//WM_LBUTTONDOWN = $0201
|
||||
//WM_LBUTTONDBLCLK = $0203;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region //private method
|
||||
/// <summary>
|
||||
/// 自定义绘制节点
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
private void DrawNodeItem(DrawTreeNodeEventArgs e)
|
||||
{
|
||||
TreeNode tn = e.Node;
|
||||
if (tn.Level == 0)
|
||||
{
|
||||
using (Graphics g = e.Graphics)
|
||||
{
|
||||
//g.Clear(this.BackColor); // 清空画布,完整重绘时才能使用
|
||||
//g.SmoothingMode = SmoothingMode.HighQuality; // 高质量
|
||||
//g.PixelOffsetMode = PixelOffsetMode.HighQuality; // 高像素偏移质量
|
||||
//绘制分组的背景
|
||||
//RenderBackgroundInternalRate(g,
|
||||
// e.Bounds,
|
||||
// GroupBgColor,
|
||||
// GroupBgColor,
|
||||
// Color.FromArgb(200, 255, 255, 255),
|
||||
// 0.45f,
|
||||
// true,
|
||||
// 300);
|
||||
int red = GroupBgColor.R;
|
||||
int green = GroupBgColor.G;
|
||||
int blue = GroupBgColor.B;
|
||||
if (red < 127) red += 15; else red -= 15;
|
||||
if (green < 127) green += 15; else green -= 15;
|
||||
if (blue < 127) blue += 15; else blue -= 15;
|
||||
var color = Color.FromArgb(red, green, blue);
|
||||
RenderBackgroundSolid(g, e.Bounds, color, color, color, false);
|
||||
//绘制展开按扭
|
||||
//g.FillEllipse(new SolidBrush(ExpandButtonColor), ExpandButtonBounds(e.Bounds));
|
||||
//g.DrawEllipse(new Pen(Color.LightGray), ExpandButtonBounds(e.Bounds));
|
||||
//Point p1;
|
||||
//Point p2;
|
||||
//Point p3;
|
||||
//if (tn.IsExpanded)
|
||||
//{
|
||||
// p1 = new Point(ExpandButtonBounds(e.Bounds).X + 3, ExpandButtonBounds(e.Bounds).Bottom - 4);
|
||||
// p2 = new Point(ExpandButtonBounds(e.Bounds).X + (ExpandButtonSize.Width) / 2, ExpandButtonBounds(e.Bounds).Top + 5);
|
||||
// p3 = new Point(ExpandButtonBounds(e.Bounds).Right - 3, ExpandButtonBounds(e.Bounds).Bottom - 4);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// p1 = new Point(ExpandButtonBounds(e.Bounds).X + 3, ExpandButtonBounds(e.Bounds).Y + 4);
|
||||
// p2 = new Point(ExpandButtonBounds(e.Bounds).X + (ExpandButtonSize.Width) / 2, ExpandButtonBounds(e.Bounds).Bottom - 5);
|
||||
// p3 = new Point(ExpandButtonBounds(e.Bounds).Right - 3, ExpandButtonBounds(e.Bounds).Y + 4);
|
||||
//}
|
||||
//GraphicsPath gp = new GraphicsPath();
|
||||
//gp.AddLine(p1, p2);
|
||||
//gp.AddLine(p2, p3);
|
||||
//g.DrawPath(new Pen(Color.FromArgb(255, 150, 0, 0), 2f), gp);
|
||||
|
||||
//绘制分组的文本
|
||||
TextRenderer.DrawText(g, e.Node.Text, this.GroupFont, GroupTitleBounds(e.Bounds), this.GroupTitleColor,
|
||||
TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
|
||||
}
|
||||
}
|
||||
else if (tn.Level == 1)
|
||||
{
|
||||
//e.DrawDefault = true;
|
||||
|
||||
using (Graphics g = e.Graphics)
|
||||
{
|
||||
#region 小奶猫增加权限后,无法自动绘制TreeNode图标,经调试确认,增加此段代码 by ttzhao 2020.7.1
|
||||
if (!dicNodeImageSelect.Keys.Contains(e.Node))
|
||||
{
|
||||
// 获取图标
|
||||
if (Properties.Resources.ResourceManager.GetObject(e.Node.Text + "_select") != null)
|
||||
{
|
||||
var bitmap = (Bitmap)Properties.Resources.ResourceManager.GetObject(e.Node.Text + "_select");
|
||||
dicNodeImageSelect[e.Node] = bitmap;
|
||||
}
|
||||
}
|
||||
if (!dicNodeImage.Keys.Contains(e.Node))
|
||||
{
|
||||
// 获取图标
|
||||
if (Properties.Resources.ResourceManager.GetObject(e.Node.Text) != null)
|
||||
{
|
||||
var bitmap = (Bitmap)Properties.Resources.ResourceManager.GetObject(e.Node.Text);
|
||||
dicNodeImage[e.Node] = bitmap;
|
||||
}
|
||||
}
|
||||
#endregion 小奶猫增加权限后,无法自动绘制TreeNode图标,经调试确认,增加此段代码 by ttzhao 2020.7.1
|
||||
|
||||
if (tn.IsSelected)
|
||||
{
|
||||
RenderBackgroundSolid(g, e.Bounds, ChildNodeSelectedBgColor, ChildNodeSelectedBgColor, ChildNodeSelectedBgColor, false);
|
||||
//TextRenderer.DrawText(g, e.Node.Text, new Font(this.Font.FontFamily.Name, this.Font.Size, FontStyle.Underline), e.Bounds, OverForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
||||
TextRenderer.DrawText(g, e.Node.Text, this.Font, ChildTitleBounds(e.Bounds), this.OverForeColor,
|
||||
TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
||||
|
||||
// 绘制图标
|
||||
if (dicNodeImageSelect.Keys.Contains(e.Node))
|
||||
g.DrawImage(dicNodeImageSelect[e.Node], new Rectangle(e.Bounds.X + 30, e.Bounds.Y + 8, 16, 16));
|
||||
else if (defaultNodeImageSelect != null)
|
||||
g.DrawImage(defaultNodeImageSelect, new Rectangle(e.Bounds.X + 30, e.Bounds.Y + 8, 16, 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderBackgroundSolid(g, e.Bounds, GroupBgColor, GroupBgColor, GroupBgColor, false);
|
||||
//TextRenderer.DrawText(g, e.Node.Text, this.Font, e.Bounds, this.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
||||
TextRenderer.DrawText(g, e.Node.Text, this.Font, ChildTitleBounds(e.Bounds), this.ForeColor,
|
||||
TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
|
||||
|
||||
// 绘制图标
|
||||
if (dicNodeImage.Keys.Contains(e.Node))
|
||||
g.DrawImage(dicNodeImage[e.Node], new Rectangle(e.Bounds.X + 30, e.Bounds.Y + 8, 16, 16));
|
||||
else if (defaultNodeImage != null)
|
||||
g.DrawImage(defaultNodeImage, new Rectangle(e.Bounds.X + 30, e.Bounds.Y + 8, 16, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 展开按扭区域 一级菜单后面的展开按钮
|
||||
/// </summary>
|
||||
/// <param name="childRect"></param>
|
||||
/// <returns></returns>
|
||||
private Rectangle ExpandButtonBounds(Rectangle childRect)
|
||||
{
|
||||
Rectangle lrect = new Rectangle(new Point(childRect.Right - ExpandButtonSize.Width * 3 / 2, (childRect.Height - ExpandButtonSize.Height) / 2 + childRect.Top), ExpandButtonSize);
|
||||
return lrect;
|
||||
}
|
||||
/// <summary>
|
||||
/// 取得分组标题绘制空间 一级菜单
|
||||
/// </summary>
|
||||
/// <param name="childRect"></param>
|
||||
/// <returns></returns>
|
||||
private Rectangle GroupTitleBounds(Rectangle childRect)
|
||||
{
|
||||
Rectangle lrect = childRect;
|
||||
lrect.Width -= ExpandButtonSize.Width * 3 / 2 + 20;
|
||||
//lrect.Offset(45, 0);
|
||||
lrect.Offset(12, 0);
|
||||
return lrect;
|
||||
}
|
||||
private Rectangle ChildTitleBounds(Rectangle rect)
|
||||
{
|
||||
Rectangle lrect = rect;
|
||||
lrect.Width -= 50;
|
||||
lrect.Offset(55, 0);
|
||||
return lrect;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region //draw
|
||||
internal void RenderBackgroundSolid(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, bool drawBorder)
|
||||
{
|
||||
if (drawBorder)
|
||||
{
|
||||
rect.Width--;
|
||||
rect.Height--;
|
||||
}
|
||||
using (SolidBrush brush = new SolidBrush(baseColor))
|
||||
{
|
||||
g.FillRectangle(brush, rect);
|
||||
}
|
||||
if (drawBorder)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
rect.Inflate(-1, -1);
|
||||
using (Pen pen = new Pen(innerBorderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor,
|
||||
float basePosition, bool drawBorder, LinearGradientMode mode)
|
||||
{
|
||||
if (drawBorder)
|
||||
{
|
||||
rect.Width--;
|
||||
rect.Height--;
|
||||
}
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
|
||||
{
|
||||
Color[] colors = new Color[4];
|
||||
colors[0] = GetColor(baseColor, 0, 35, 24, 9);
|
||||
colors[1] = GetColor(baseColor, 0, 13, 8, 3);
|
||||
colors[2] = baseColor;
|
||||
colors[3] = GetColor(baseColor, 0, 68, 69, 54);
|
||||
ColorBlend blend = new ColorBlend();
|
||||
blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
|
||||
blend.Colors = colors;
|
||||
brush.InterpolationColors = blend;
|
||||
g.FillRectangle(brush, rect);
|
||||
}
|
||||
if (baseColor.A > 80)
|
||||
{
|
||||
Rectangle rectTop = rect;
|
||||
if (mode == LinearGradientMode.Vertical)
|
||||
{
|
||||
rectTop.Height = (int)(rectTop.Height * basePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectTop.Width = (int)(rect.Width * basePosition);
|
||||
}
|
||||
using (SolidBrush brushAlpha =
|
||||
new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
|
||||
{
|
||||
g.FillRectangle(brushAlpha, rectTop);
|
||||
}
|
||||
}
|
||||
if (drawBorder)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
rect.Inflate(-1, -1);
|
||||
using (Pen pen = new Pen(innerBorderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal void RenderBackgroundInternalRate(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor,
|
||||
float basePosition, bool drawBorder, float rate)
|
||||
{
|
||||
if (drawBorder)
|
||||
{
|
||||
rect.Width--;
|
||||
rect.Height--;
|
||||
}
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, rate))
|
||||
{
|
||||
Color[] colors = new Color[4];
|
||||
colors[0] = GetColor(baseColor, 0, 35, 24, 9);
|
||||
colors[1] = GetColor(baseColor, 0, 13, 8, 3);
|
||||
colors[2] = baseColor;
|
||||
colors[3] = GetColor(baseColor, 0, 68, 69, 54);
|
||||
ColorBlend blend = new ColorBlend();
|
||||
blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
|
||||
blend.Colors = colors;
|
||||
brush.InterpolationColors = blend;
|
||||
g.FillRectangle(brush, rect);
|
||||
}
|
||||
if (baseColor.A > 80)
|
||||
{
|
||||
Rectangle rectTop = rect;
|
||||
if (true/*mode == LinearGradientMode.Vertical*/)
|
||||
{
|
||||
rectTop.Height = (int)(rectTop.Height * basePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectTop.Width = (int)(rect.Width * basePosition);
|
||||
}
|
||||
using (SolidBrush brushAlpha =
|
||||
new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
|
||||
{
|
||||
g.FillRectangle(brushAlpha, rectTop);
|
||||
}
|
||||
}
|
||||
if (drawBorder)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
rect.Inflate(-1, -1);
|
||||
using (Pen pen = new Pen(innerBorderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetColor(Color colorBase, int a, int r, int g, int b)
|
||||
{
|
||||
int a0 = colorBase.A;
|
||||
int r0 = colorBase.R;
|
||||
int g0 = colorBase.G;
|
||||
int b0 = colorBase.B;
|
||||
if (a + a0 > 255) { a = 255; } else { a = a + a0; }
|
||||
if (r + r0 > 255) { r = 255; } else { r = r + r0; }
|
||||
if (g + g0 > 255) { g = 255; } else { g = g + g0; }
|
||||
if (b + b0 > 255) { b = 255; } else { b = b + b0; }
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
private Color GetColor2(Color colorBase, int a, int r, int g, int b)
|
||||
{
|
||||
int a0 = colorBase.A;
|
||||
int r0 = colorBase.R;
|
||||
int g0 = colorBase.G;
|
||||
int b0 = colorBase.B;
|
||||
if (a + a0 > 255) { a = 255; } else { a = a + a0; }
|
||||
if (r0 - r < 0) { r = 0; } else { r = r0 - r; }
|
||||
if (g0 - g < 0) { g = 0; } else { g = g0 - g; }
|
||||
if (b0 - b < 0) { b = 0; } else { b = b0 - b; }
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static int LOWORD(int value)
|
||||
{
|
||||
return value & 0xFFFF;
|
||||
}
|
||||
|
||||
public static int HIWORD(int value)
|
||||
{
|
||||
return value >> 16;
|
||||
}
|
||||
|
||||
public void ExpandGroup(string groupName)
|
||||
{
|
||||
var node = this.AllNodes.FirstOrDefault(n => n.Name == groupName);
|
||||
if (node == null)
|
||||
return;
|
||||
BeginUpdate();
|
||||
if (!this.Nodes.Contains(node))
|
||||
this.Nodes.Insert(0, node);
|
||||
node.Expand();
|
||||
EndUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Work.UserComponents
|
||||
{
|
||||
partial class UcTreeView
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserControls
|
||||
{
|
||||
public partial class ButtonEx : Button
|
||||
{
|
||||
public ButtonEx()
|
||||
{
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.ForeColor = System.Drawing.Color.White;
|
||||
//this.Font = new System.Drawing.Font("华文宋体", 8.999999F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
Cursor = Cursors.Hand;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
this.UseVisualStyleBackColor = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不显示控件获焦提示
|
||||
/// </summary>
|
||||
protected override bool ShowFocusCues
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// 无边框的DataGridView单元格
|
||||
/// </summary>
|
||||
public class CustomDataGridViewTextBoxCell : DataGridViewTextBoxCell
|
||||
{
|
||||
private DataGridViewAdvancedBorderStyle _style;
|
||||
|
||||
public CustomDataGridViewTextBoxCell() : base()
|
||||
{
|
||||
_style = new DataGridViewAdvancedBorderStyle();
|
||||
_style.Bottom = DataGridViewAdvancedCellBorderStyle.None;
|
||||
_style.Top = DataGridViewAdvancedCellBorderStyle.None;
|
||||
_style.Left = DataGridViewAdvancedCellBorderStyle.None;
|
||||
_style.Right = DataGridViewAdvancedCellBorderStyle.None;
|
||||
}
|
||||
|
||||
public DataGridViewAdvancedBorderStyle AdvancedBorderStyle
|
||||
{
|
||||
get { return _style; }
|
||||
set
|
||||
{
|
||||
_style.Bottom = value.Bottom;
|
||||
_style.Top = value.Top;
|
||||
_style.Left = value.Left;
|
||||
_style.Right = value.Right;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
|
||||
{
|
||||
base.PaintBorder(graphics, clipBounds, bounds, cellStyle, _style);
|
||||
}
|
||||
|
||||
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
|
||||
{
|
||||
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, _style, paintParts);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserControls
|
||||
{
|
||||
public partial class StatusBarUserControl : UserControl
|
||||
{
|
||||
public int Factor = 5; // 进度条扩大倍数
|
||||
|
||||
public StatusBarUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void InitProgressBar()
|
||||
{
|
||||
pgbTaskProgress.Value = pgbTaskProgress.Minimum;
|
||||
pgbTaskProgress.Text = "0" + "/" + pgbTaskProgress.Maximum;
|
||||
}
|
||||
|
||||
public void UpdateProgressBar(int handleCount)
|
||||
{
|
||||
pgbTaskProgress.Text = handleCount + "/" + pgbTaskProgress.Maximum;
|
||||
pgbTaskProgress.Value = handleCount;
|
||||
}
|
||||
|
||||
public void UpdateProgressBarStatus(string text)
|
||||
{
|
||||
lblTaskStatus.Text = text;
|
||||
}
|
||||
|
||||
public void FinishProgressBar(string text)
|
||||
{
|
||||
lblTaskStatus.Text = text;
|
||||
pgbTaskProgress.Value = pgbTaskProgress.Maximum;
|
||||
}
|
||||
|
||||
public void CancelProgressBar(string text)
|
||||
{
|
||||
lblTaskStatus.Text = text;
|
||||
pgbTaskProgress.Value = pgbTaskProgress.Maximum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
namespace Work.UserControls
|
||||
{
|
||||
partial class StatusBarUserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.lblTaskStatus = new DevComponents.DotNetBar.LabelX();
|
||||
this.labelX19 = new DevComponents.DotNetBar.LabelX();
|
||||
this.pgbTaskProgress = new DevComponents.DotNetBar.Controls.ProgressBarX();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lblTaskStatus
|
||||
//
|
||||
this.lblTaskStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
//
|
||||
//
|
||||
//
|
||||
this.lblTaskStatus.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
|
||||
this.lblTaskStatus.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.lblTaskStatus.Location = new System.Drawing.Point(327, 2);
|
||||
this.lblTaskStatus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.lblTaskStatus.Name = "lblTaskStatus";
|
||||
this.lblTaskStatus.Size = new System.Drawing.Size(433, 18);
|
||||
this.lblTaskStatus.TabIndex = 24;
|
||||
this.lblTaskStatus.Text = "准备就绪";
|
||||
//
|
||||
// labelX19
|
||||
//
|
||||
this.labelX19.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
//
|
||||
//
|
||||
//
|
||||
this.labelX19.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
|
||||
this.labelX19.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.labelX19.Location = new System.Drawing.Point(282, 2);
|
||||
this.labelX19.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.labelX19.Name = "labelX19";
|
||||
this.labelX19.Size = new System.Drawing.Size(42, 18);
|
||||
this.labelX19.TabIndex = 23;
|
||||
this.labelX19.Text = "状态:";
|
||||
//
|
||||
// pgbTaskProgress
|
||||
//
|
||||
this.pgbTaskProgress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
//
|
||||
//
|
||||
//
|
||||
this.pgbTaskProgress.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
|
||||
this.pgbTaskProgress.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.pgbTaskProgress.Location = new System.Drawing.Point(3, 0);
|
||||
this.pgbTaskProgress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pgbTaskProgress.Name = "pgbTaskProgress";
|
||||
this.pgbTaskProgress.Size = new System.Drawing.Size(260, 22);
|
||||
this.pgbTaskProgress.TabIndex = 25;
|
||||
this.pgbTaskProgress.Text = "0/0";
|
||||
this.pgbTaskProgress.TextVisible = true;
|
||||
//
|
||||
// StatusBarUserControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.Controls.Add(this.pgbTaskProgress);
|
||||
this.Controls.Add(this.lblTaskStatus);
|
||||
this.Controls.Add(this.labelX19);
|
||||
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.Name = "StatusBarUserControl";
|
||||
this.Size = new System.Drawing.Size(773, 26);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
public DevComponents.DotNetBar.LabelX lblTaskStatus;
|
||||
private DevComponents.DotNetBar.LabelX labelX19;
|
||||
public DevComponents.DotNetBar.Controls.ProgressBarX pgbTaskProgress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,151 @@
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.UserControls
|
||||
{
|
||||
public partial class UcSplitPage : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否显示每页条数(启用每页条数功能)
|
||||
/// </summary>
|
||||
[Description("显示每页条数"), Category("UserProperty")]
|
||||
public bool IsShowPageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.cmbPageSize.Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (cmbPageSize.Visible != value)
|
||||
{
|
||||
this.lblPageSize.Visible = this.cmbPageSize.Visible = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int totalPage = 1;
|
||||
public int TotalPage
|
||||
{
|
||||
get { return totalPage; }
|
||||
set
|
||||
{
|
||||
if (TotalPage != value && value > 0)
|
||||
{
|
||||
totalPage = value;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.lblTotal.Text = "共 " + totalPage + " 页";
|
||||
}));
|
||||
}
|
||||
else
|
||||
this.lblTotal.Text = "共 " + totalPage + " 页";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int currentPage = 1;
|
||||
public int CurrentPage
|
||||
{
|
||||
get { return currentPage; }
|
||||
set
|
||||
{
|
||||
if (currentPage != value)
|
||||
{
|
||||
currentPage = value;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.lblPage.Text = "" + currentPage;
|
||||
}));
|
||||
}
|
||||
else
|
||||
this.lblPage.Text = "" + currentPage;
|
||||
}
|
||||
OnPageChange(this);
|
||||
}
|
||||
}
|
||||
|
||||
[Description("每页条数"), Category("UserProperty")]
|
||||
public int PageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int pageSize = 50;
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
}));
|
||||
}
|
||||
else
|
||||
pageSize = Math.Max(this.cmbPageSize.Text.ParseToInt(), 1);
|
||||
return pageSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.cmbPageSize.Text.ParseToInt() != value)
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
else
|
||||
this.cmbPageSize.Text = value.ParseToString();
|
||||
}
|
||||
//OnPageChange(this);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<object> PageChange;
|
||||
protected virtual void OnPageChange(object sender)
|
||||
{
|
||||
this.PageChange?.Invoke(sender);
|
||||
}
|
||||
|
||||
public UcSplitPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void pnlJump_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.txtJumpPage.Text.ParseToInt();
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
|
||||
}
|
||||
|
||||
private void btnPrev_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage - 1;
|
||||
this.CurrentPage = Math.Max(1, page);
|
||||
}
|
||||
|
||||
private void btnNext_Click(object sender, EventArgs e)
|
||||
{
|
||||
int page = this.CurrentPage + 1;
|
||||
this.CurrentPage = Math.Min(totalPage, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
|
||||
namespace Work.UserControls
|
||||
{
|
||||
partial class UcSplitPage
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnPrev = new DevComponents.DotNetBar.PanelEx();
|
||||
this.btnNext = new DevComponents.DotNetBar.PanelEx();
|
||||
this.lblPage = new System.Windows.Forms.Label();
|
||||
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.btnJump = new DevComponents.DotNetBar.PanelEx();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.txtJumpPage = new DevComponents.DotNetBar.Controls.TextBoxX();
|
||||
this.lblJump = new System.Windows.Forms.Label();
|
||||
this.lblTotal = new System.Windows.Forms.Label();
|
||||
this.lblPageSize = new System.Windows.Forms.Label();
|
||||
this.cmbPageSize = new System.Windows.Forms.ComboBox();
|
||||
this.flowLayoutPanel2.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnPrev
|
||||
//
|
||||
this.btnPrev.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.btnPrev.AutoSize = true;
|
||||
this.btnPrev.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
|
||||
this.btnPrev.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnPrev.DisabledBackColor = System.Drawing.Color.Empty;
|
||||
this.btnPrev.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnPrev.Location = new System.Drawing.Point(259, 0);
|
||||
this.btnPrev.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.btnPrev.Name = "btnPrev";
|
||||
this.btnPrev.Size = new System.Drawing.Size(31, 20);
|
||||
this.btnPrev.Style.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnPrev.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnPrev.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnPrev.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
|
||||
this.btnPrev.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
this.btnPrev.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
|
||||
this.btnPrev.Style.ForeColor.Color = System.Drawing.Color.White;
|
||||
this.btnPrev.Style.GradientAngle = 90;
|
||||
this.btnPrev.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnPrev.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnPrev.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnPrev.TabIndex = 431;
|
||||
this.btnPrev.Text = "上页";
|
||||
this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click);
|
||||
//
|
||||
// btnNext
|
||||
//
|
||||
this.btnNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.btnNext.AutoSize = true;
|
||||
this.btnNext.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
|
||||
this.btnNext.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnNext.DisabledBackColor = System.Drawing.Color.Empty;
|
||||
this.btnNext.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnNext.Location = new System.Drawing.Point(311, 0);
|
||||
this.btnNext.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.btnNext.Name = "btnNext";
|
||||
this.btnNext.Size = new System.Drawing.Size(31, 20);
|
||||
this.btnNext.Style.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnNext.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnNext.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnNext.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
|
||||
this.btnNext.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
this.btnNext.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
|
||||
this.btnNext.Style.ForeColor.Color = System.Drawing.Color.White;
|
||||
this.btnNext.Style.GradientAngle = 90;
|
||||
this.btnNext.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnNext.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnNext.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnNext.TabIndex = 435;
|
||||
this.btnNext.Text = "下页";
|
||||
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
|
||||
//
|
||||
// lblPage
|
||||
//
|
||||
this.lblPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.lblPage.AutoSize = true;
|
||||
this.lblPage.Location = new System.Drawing.Point(293, 0);
|
||||
this.lblPage.Name = "lblPage";
|
||||
this.lblPage.Size = new System.Drawing.Size(15, 20);
|
||||
this.lblPage.TabIndex = 436;
|
||||
this.lblPage.Text = "1";
|
||||
this.lblPage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// flowLayoutPanel1
|
||||
//
|
||||
this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 3);
|
||||
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
|
||||
this.flowLayoutPanel1.Size = new System.Drawing.Size(200, 100);
|
||||
this.flowLayoutPanel1.TabIndex = 437;
|
||||
//
|
||||
// flowLayoutPanel2
|
||||
//
|
||||
this.flowLayoutPanel2.Controls.Add(this.btnJump);
|
||||
this.flowLayoutPanel2.Controls.Add(this.label1);
|
||||
this.flowLayoutPanel2.Controls.Add(this.txtJumpPage);
|
||||
this.flowLayoutPanel2.Controls.Add(this.lblJump);
|
||||
this.flowLayoutPanel2.Controls.Add(this.btnNext);
|
||||
this.flowLayoutPanel2.Controls.Add(this.lblPage);
|
||||
this.flowLayoutPanel2.Controls.Add(this.btnPrev);
|
||||
this.flowLayoutPanel2.Controls.Add(this.lblTotal);
|
||||
this.flowLayoutPanel2.Controls.Add(this.lblPageSize);
|
||||
this.flowLayoutPanel2.Controls.Add(this.cmbPageSize);
|
||||
this.flowLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flowLayoutPanel2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.flowLayoutPanel2.Location = new System.Drawing.Point(0, 0);
|
||||
this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
|
||||
this.flowLayoutPanel2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
|
||||
this.flowLayoutPanel2.Size = new System.Drawing.Size(480, 23);
|
||||
this.flowLayoutPanel2.TabIndex = 0;
|
||||
//
|
||||
// btnJump
|
||||
//
|
||||
this.btnJump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.btnJump.AutoSize = true;
|
||||
this.btnJump.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
|
||||
this.btnJump.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnJump.DisabledBackColor = System.Drawing.Color.Empty;
|
||||
this.btnJump.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnJump.Location = new System.Drawing.Point(446, 0);
|
||||
this.btnJump.Margin = new System.Windows.Forms.Padding(3, 0, 3, 0);
|
||||
this.btnJump.Name = "btnJump";
|
||||
this.btnJump.Size = new System.Drawing.Size(31, 20);
|
||||
this.btnJump.Style.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnJump.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnJump.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnJump.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
|
||||
this.btnJump.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
this.btnJump.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
|
||||
this.btnJump.Style.ForeColor.Color = System.Drawing.Color.White;
|
||||
this.btnJump.Style.GradientAngle = 90;
|
||||
this.btnJump.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnJump.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnJump.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnJump.TabIndex = 439;
|
||||
this.btnJump.Text = "跳转";
|
||||
this.btnJump.Click += new System.EventHandler(this.pnlJump_Click);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(423, 0);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(20, 20);
|
||||
this.label1.TabIndex = 445;
|
||||
this.label1.Text = "页";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// txtJumpPage
|
||||
//
|
||||
this.txtJumpPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
//
|
||||
//
|
||||
//
|
||||
this.txtJumpPage.Border.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;
|
||||
this.txtJumpPage.Border.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;
|
||||
this.txtJumpPage.Border.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;
|
||||
this.txtJumpPage.Border.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;
|
||||
this.txtJumpPage.Border.Class = "CrumbBarBackgroundKey";
|
||||
this.txtJumpPage.Border.CornerType = DevComponents.DotNetBar.eCornerType.Square;
|
||||
this.txtJumpPage.Border.PaddingBottom = 2;
|
||||
this.txtJumpPage.Border.PaddingLeft = 2;
|
||||
this.txtJumpPage.Border.PaddingRight = 2;
|
||||
this.txtJumpPage.Border.PaddingTop = 2;
|
||||
this.txtJumpPage.Font = new System.Drawing.Font("微软雅黑", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.txtJumpPage.Location = new System.Drawing.Point(393, 0);
|
||||
this.txtJumpPage.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.txtJumpPage.Name = "txtJumpPage";
|
||||
this.txtJumpPage.Size = new System.Drawing.Size(30, 21);
|
||||
this.txtJumpPage.TabIndex = 444;
|
||||
this.txtJumpPage.Text = "1";
|
||||
//
|
||||
// lblJump
|
||||
//
|
||||
this.lblJump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.lblJump.AutoSize = true;
|
||||
this.lblJump.Location = new System.Drawing.Point(345, 0);
|
||||
this.lblJump.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0);
|
||||
this.lblJump.Name = "lblJump";
|
||||
this.lblJump.Size = new System.Drawing.Size(48, 20);
|
||||
this.lblJump.TabIndex = 437;
|
||||
this.lblJump.Text = "跳转到 ";
|
||||
this.lblJump.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lblTotal
|
||||
//
|
||||
this.lblTotal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.lblTotal.AutoSize = true;
|
||||
this.lblTotal.Location = new System.Drawing.Point(220, 0);
|
||||
this.lblTotal.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.lblTotal.Name = "lblTotal";
|
||||
this.lblTotal.Size = new System.Drawing.Size(39, 20);
|
||||
this.lblTotal.TabIndex = 446;
|
||||
this.lblTotal.Text = "共1页";
|
||||
this.lblTotal.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lblPageSize
|
||||
//
|
||||
this.lblPageSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.lblPageSize.AutoSize = true;
|
||||
this.lblPageSize.Location = new System.Drawing.Point(177, 0);
|
||||
this.lblPageSize.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.lblPageSize.Name = "lblPageSize";
|
||||
this.lblPageSize.Size = new System.Drawing.Size(37, 20);
|
||||
this.lblPageSize.TabIndex = 453;
|
||||
this.lblPageSize.Text = "条/页";
|
||||
this.lblPageSize.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.lblPageSize.Visible = false;
|
||||
//
|
||||
// cmbPageSize
|
||||
//
|
||||
this.cmbPageSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
|
||||
this.cmbPageSize.Font = new System.Drawing.Font("微软雅黑", 7F);
|
||||
this.cmbPageSize.FormattingEnabled = true;
|
||||
this.cmbPageSize.Items.AddRange(new object[] {
|
||||
"50",
|
||||
"100",
|
||||
"200",
|
||||
"500",
|
||||
"1000",
|
||||
"2000",
|
||||
"5000"});
|
||||
this.cmbPageSize.Location = new System.Drawing.Point(132, 0);
|
||||
this.cmbPageSize.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.cmbPageSize.Name = "cmbPageSize";
|
||||
this.cmbPageSize.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.cmbPageSize.Size = new System.Drawing.Size(45, 22);
|
||||
this.cmbPageSize.TabIndex = 452;
|
||||
this.cmbPageSize.Text = "50";
|
||||
this.cmbPageSize.Visible = false;
|
||||
//
|
||||
// UcSplitPage
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.Controls.Add(this.flowLayoutPanel2);
|
||||
this.Controls.Add(this.flowLayoutPanel1);
|
||||
this.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.Name = "UcSplitPage";
|
||||
this.Size = new System.Drawing.Size(480, 23);
|
||||
this.flowLayoutPanel2.ResumeLayout(false);
|
||||
this.flowLayoutPanel2.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DevComponents.DotNetBar.PanelEx btnPrev;
|
||||
private DevComponents.DotNetBar.PanelEx btnNext;
|
||||
private System.Windows.Forms.Label lblPage;
|
||||
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
|
||||
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
|
||||
private System.Windows.Forms.Label lblJump;
|
||||
private DevComponents.DotNetBar.PanelEx btnJump;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private DevComponents.DotNetBar.Controls.TextBoxX txtJumpPage;
|
||||
private System.Windows.Forms.Label lblPageSize;
|
||||
public System.Windows.Forms.ComboBox cmbPageSize;
|
||||
public System.Windows.Forms.Label lblTotal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.Extension
|
||||
{
|
||||
public static class ControlExtension
|
||||
{
|
||||
public static Point GetRelativePosition(this Control control, Form form)
|
||||
{
|
||||
Point location = control.Location;
|
||||
Control parent = control.Parent;
|
||||
while (parent != null && parent != form)
|
||||
{
|
||||
location.X += parent.Location.X;
|
||||
location.Y += parent.Location.Y;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
public static Point GetRelativePosition(this Control control, Control parentControl)
|
||||
{
|
||||
if (control == null || parentControl == null)
|
||||
return new Point(0, 0);
|
||||
|
||||
Point location = control.Location;
|
||||
Control parent = control.Parent;
|
||||
while (parent != null && parent != parentControl)
|
||||
{
|
||||
location.X += parent.Location.X;
|
||||
location.Y += parent.Location.Y;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
public static Point GetRelativePosition(this Control control)
|
||||
{
|
||||
Point location = control.Location;
|
||||
Control parent = control.Parent;
|
||||
while (parent != null && !(parent is Form))
|
||||
{
|
||||
location.X += parent.Location.X;
|
||||
location.Y += parent.Location.Y;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
public static Control GetParentNotTable(this Control contorl)
|
||||
{
|
||||
Control parent = contorl.Parent;
|
||||
while (parent != null && (parent is TableLayoutPanel || parent is FlowLayoutPanel))
|
||||
{
|
||||
parent = parent.Parent;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,912 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using NaiBa.Util;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Work.UserComponents;
|
||||
|
||||
namespace Work.Extension
|
||||
{
|
||||
public static class DataGridViewExtension
|
||||
{
|
||||
public static object GetCellValueFromColumnName(this DataGridViewCellCollection CellCollection, string name)
|
||||
{
|
||||
return CellCollection.Cast<DataGridViewCell>().FirstOrDefault(c => c.OwningColumn.Name == name)?.Value;
|
||||
}
|
||||
|
||||
public static UcCheckBox AddSelectorColumn(this DataGridView dgv, string columnName = "Selected", Action<DataGridViewColumn> addHeaderCheckBoxOverride = null)
|
||||
{
|
||||
if (dgv.Columns[columnName] == null)
|
||||
{
|
||||
//var dt = dgv.Table();
|
||||
|
||||
//var dcol = new DataColumn(columnName, typeof(bool));
|
||||
//dt.Columns.Add(dcol);
|
||||
|
||||
//dt.ColumnChanged += (s, e) =>
|
||||
//{
|
||||
// var chCols = e.Row.GetChangedColumns();
|
||||
// if (chCols.Count == 1 && chCols[0].Equals(dcol))
|
||||
// e.Row.AcceptChanges();
|
||||
//};
|
||||
}
|
||||
|
||||
var col = dgv.Columns[columnName];
|
||||
col.HeaderText = "";
|
||||
col.ReadOnly = false;
|
||||
if (addHeaderCheckBoxOverride != null)
|
||||
{
|
||||
addHeaderCheckBoxOverride(col);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return col.AddHeaderCheckBox();
|
||||
}
|
||||
}
|
||||
|
||||
public static UcCheckBox AddHeaderCheckBox(this DataGridViewColumn column, HorizontalAlignment align = HorizontalAlignment.Center, int leftBorderOffset = 0, int rightBorderOffset = 0, Func<object, bool> getValue = null, Action<object, bool> setValue = null, bool isSetCheckedChangedEvent = true, UcCheckBox checkBox = null, bool isClearHeaderText = false)
|
||||
{
|
||||
if (column?.DataGridView == null) //throw new ArgumentNullException("First you need to add the column to grid.");
|
||||
MessageBox.Show("DataGridView中没有对应的CheckBox列");
|
||||
|
||||
// Creating checkbox without panel
|
||||
if (checkBox == null)
|
||||
{
|
||||
checkBox = new UcCheckBox();
|
||||
|
||||
checkBox.Name = "chk" + column.Name;
|
||||
}
|
||||
checkBox.Size = new Size(13, 13);
|
||||
checkBox.BackColor = Color.Transparent;
|
||||
checkBox.Enabled = true;
|
||||
|
||||
// Reset properties
|
||||
checkBox.Padding = new Padding(6, 2, 0, 0);
|
||||
checkBox.Margin = new Padding(0);
|
||||
checkBox.Text = "";
|
||||
|
||||
if (isClearHeaderText)
|
||||
column.HeaderText = "";
|
||||
|
||||
var changedByUser = true;
|
||||
var dgv = column.DataGridView;
|
||||
|
||||
if (isSetCheckedChangedEvent)
|
||||
{
|
||||
checkBox.CheckedChanged += (s, e) =>
|
||||
{
|
||||
if (changedByUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
changedByUser = false;
|
||||
|
||||
if (dgv.IsCurrentCellInEditMode && dgv.CurrentCell.OwningColumn.Name.Equals(column.Name))
|
||||
dgv.EndEdit();
|
||||
|
||||
var dgvRows = new List<DataGridViewRow>((dgv.SelectedRows.Count < 2 ? (ICollection)dgv.Rows : dgv.SelectedRows).Cast<DataGridViewRow>());
|
||||
dgvRows = dgvRows.Where(r => r.Visible == true).ToList();
|
||||
|
||||
if (column.IsDataBound)
|
||||
{
|
||||
//adding to list because of BindingSource sort by that column
|
||||
var boundItems = new List<object>();
|
||||
var areDataRows = dgvRows.Count < 1 || dgvRows[0].DataBoundItem is DataRowView;
|
||||
if (areDataRows)
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvRows)
|
||||
boundItems.Add(((DataRowView)row.DataBoundItem).Row);
|
||||
foreach (DataRow dr in boundItems)
|
||||
{
|
||||
var val = dr[column.DataPropertyName];
|
||||
if ((val is bool && (bool)val) != checkBox.Checked)
|
||||
dr[column.DataPropertyName] = checkBox.Checked;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvRows)
|
||||
boundItems.Add(row.DataBoundItem);
|
||||
foreach (var item in boundItems)
|
||||
{
|
||||
var val = getValue(item);
|
||||
if (val != checkBox.Checked)
|
||||
setValue(item, checkBox.Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (DataGridViewRow dgr in dgvRows)
|
||||
{
|
||||
var cell = dgr.Cells[column.Name];
|
||||
if ((cell.Value is bool && (bool)cell.Value) != checkBox.Checked)
|
||||
cell.Value = checkBox.Checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
changedByUser = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Add checkbox to datagrid cell
|
||||
dgv.Controls.Add(checkBox);
|
||||
|
||||
Action onColResize = () =>
|
||||
{
|
||||
var colCheck = dgv.Columns[column.Name];
|
||||
if (colCheck == null) return;
|
||||
int colLeft = (dgv.RowHeadersVisible ? dgv.RowHeadersWidth : 0) - (colCheck.Frozen ? 0 : dgv.HorizontalScrollingOffset);
|
||||
foreach (DataGridViewColumn col in dgv.Columns)
|
||||
{
|
||||
if (col.DisplayIndex >= colCheck.DisplayIndex) break;
|
||||
if (!col.Visible) continue;
|
||||
colLeft += col.Width;
|
||||
}
|
||||
|
||||
var newPoint = new Point(colLeft, dgv.ColumnHeadersHeight / 2 - checkBox.Height / 2);
|
||||
|
||||
if (align == HorizontalAlignment.Left)
|
||||
newPoint.X += 3;
|
||||
else if (align == HorizontalAlignment.Center)
|
||||
newPoint.X += colCheck.Width / 2 - checkBox.Width / 2;
|
||||
else if (align == HorizontalAlignment.Right)
|
||||
newPoint.X += colCheck.Width - checkBox.Width - 3;
|
||||
|
||||
var minLeft = colLeft + leftBorderOffset;
|
||||
var maxLeft = colLeft + colCheck.Width - checkBox.Width + rightBorderOffset;
|
||||
|
||||
if (newPoint.X < minLeft) newPoint.X = minLeft;
|
||||
if (newPoint.X > maxLeft) newPoint.X = maxLeft;
|
||||
|
||||
checkBox.Location = newPoint;
|
||||
checkBox.Visible = colCheck.Visible;
|
||||
};
|
||||
dgv.ColumnWidthChanged += (s, e) => onColResize();
|
||||
dgv.ColumnHeadersHeightChanged += (s, e) => onColResize();
|
||||
dgv.Scroll += (s, e) => onColResize();
|
||||
dgv.Resize += (s, e) => onColResize();
|
||||
dgv.Sorted += (s, e) => onColResize();
|
||||
dgv.RowHeadersWidthChanged += (s, e) => onColResize();
|
||||
dgv.ColumnStateChanged += (s, e) => onColResize();
|
||||
|
||||
Action<object> onDataChanged = (e) =>
|
||||
{
|
||||
if (!changedByUser) return;
|
||||
if (e is DataColumnChangeEventArgs)
|
||||
{
|
||||
if (!((DataColumnChangeEventArgs)e).Column.ColumnName.Equals(column.Name))
|
||||
return;
|
||||
}
|
||||
else if (e is ListChangedEventArgs)
|
||||
{
|
||||
var prop = ((ListChangedEventArgs)e).PropertyDescriptor;
|
||||
if (prop != null && !prop.Name.Equals(column.DataPropertyName))
|
||||
return;
|
||||
}
|
||||
|
||||
bool allAreTrue = true;
|
||||
foreach (DataGridViewRow row in dgv.SelectedRows.Count < 2 ? (ICollection)dgv.Rows : dgv.SelectedRows)
|
||||
{
|
||||
var val = row.Cells[column.Name].Value;
|
||||
if (!(val is bool) || !(bool)val)
|
||||
{
|
||||
allAreTrue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
changedByUser = false;
|
||||
var tag = checkBox.Tag;
|
||||
checkBox.Tag = "AUTO";
|
||||
try
|
||||
{
|
||||
if (isSetCheckedChangedEvent)
|
||||
{
|
||||
checkBox.Checked = allAreTrue;
|
||||
}
|
||||
}
|
||||
finally { checkBox.Tag = tag; }
|
||||
}
|
||||
finally
|
||||
{
|
||||
changedByUser = true;
|
||||
}
|
||||
};
|
||||
dgv.CellClick += (s, e) => onDataChanged(e);
|
||||
dgv.CellContentClick += (s, e) => onDataChanged(e);
|
||||
dgv.SelectionChanged += (s, e) => onDataChanged(e);
|
||||
if (dgv.DataSource is BindingSource)
|
||||
((BindingSource)dgv.DataSource).ListChanged += (s, e) => onDataChanged(e);
|
||||
else if (dgv.DataSource is DataSet)
|
||||
((DataSet)dgv.DataSource).Tables[dgv.DataMember].ColumnChanged += (s, e) => onDataChanged(e);
|
||||
else if (dgv.DataSource is DataTable)
|
||||
((DataTable)dgv.DataSource).ColumnChanged += (s, e) => onDataChanged(e);
|
||||
|
||||
onColResize();
|
||||
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制合并的表头单元格
|
||||
/// </summary>
|
||||
/// <param name="dgv"></param>
|
||||
/// <param name="colNameCollection">单元格名称</param>
|
||||
/// <param name="headerText">合并后的表头显示文字</param>
|
||||
/// <param name="isEnableResizing">是否允许调整大小</param>
|
||||
public static void AddMergeColumnHeader(this DataGridView dgv, List<string> colNameCollection, string headerText, bool isMultiLevelHeader = false)
|
||||
{
|
||||
int nHeight = 0;
|
||||
int nLeft = 0;
|
||||
int nTop = 0;
|
||||
int nWidth = 0;
|
||||
bool isMultiLevel = isMultiLevelHeader; // 是否为二级复合表头
|
||||
bool isResize = false; // 是否已调整过表头
|
||||
|
||||
//合并列中某一列的列宽变化时,强制重绘表头
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
{
|
||||
if (colNameCollection.Contains(e.Column.Name))
|
||||
{
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
if (dgv.Columns.Contains(columnName))
|
||||
dgv.InvalidateCell(dgv.Columns[columnName].HeaderCell); // 标记单元格为需要重绘
|
||||
}
|
||||
dgv.Update();
|
||||
}
|
||||
};
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
|
||||
{
|
||||
bool tag = false;
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
var bounds = dgv.Columns[columnName].HeaderCell.ContentBounds;
|
||||
if (bounds.Left < 10 || bounds.Right > dgv.Width - 10)
|
||||
{
|
||||
tag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tag == true)
|
||||
{
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
if (dgv.Columns.Contains(columnName))
|
||||
dgv.InvalidateCell(dgv.Columns[columnName].HeaderCell); // 标记单元格为需要重绘
|
||||
}
|
||||
dgv.Update();
|
||||
}
|
||||
}
|
||||
};
|
||||
//处理重绘事件,绘制合并表头和二级表头
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex == -1 && e.ColumnIndex >= 0) // 重绘表头单元格及标题
|
||||
{
|
||||
string name = dgv.Columns[e.ColumnIndex].Name;
|
||||
// 调整为复合表头
|
||||
if (isMultiLevel && !isResize)
|
||||
{
|
||||
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
|
||||
dgv.ColumnHeadersHeight = e.CellBounds.Height * 2;
|
||||
isResize = true;
|
||||
}
|
||||
if (colNameCollection.Contains(name))
|
||||
{
|
||||
e.PaintBackground(e.CellBounds, false); // false不绘制单元格背景
|
||||
//e.PaintContent(e.CellBounds); // 绘制单元格内容,此处不要绘制
|
||||
|
||||
Brush brush;
|
||||
Pen pen;
|
||||
if (colNameCollection.IndexOf(name) == 0)
|
||||
{
|
||||
nTop = e.CellBounds.Top;
|
||||
nLeft = e.CellBounds.Left;
|
||||
nWidth = e.CellBounds.Width;
|
||||
if (isMultiLevelHeader)
|
||||
nHeight = e.CellBounds.Height / 2;
|
||||
else
|
||||
nHeight = e.CellBounds.Height;
|
||||
foreach (string str2 in colNameCollection)
|
||||
{
|
||||
if (!str2.Equals(name))
|
||||
{
|
||||
nWidth += dgv.Columns[str2].Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
//填充表头背景(覆盖原来的分隔线)
|
||||
Rectangle rtTmp = new Rectangle(nLeft, nTop, nWidth, nHeight);
|
||||
using (brush = new SolidBrush(/*e.CellStyle.BackColor*/dgv.BackgroundColor))
|
||||
{
|
||||
var rtBounds = e.CellBounds;
|
||||
rtBounds.Height -= 1;
|
||||
e.Graphics.FillRectangle(brush, rtBounds);
|
||||
}
|
||||
//非多级表头,只需绘制最后一个连续表头的垂直分隔线
|
||||
if (!isMultiLevelHeader)
|
||||
{
|
||||
if (colNameCollection.IndexOf(name) == colNameCollection.Count - 1)
|
||||
{
|
||||
// 分隔线
|
||||
using (pen = new Pen(Color.FromArgb(229, 229, 229)))
|
||||
{
|
||||
var rtBounds = e.CellBounds;
|
||||
e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top + 1, rtBounds.Right - 1, rtBounds.Bottom - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//分割多级表头
|
||||
using (pen = new Pen(/*dgv.GridColor*/Color.FromArgb(229, 229, 229)))
|
||||
{
|
||||
//水平分隔线
|
||||
e.Graphics.DrawLine(pen, nLeft, nHeight, nLeft + nWidth, nHeight);
|
||||
//垂直分隔线
|
||||
var rtBounds = e.CellBounds;
|
||||
if (colNameCollection.IndexOf(name) == colNameCollection.Count - 1)
|
||||
e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top + 1, rtBounds.Right - 1, rtBounds.Bottom - 2);
|
||||
else
|
||||
e.Graphics.DrawLine(pen, rtBounds.Right - 1, nHeight, rtBounds.Right - 1, rtBounds.Bottom - 2);
|
||||
}
|
||||
//绘制二级表头文字
|
||||
using (brush = new SolidBrush(e.CellStyle.ForeColor))
|
||||
{
|
||||
SizeF textSize = TextRenderer.MeasureText(dgv.Columns[e.ColumnIndex].HeaderText, e.CellStyle.Font);
|
||||
int nSubTop = nTop + nHeight;
|
||||
int nSubLeft = e.CellBounds.Left;
|
||||
int nSubWidth = e.CellBounds.Width;
|
||||
int nSubHeight = nHeight;
|
||||
PointF point = new PointF(nSubLeft + 6, nSubTop + (nSubHeight - textSize.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center"))
|
||||
point.X = nSubLeft + (nSubWidth - textSize.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nSubLeft + nSubWidth - textSize.Width - 6;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nSubTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nSubTop + nSubHeight - textSize.Height - 4;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
e.Graphics.DrawString(dgv.Columns[e.ColumnIndex].HeaderText, e.CellStyle.Font, brush, point);
|
||||
}
|
||||
}
|
||||
//绘制合并表头名称,只在最后绘制一次
|
||||
if (colNameCollection.IndexOf(name) == colNameCollection.Count - 1)
|
||||
{
|
||||
using (brush = new SolidBrush(e.CellStyle.ForeColor))
|
||||
{
|
||||
SizeF textSize = TextRenderer.MeasureText(headerText, e.CellStyle.Font);
|
||||
//单元列移出可见范围后将不再移动,需要强制改变绘制文字的位置
|
||||
if (nLeft < 0)
|
||||
nLeft = e.CellBounds.Right - nWidth;
|
||||
PointF point = new PointF(nLeft + 6, nTop + (nHeight - textSize.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center") || isMultiLevel)
|
||||
point.X = nLeft + (nWidth - textSize.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nLeft + nWidth - textSize.Width - 6;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nTop + nHeight - textSize.Height - 4;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
e.Graphics.DrawString(headerText, e.CellStyle.Font, brush, point);
|
||||
}
|
||||
}
|
||||
//e.set_Handled(true);
|
||||
e.Handled = true; // 告知系统不再处理表头单元格绘制事件
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddMergeColumn(this DataGridView dgv, List<string> colNameCollection, Color? VerGridColor = null, Color? VerGridSelectColor = null)
|
||||
{
|
||||
int nHeight = 0;
|
||||
int nLeft = 0;
|
||||
int nTop = 0;
|
||||
int nWidth = 0;
|
||||
|
||||
//合并列中某一列的列宽变化时,强制重绘表头
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
{
|
||||
if (colNameCollection.Contains(e.Column.Name))
|
||||
{
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
if (dgv.Columns.Contains(columnName))
|
||||
dgv.InvalidateCell(dgv.Columns[columnName].HeaderCell); // 标记单元格为需要重绘
|
||||
}
|
||||
dgv.Update();
|
||||
}
|
||||
};
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
|
||||
{
|
||||
bool tag = false;
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
var bounds = dgv.Columns[columnName].HeaderCell.ContentBounds;
|
||||
if (bounds.Left < 10 || bounds.Right > dgv.Width - 10)
|
||||
{
|
||||
tag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tag == true)
|
||||
{
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
if (dgv.Columns.Contains(columnName))
|
||||
dgv.InvalidateCell(dgv.Columns[columnName].HeaderCell); // 标记单元格为需要重绘
|
||||
}
|
||||
dgv.Update();
|
||||
}
|
||||
}
|
||||
};
|
||||
//处理重绘事件
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
{
|
||||
string name = dgv.Columns[e.ColumnIndex].Name;
|
||||
if (colNameCollection.Contains(name))
|
||||
{
|
||||
e.PaintBackground(e.CellBounds, true); // false不绘制单元格背景
|
||||
e.PaintContent(e.CellBounds); // 绘制单元格内容,此处要绘制内容
|
||||
|
||||
Brush brush;
|
||||
Pen pen;
|
||||
if (colNameCollection.IndexOf(name) == 0)
|
||||
{
|
||||
nTop = e.CellBounds.Top;
|
||||
nLeft = e.CellBounds.Left;
|
||||
nWidth = e.CellBounds.Width;
|
||||
nHeight = e.CellBounds.Height;
|
||||
foreach (string str2 in colNameCollection)
|
||||
{
|
||||
if (!str2.Equals(name))
|
||||
{
|
||||
nWidth += dgv.Columns[str2].Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
//填充背景(覆盖原来的分隔线)
|
||||
//Rectangle rtTmp = new Rectangle(nLeft, nTop, nWidth, nHeight);
|
||||
//using (brush = new SolidBrush(/*e.CellStyle.BackColor*/dgv.BackgroundColor))
|
||||
//{
|
||||
// var rtBounds = e.CellBounds;
|
||||
// rtBounds.Height -= 1;
|
||||
// e.Graphics.FillRectangle(brush, rtBounds);
|
||||
//}
|
||||
if (colNameCollection.IndexOf(name) < colNameCollection.Count - 1)
|
||||
{
|
||||
var penColor = VerGridColor;
|
||||
// 分隔线
|
||||
if (penColor == null)
|
||||
{
|
||||
//VerGridColor = Color.FromArgb(229, 229, 229);
|
||||
penColor = e.RowIndex % 2 == 0 ? dgv.DefaultCellStyle.BackColor : dgv.AlternatingRowsDefaultCellStyle.BackColor;
|
||||
}
|
||||
var penSelectColor = VerGridSelectColor;
|
||||
if (penSelectColor == null)
|
||||
//VerGridColorSelect = Color.FromArgb(129, 129, 129);
|
||||
penSelectColor = dgv.DefaultCellStyle.SelectionBackColor;
|
||||
if ((dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected)
|
||||
{
|
||||
using (pen = new Pen(penSelectColor.Value))
|
||||
{
|
||||
var rtBounds = e.CellBounds;
|
||||
e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (pen = new Pen(penColor.Value))
|
||||
{
|
||||
var rtBounds = e.CellBounds;
|
||||
e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
//e.set_Handled(true);
|
||||
e.Handled = true; // 告知系统不再处理表头单元格绘制事件
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static void AddVerticalMergeCell(this DataGridView dgv, ConcurrentList<DataGridViewCell> cellLst, bool drawRightBorder = true, Color? VerGridColor = null, Color? VerGridSelectColor = null)
|
||||
{
|
||||
int nHeight = 0;
|
||||
int nLeft = 0;
|
||||
int nTop = 0;
|
||||
int nWidth = 0;
|
||||
|
||||
dgv.RowHeightChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.RowIndex == e.Row.Index)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
//合并列中某一列的列宽变化时,强制重绘
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.ColumnIndex == e.Column.Index)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
dgv.SelectionChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.Displayed)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (DataGridViewCell cell in cellLst)
|
||||
{
|
||||
if (cell.Displayed)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
//处理重绘事件
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
{
|
||||
foreach (DataGridViewCell cell in cellLst)
|
||||
{
|
||||
if (cell.RowIndex == e.RowIndex && cell.ColumnIndex == e.ColumnIndex)
|
||||
{
|
||||
nTop = e.CellBounds.Top;
|
||||
nLeft = e.CellBounds.Left;
|
||||
nWidth = e.CellBounds.Width;
|
||||
nHeight = 0;
|
||||
foreach (DataGridViewCell c in cellLst)
|
||||
{
|
||||
nHeight += dgv.Rows[c.RowIndex].Height;
|
||||
}
|
||||
for (int i = 0; i < cellLst.IndexOf(cell); i++)
|
||||
{
|
||||
nTop -= dgv.Rows[cellLst[i].RowIndex].Height;
|
||||
}
|
||||
var rect = new Rectangle(nLeft, nTop, nWidth - 1, nHeight - 1);
|
||||
if (!drawRightBorder)
|
||||
rect = new Rectangle(nLeft, nTop, nWidth, nHeight - 1);
|
||||
|
||||
e.PaintBackground(e.CellBounds, true); // false不绘制单元格背景
|
||||
//e.PaintContent(e.CellBounds); // 绘制单元格内容,此处根据需要决定是否绘制内容
|
||||
|
||||
Brush brush;
|
||||
Pen pen;
|
||||
//if (cellLst.IndexOf(cell) < cellLst.Count - 1)
|
||||
{
|
||||
var color = VerGridColor;
|
||||
// 分隔线
|
||||
if (color == null)
|
||||
{
|
||||
//VerGridColor = Color.FromArgb(229, 229, 229);
|
||||
color = e.RowIndex % 2 == 0 ? dgv.DefaultCellStyle.BackColor : dgv.AlternatingRowsDefaultCellStyle.BackColor;
|
||||
color = e.CellStyle.BackColor;
|
||||
}
|
||||
var selectColor = VerGridSelectColor;
|
||||
if (selectColor == null)
|
||||
//VerGridColorSelect = Color.FromArgb(129, 129, 129);
|
||||
selectColor = dgv.DefaultCellStyle.SelectionBackColor;
|
||||
//if ((dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected)
|
||||
if (cellLst.Any(c => c.Selected))
|
||||
{
|
||||
//using (pen = new Pen(selectColor.Value))
|
||||
//{
|
||||
// var rtBounds = e.CellBounds;
|
||||
// //e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2); // 右竖线
|
||||
// e.Graphics.DrawLine(pen, rtBounds.Left, rtBounds.Bottom - 1, rtBounds.Right - 2, rtBounds.Bottom - 1); // 下横线
|
||||
//}
|
||||
using (brush = new SolidBrush(selectColor.Value))
|
||||
{
|
||||
e.Graphics.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//using (pen = new Pen(color.Value))
|
||||
//{
|
||||
// var rtBounds = e.CellBounds;
|
||||
// //e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2); // 右竖线
|
||||
// e.Graphics.DrawLine(pen, rtBounds.Left, rtBounds.Bottom - 1, rtBounds.Right - 2, rtBounds.Bottom - 1); // 下横线
|
||||
//}
|
||||
using (brush = new SolidBrush(color.Value))
|
||||
{
|
||||
e.Graphics.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (cellLst.IndexOf(cell) == cellLst.Count - 1)
|
||||
if (cell is DataGridViewImageCell == false)
|
||||
{
|
||||
var color = e.CellStyle.ForeColor;
|
||||
if (cellLst.Any(c => c.Selected))
|
||||
{
|
||||
color = e.CellStyle.SelectionForeColor;
|
||||
}
|
||||
using (brush = new SolidBrush(color))
|
||||
{
|
||||
//StringFormat stringFormat = new StringFormat();
|
||||
//stringFormat.Alignment = StringAlignment.Near;
|
||||
//stringFormat.LineAlignment = StringAlignment.Near;
|
||||
//stringFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces; // 确保尾部空格被计算在内
|
||||
//stringFormat.Trimming = StringTrimming.Character; // 处理超出宽度的字符
|
||||
//stringFormat.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, cell.Value.ParseToString().Length) }); // 设置测量范围
|
||||
|
||||
SizeF textSize = TextRenderer.MeasureText(cell.Value.ParseToString(), e.CellStyle.Font, new Size(nWidth - 10, nHeight), TextFormatFlags.WordBreak);
|
||||
//单元列移出可见范围后将不再移动,需要强制改变绘制文字的位置
|
||||
if (nLeft < 0)
|
||||
nLeft = e.CellBounds.Right - nWidth;
|
||||
PointF point = new PointF(nLeft + 1, nTop + (nHeight - textSize.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center"))
|
||||
point.X = nLeft + (nWidth - textSize.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nLeft + nWidth - textSize.Width - 1;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nTop + nHeight - textSize.Height - 4;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rectF = new RectangleF(point.X, point.Y, nWidth - 10, nHeight - 10);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, point);
|
||||
e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, rectF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var img = cell.Value as Image;
|
||||
|
||||
PointF point = new PointF(nLeft, nTop + (nHeight - img.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center"))
|
||||
point.X = nLeft + (nWidth - img.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nLeft + nWidth - img.Width - 1;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nTop + nHeight - img.Height;
|
||||
e.Graphics.DrawImage(img, point);
|
||||
//RectangleF rectF = new RectangleF(point.X, point.Y, nWidth - 10, nHeight - 10);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, point);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, rectF);
|
||||
}
|
||||
e.Handled = true; // 告知系统不再处理单元格绘制事件
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddImgColumn(this DataGridView dgv, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
{
|
||||
//bool isScroll = false;
|
||||
CancellationTokenSource cancelToken = new CancellationTokenSource();
|
||||
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
cancelToken.Cancel();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
Task.Run(() =>
|
||||
{
|
||||
//while (isScroll && 1 == 1)
|
||||
// Thread.Sleep(1);
|
||||
//isScroll = true;
|
||||
ShowDgvImg(cancelToken, dgv, dgv.Rows.Cast<DataGridViewRow>().ToList(), imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//isScroll = false;
|
||||
}, cancelToken.Token);
|
||||
};
|
||||
//dgv.Resize += (s, e) =>
|
||||
//{
|
||||
// ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//};
|
||||
dgv.Sorted += (s, e) =>
|
||||
{
|
||||
cancelToken.Cancel();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
Task.Run(() =>
|
||||
{
|
||||
//while (isScroll && 1 == 1)
|
||||
// Thread.Sleep(1);
|
||||
//isScroll = true;
|
||||
ShowDgvImg(cancelToken, dgv, dgv.Rows.Cast<DataGridViewRow>().ToList(), imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//isScroll = false;
|
||||
}, cancelToken.Token);
|
||||
};
|
||||
//dgv.RowsRemoved += (s, e) =>
|
||||
//{
|
||||
// ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//};
|
||||
dgv.RowsAdded += (s, e) =>
|
||||
{
|
||||
cancelToken.Cancel();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
Task.Run(() =>
|
||||
{
|
||||
//while (isScroll && 1 == 1)
|
||||
// Thread.Sleep(1);
|
||||
//isScroll = true;
|
||||
if (e.RowIndex < (dgv.FirstDisplayedScrollingRowIndex + dgv.DisplayedRowCount(true)))
|
||||
ShowDgvImg(cancelToken, dgv, dgv.Rows.Cast<DataGridViewRow>().ToList(), imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
else
|
||||
ShowDgvImg(cancelToken, dgv, new List<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//isScroll = false;
|
||||
}, cancelToken.Token);
|
||||
};
|
||||
dgv.RowPostPaint += (s, e) =>
|
||||
{
|
||||
//if (e.RowIndex >= 0 && e.RowIndex < 25)
|
||||
//{
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
// while (isScroll && 1 == 1)
|
||||
// Thread.Sleep(1);
|
||||
// isScroll = true;
|
||||
// try
|
||||
// {
|
||||
// if (dgv.Rows.Count > e.RowIndex)
|
||||
// ShowDgvImg(dgv, new List<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
|
||||
// }
|
||||
// isScroll = false;
|
||||
// });
|
||||
//}
|
||||
};
|
||||
dgv.CellValueChanged += (s, e) =>
|
||||
{
|
||||
if (dgv.Columns[e.ColumnIndex].Name == imgPathColumn)
|
||||
{
|
||||
var row = dgv.Rows[e.RowIndex];
|
||||
if (row.Cells[imgColumn].Value != null && row.Cells[imgColumn].Value != defaultBitmap)
|
||||
{
|
||||
row.Cells[imgColumn].Value = defaultBitmap;
|
||||
|
||||
cancelToken.Cancel();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
Task.Run(() =>
|
||||
{
|
||||
//while (isScroll && 1 == 1)
|
||||
// Thread.Sleep(1);
|
||||
//isScroll = true;
|
||||
ShowDgvImg(cancelToken, dgv, new List<DataGridViewRow> { row }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//isScroll = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Bitmap defaultBitmap = new Bitmap(1, 1);
|
||||
static void ShowDgvImg(CancellationTokenSource cancelToken, DataGridView dgv, List<DataGridViewRow> rowLst, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
{
|
||||
if (rowLst == null)
|
||||
{
|
||||
rowLst = new List<DataGridViewRow>();
|
||||
rowLst.AddRange(dgv.Rows.Cast<DataGridViewRow>());
|
||||
}
|
||||
foreach (DataGridViewRow row in rowLst)
|
||||
{
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
//if (row.Index <= 1)
|
||||
// continue;
|
||||
if (row.Displayed == false && row.Index > 0) // 不设置大于0 第一行始终不显示图片
|
||||
{
|
||||
dgv.Invoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (row.Index >= 0 && row.Cells[imgColumn]?.Value != defaultBitmap)
|
||||
row.Cells[imgColumn].Value = defaultBitmap;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (row.Cells[imgColumn]?.Value == defaultBitmap || row.Cells[imgColumn]?.Value == null)
|
||||
{
|
||||
Image image = defaultBitmap;
|
||||
string imgUrl = row.Cells[imgPathColumn]?.Value.ParseToString();
|
||||
if (!string.IsNullOrWhiteSpace(imgUrl))
|
||||
{
|
||||
if (isSetHttpsHttp == true)
|
||||
imgUrl = imgUrl.Replace("https://", "http://");
|
||||
string getImgError = "";
|
||||
image = GetHtml.GetUrlImg(imgUrl, out getImgError);
|
||||
if (!string.IsNullOrEmpty(getImgError))
|
||||
//BaseMsgForm.ShowError("图片加载失败 " + getImgError);
|
||||
image = Properties.Resources.errpic;
|
||||
}
|
||||
|
||||
dgv.Invoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (row.Index >= 0)
|
||||
{
|
||||
row.Cells[imgColumn].Value = image;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+10
@@ -130,6 +130,16 @@ namespace Work.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap errpic {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("errpic", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
|
||||
@@ -190,4 +190,7 @@
|
||||
<data name="icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon.ico;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="errpic" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\resources\errpic.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
Reference in new issue
Block a user