一,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 常用的方法的更多相关文章

  1. Winform常用开发模式第一篇

    Winform常用开发模式第一篇 上一篇博客最后我提到“异步编程模型”(APM),之后本来打算整理一下这方面的材料然后总结一下写篇文章与诸位分享,后来在整理的过程中不断的延伸不断地扩展,发现完全偏离了 ...

  2. DevExpress Winform 常用控件

    Ø  前言 DevExpress 控件的功能比较强大,是全球知名控件开发公司,对于开发 B/S 或 C/S 都非常出色,可以实现很炫且功能强大的效果. DevExpress Winform 常用控件是 ...

  3. C#中WinForm程序退出方法技巧总结[转]

      这篇文章主要介绍了C#中WinForm程序退出方法,实例总结了技巧退出WinForm程序窗口的各种常用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中WinForm程序退出方法技 ...

  4. C# Winform退出程序的方法介绍

    这篇文章主要介绍了C#中WinForm程序退出方法, 实例总结了技巧退出WinForm程序窗口的各种常用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中WinForm程序退出方法技巧 ...

  5. WebAPi添加常用扩展方法及思维发散

    前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...

  6. 【转】C#中WinForm程序退出方法技巧总结

    C#中WinForm程序退出方法技巧总结 一.关闭窗体 在c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.Ex ...

  7. StringUtils中的常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  8. JOptionPane类提示框的一些常用的方法

    JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...

  9. 常用js方法

    function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...

随机推荐

  1. 使用Git上传代码到远程仓库

    1.进入文件夹,cd f:/test/ 2.初始化远程仓库,git init 3.添加代码,git add . (注意add后面的点前面有一个空格) 4.提交代码到远程仓库,git commit -m ...

  2. 获取form表单元素值的4种方式

    <html><head><title></title><script type="text/javascript"> f ...

  3. C++ STL的容器类型

    1.顺序容器 2.关联容器 3.vector的使用 vector<数据类型> a; a.push_back(10)  -------->把数据从末末尾段插入vector里面 a.po ...

  4. 二叉查找树的实现——c++

    二叉查找树的c++实现: 1. 节点和二叉查找树的定义 1.1 二叉查找树节点 template <class T> class BSTNode{ public: T key; // 关键 ...

  5. web安全之——XSS、CSRF

    XSS漏洞 XSS 全称 Cross Site Scripting ,跨站脚本攻击.它的形成主要原因是多数用户输入没有转义,而被直接执行. 参考下面一段脚本: $('#box').html(locat ...

  6. 查看服务器CPU的个数、CPU的核数、多核超线程数、机器硬件型号

    这里有几个概念: 1.一台物理机的物理CPU的个数 2.一个CPU上的核数 3.一个核上面支持的线程数 有下面的计算公式: # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 ...

  7. 【xsy1504】 pitcure 树状数组

    数据范围:$n≤2\times 10^5$ 以下是题解: #include<bits/stdc++.h> #define L unsigned int #define MOD 167772 ...

  8. OS之内存管理 ---基本的内存管理策略(二)

    分段 基本方法 分段就是基于用户视图的内存管理方案.逻辑地址空间是由一组段构成的,每个段都有名称和长度.地址指定了段名称和段内偏移.因此用户通过两个量来指定地址:段名称和段偏移. 为了简单,进行对段的 ...

  9. Spring Security构建Rest服务-1204-Spring Security OAuth开发APP认证框架之Token处理

    token处理之一基本参数配置 处理token时间.存储策略,客户端配置等 以前的都是spring security oauth默认的token生成策略,token默认在org.springframe ...

  10. Spring Security构建Rest服务-0700-SpringSecurity开发基于表单的认证

    自定义用户认证逻辑: 1,处理用户信息获取,2,用户校验,3密码的加密解密 新建:MyUserDetailService类,实现UserDetailsService接口. UserDetailsSer ...