Winform 常用的方法
一,Winform 如何内嵌窗体
1,判断窗体中是否以还有内嵌窗体
private void ClosePreForm()
{
foreach (Control item in this.spContainer.Panel2.Controls)
{
if (item is Form)
{
Form objControl = (Form)item;
objControl.Close();
}
}
}
2,嵌套form窗体到主窗体内
private void OpenForm(Form objForm)
{
ClosePreForm();
objForm.TopLevel = false;
objForm.FormBorderStyle = FormBorderStyle.None;
objForm.Parent = this.spContainer.Panel2;
objForm.Dock = DockStyle.Fill;
objForm.Show();
}
3, 选择指定后缀的文件
private void txtMusicFile_TextChanged(object sender, EventArgs e)
{
FolderBrowserDialog file = new FolderBrowserDialog();
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
fileDialog.Title = "请选择文件";
fileDialog.Filter = "所有文件(*mp3*)|*.mp3*";
if (file.ShowDialog() == DialogResult.OK)
{
//选择成功后,需要处理的代码
}
}
二,DataGridView常见的几种样式
/// <summary>
/// 设置DataGridView的样式
/// </summary>
public class DataGridViewStyle
{
/// <summary>
/// 普通的样式
/// </summary>
public void DgvStyle1(DataGridView dgv)
{
//奇数行的背景色
dgv.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
dgv.AlternatingRowsDefaultCellStyle.SelectionForeColor = System.Drawing.Color.Blue;
dgv.AlternatingRowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
dgv.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
//默认的行样式
dgv.RowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
dgv.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
dgv.RowsDefaultCellStyle.SelectionForeColor = System.Drawing.Color.Blue;
//数据网格颜色
dgv.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
//列标题的宽度
dgv.ColumnHeadersHeight = 30; }
/// <summary>
/// 凹凸样式
/// </summary>
/// 需要手动设置this.RowTemplate.DividerHeight = 2;
public void DgvStyle2(DataGridView dgv)
{
//奇数行的背景色
// this.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
//单元格边框样式
dgv.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.Sunken;
//列标题的边框样式
dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Sunken;
dgv.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dgv.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
dgv.ColumnHeadersHeight = 28;
//行的边框样式
dgv.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Sunken;
dgv.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
//this.DefaultCellStyle.ForeColor = System.Drawing.Color.Black;
//this.DefaultCellStyle.BackColor = System.Drawing.SystemColors.ButtonFace;
dgv.RowTemplate.DividerHeight = 1;
////禁止当前默认的视觉样式
dgv.EnableHeadersVisualStyles = false; //自动调整列宽
// this.AutoResizeColumns();
}
/// <summary>
/// 华丽的样式
/// </summary>
public void DgvStyle3(DataGridView dgv)
{
//未显示数据时的背景色
dgv.BackgroundColor = System.Drawing.SystemColors.ButtonFace;
//显示数据时的背景色
dgv.RowsDefaultCellStyle.BackColor = System.Drawing.Color.Black;
//数据网格颜色
dgv.GridColor = System.Drawing.Color.Red;
//列标题的边框样式
dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
//行的边框样式
dgv.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
////禁止当前默认的视觉样式
dgv.EnableHeadersVisualStyles = false;
//列标题的宽度
dgv.ColumnHeadersHeight = 35; //列标题的字体颜色
dgv.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.Color.Blue;
//列标题的背景颜色
dgv.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
//所有数据字体的颜色
int RowsCount = dgv.Columns.Count;
for (int i = 0; i < RowsCount; i++)
{
dgv.Columns[i].DefaultCellStyle.ForeColor = System.Drawing.Color.Yellow;
}
} /// <summary>
/// 给DataGridView添加行号
/// </summary>
/// <param name="dgv"></param>
/// <param name="e"></param>
public static void DgvRowPostPaint(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
{
try
{
//添加行号
SolidBrush v_SolidBrush = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor);
int v_LineNo = 0;
v_LineNo = e.RowIndex + 1;
string v_Line = v_LineNo.ToString();
e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
catch (Exception ex)
{
MessageBox.Show("添加行号时发生错误,错误信息:" + ex.Message, "操作失败");
}
}
}
Winform 常用的方法的更多相关文章
- Winform常用开发模式第一篇
Winform常用开发模式第一篇 上一篇博客最后我提到“异步编程模型”(APM),之后本来打算整理一下这方面的材料然后总结一下写篇文章与诸位分享,后来在整理的过程中不断的延伸不断地扩展,发现完全偏离了 ...
- DevExpress Winform 常用控件
Ø 前言 DevExpress 控件的功能比较强大,是全球知名控件开发公司,对于开发 B/S 或 C/S 都非常出色,可以实现很炫且功能强大的效果. DevExpress Winform 常用控件是 ...
- C#中WinForm程序退出方法技巧总结[转]
这篇文章主要介绍了C#中WinForm程序退出方法,实例总结了技巧退出WinForm程序窗口的各种常用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中WinForm程序退出方法技 ...
- C# Winform退出程序的方法介绍
这篇文章主要介绍了C#中WinForm程序退出方法, 实例总结了技巧退出WinForm程序窗口的各种常用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中WinForm程序退出方法技巧 ...
- WebAPi添加常用扩展方法及思维发散
前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...
- 【转】C#中WinForm程序退出方法技巧总结
C#中WinForm程序退出方法技巧总结 一.关闭窗体 在c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.Ex ...
- StringUtils中的常用的方法
org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...
- JOptionPane类提示框的一些常用的方法
JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...
- 常用js方法
function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...
随机推荐
- 虚幻4随笔6 Object和序列化
诚如之前所说,虚幻4主要的一些特性都是由UObject穿针引线在一起的,想把虚幻玩到比较深的程度,UObject是迟早要面对.回避不得的问题,所以,准备在其它主题之前,先把UObject好好弄一下.U ...
- event 自定义事件
自定义事件 1 public class Program 2 { 3 public event EventHandler ehdl=null; 4 public Program() 5 { 6 ehd ...
- Regularjs是什么
本文由作者郑海波授权网易云社区发布. 此文摘自regularjs的指南, 目前指南正在全面更新, 把老文档的[接口/语法部分]统一放到了独立的 Reference页面. Regularjs是基于动态模 ...
- OI字符串 简单学习笔记
持续更新qwq KMP 其实是MP啦qwq 就是先自己匹配自己得到状态图,然后再在上面进行模式串的匹配. nxt数组返回的是以该节点结尾的,最长的,在前面出现过的,不相交的,字符串的最靠右的,末位位置 ...
- 通过修改EIP寄存器实现32位程序的DLL注入
功能:通过修改EIP寄存器实现32位程序的DLL注入 <如果是64位 记得自己对应修改汇编代码部分> 原理:挂起目标进程,停止目标进程EIP的变换,在目标进程开启空间,然后把相关的指令机器 ...
- 【转】POJ分类很好很有层次感
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一 ...
- GPS欺骗(一)—无人机的劫持
本文作者:唯念那抹瑞利蓝 今天我们所讲的是GPS欺骗的方式和简单的定义.让大家对GPS欺骗这个方面有所了解.GPS是全世界地一个卫星定位系统,由美国制造. 0×01 例子2011年伊朗劫持美国无人机 ...
- elasticsearch 5.x Delete By Query API(根据条件删除)
之前在 2.X版本里 这个Delete By Query功能被去掉了 因为官方认为会引发一些错误 如需使用 需要自己安装插件. bin/plugin install delete-by-query 需 ...
- vsftp小记
安装一个vsftp都有问题(Version: 3.0.2-14ubuntu1),提示530 错误,之后修改配置如下(红色): # cat /etc/pam.d/vsftpdauth required ...
- Swinject 源码框架(一):基本原理
 核心是 Container类.它提供了两类方法,register 和 resolve. 为了找到在 resolve 时,能够找到对应的方法,内部维护了一个叫做services 的字典.key 是根 ...