Panel
1.自定义标题栏最小化最大化关闭
private void ZXH_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}//最小化
private void BT_ZDH_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
this.WindowState = FormWindowState.Normal;
else
this.WindowState = FormWindowState.Maximized;
}//最大化
private void GB_Click(object sender, EventArgs e)
{
this.Close();
}//关闭
2.自定义标题栏模拟窗体拖动
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool ReleaseCapture();
//上方添加至cs任意地方,下方为panel设置mousedown事件
private void panel_MouseDown(object sender, MouseEventArgs e)
{
const int WM_NCLBUTTONDOWN = 0x00A1;
const int HTCAPTION = 2;
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero);
}
}
DataGridview
1.移动表格时表格及内容闪烁
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; //其中该字段与自定义最小化产生BUG
//cp.Style |= 0x20000;可用该字段代替
return cp;
}
}//放置代码任意位置即可
2.使用Task线程时导致卡顿或者滚动条黑色无法使用
data.Invoke(new Action(() =>
{
data.Rows.Add();//添加数据
data.Rows[0].DefaultCellStyle.BackColor = Color.Beige;//指定颜色
}));//添加数据时使用Invoke方法将更新UI的操作委托给UI线程执行
3.在子窗体中用GroupBox包裹DataGridview时右侧黑色
将GroupBox换为TabControl
CheckBoxComboBox
1.根据指定条件批量选中
for (int i = 0; i < comBoBox.Items.Count; i++)
{
if (comBoBox.Items[i].ToString() == "条件")
comBoBox.CheckBoxItems[i].Checked = true;
else
comBoBox.CheckBoxItems[i].Checked = false;
}
2.批量反选
for (int i = 0; i < comBoBox.Items.Count; i++)
{
if (comBoBox.CheckBoxItems[i].Checked)
comBoBox.CheckBoxItems[i].Checked = false;
else
comBoBox.CheckBoxItems[i].Checked = true;
}