一,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. [.net]数组

    在C语言中,数组是比较简单,也使用比较多的一种基础的数据结构.常用的有一维数组,二维数组等.但是在C#中,使用最多的是List,Dictionary等一些集合类,因为用他们来操作同类型的数据,比数组更 ...

  2. Could not load file or assembly '$SharePoint.Project.AssemblyFullName$'

    The fix is simple, do the following: 1.  Open your project file in NotePad 2.  Find the PropertyGrou ...

  3. 从B站、爱奇艺、映客的IPO上市,看国内视频公司的内容审核现状

    本文由  网易云发布. 3月30日,中央电视台<经济半小时>栏目讲述了网络上的一个顽症——色情内容.在这期主题为<互联网上的“色诱”>的节目中,央视的记者揭示了色情直播的猖獗. ...

  4. 程序媛计划——python初级课时1~2

    在命令行中运行py文件:python 文件路径/文件名 python变量必须赋值后才能使用,因为py变量只有赋值后才会被创建. py可以同时给多个变量赋值:a,b,c = 10,20,'dfjkdj' ...

  5. JQuery - 动态添加Html后,如何使CSS生效,JS代码可用?

    今天在开发JQuery Mobile程序时候,需要从服务器取得数据,随后显示在页面上的Listview控件中,数据完整获取到了,也动态添加到Listview控件中,但是数据对应的CSS没有任何效果了, ...

  6. 713. Subarray Product Less Than K

    Your are given an array of positive integers nums. Count and print the number of (contiguous) subarr ...

  7. 三,PHP缓存机制实现页面静态化

    页面静态化思路: 因为新闻这种信息对实时性要求不高,并且比较稳定,所以可以这样做:当地一个用户访问某条新闻后,我们使用ob缓存机制,将内容缓存到html页面.当下一次访问时候,直接访问html页面.这 ...

  8. 分布式ehcache缓存

    今天在这里了记录一下学习ehcache分布式集群的过程. ehcache的三种最为常用集群方式,分别是 RMI.JGroups 以及 EhCache Server . 这里主要讲一下rmi方式. 1. ...

  9. POJ 2392

    #include <iostream> #include <algorithm> #define MAXN 40005 using namespace std; struct ...

  10. IP等级

    IP是Ingress Protection的缩写,IP等级是针对电气设备外壳对异物侵入的防护等级,来源是国际电工委员会的标准IEC 60529,这个标准在2004年也被采用为美国国家标准.  在这个标 ...