Files
kami_itunes_june/AppleBatch_June.Forms/FormEditListViewHander.cs
2024-07-22 00:43:14 +08:00

153 lines
3.7 KiB
C#

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace AppleBatch_June.Forms
{
public class FormEditListViewHander : Form
{
private IContainer components;
private LinkLabel linkLabel1;
public bool isAstrict { get; set; } = true;
public ListView lvData { get; set; }
public FormEditListViewHander()
{
InitializeComponent();
}
private void FormEditListViewHander_Load(object sender, EventArgs e)
{
if (lvData != null)
{
initHander(lvData);
}
}
public void initHander(ListView lvData)
{
int num = 20;
int num2 = 20;
int num3 = 0;
foreach (ColumnHeader column in lvData.Columns)
{
_ = column.Text;
addCkeckBox(num, num2, column);
num += 100;
num3++;
if (num3 == 5)
{
num = 20;
num2 += 40;
num3 = 0;
}
}
}
private void addCkeckBox(int pi, int y, ColumnHeader item)
{
string text = item.Text;
bool @checked = false;
if (item.Width > 0)
{
@checked = true;
}
CheckBox checkBox = new CheckBox();
checkBox.AutoSize = true;
checkBox.Font = new Font("微软雅黑", 10f, FontStyle.Regular, GraphicsUnit.Point, 134);
if (isAstrict && (text.Contains("序号") || text == "信息" || text.Contains("返回信息")))
{
checkBox.Enabled = false;
}
checkBox.Location = new Point(pi, y);
checkBox.Size = new Size(70, 24);
checkBox.TabIndex = 0;
checkBox.Checked = @checked;
checkBox.Text = text;
checkBox.Tag = item;
checkBox.UseVisualStyleBackColor = true;
checkBox.CheckedChanged += radioButton1_CheckedChanged;
base.Controls.Add(checkBox);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (!(sender is CheckBox))
{
return;
}
CheckBox checkBox = sender as CheckBox;
if (checkBox.Tag is ColumnHeader columnHeader)
{
int result;
if (!checkBox.Checked)
{
columnHeader.Tag = columnHeader.Width;
columnHeader.Width = 0;
}
else if (columnHeader.Tag != null && int.TryParse(columnHeader.Tag.ToString(), out result))
{
columnHeader.Width = result;
}
else
{
columnHeader.Width = 100;
}
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
foreach (object control in base.Controls)
{
if (control is CheckBox && control is CheckBox)
{
(control as CheckBox).Checked = true;
}
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
base.SuspendLayout();
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(520, 117);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(53, 12);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "全部显示";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(linkLabel1_LinkClicked);
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(585, 138);
base.Controls.Add(this.linkLabel1);
base.MaximizeBox = false;
base.MinimizeBox = false;
base.Name = "FormEditListViewHander";
base.ShowIcon = false;
base.ShowInTaskbar = false;
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "编辑显示列";
base.Load += new System.EventHandler(FormEditListViewHander_Load);
base.ResumeLayout(false);
base.PerformLayout();
}
}
}