• C#常用代码


    //载入资源字符串
    string s1 = Properties.Resources.id1;  

    //列表框示例
                listView1.Columns.Add("name");
                listView1.Columns.Add("age");
                listView1.Columns.Add("rollno");
                ListViewItem firstrecord = new ListViewItem("hope");//这个是第一行第一列
                firstrecord.SubItems.Add("22");//第一行第二列
                firstrecord.SubItems.Add("1001");//第一行第三列
                ListViewItem secondrecord = new ListViewItem("basil");//这个是第二行第一列
                secondrecord.SubItems.Add("23");//第二行第二列
                secondrecord.SubItems.Add("1002");//第二行第三列
                listView1.Items.Add(firstrecord);//把第一行添加上
                listView1.Items.Add(secondrecord);//把第二行添加上

    -------------------
    //打开文件对话框,并且把图片框换入新图片

     OpenFileDialog ofdPic = new OpenFileDialog();
                ofdPic.Filter = "JPG(*.JPG;*.JPEG);gif文件(*.GIF)|*.jpg;*.jpeg;*.gif";
                ofdPic.FilterIndex = 1;
                ofdPic.FileName = "";
                if (ofdPic.ShowDialog() == DialogResult.OK)
                {
                    MessageBox.Show("loadimage");
                   
                    string sPicPaht = ofdPic.FileName.ToString();
                    pictureBox1.LoadAsync(sPicPaht);

                }


    --------------------------------------------------------------------------------------------
    //状态栏写入内容

    编写其Tick事件为
    p rivate void timer1_Tick(object sender, EventArgs e)
    {
    this.toolStripStatusLabel3.Text = "系统当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
    }

    在Form的Load事件中 对timer1进行相关设置
    p rivate void MainForm_Load(object sender, EventArgs e)
    {
    this.toolStripStatusLabel3.Text = "系统当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
    this.timer1.Interval=1000;
    this.timer1.Start();
    }

    --------------------------------------------------------------------------------------------
    //静态类型File的用法
    System.IO.File.WriteAllText("D:/index/mx.htm", htmltext, System.Text.Encoding.GetEncoding("GB2312"));
    File.WriteAllLines(fName, s1, System.Text.Encoding.GetEncoding("utf-8"));

    -----------------------------------------------------------------------------------------------
    //save as 对话框

     SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "文本文件|*.txt";
                saveFileDialog.FilterIndex = 2;
                //saveFileDialog.RestoreDirectory = true;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                   
                        string fName = saveFileDialog.FileName;
                       
                        //File.WriteAllBytes(fName, richTextBox1.Text, System.Text.Encoding.GetEncoding("GB2312"));
                        string[] s1 = new string[1];
                        s1[0] = richTextBox1.Text;
                        File.WriteAllLines(fName, s1, System.Text.Encoding.GetEncoding("utf-8"));
                      
                       
                  
                }

    --------------------------------------------------------------------------------------------
    //树形框用法
     TreeNode RootNode = new TreeNode();
                TreeNode SonNode1 = new TreeNode("儿子1");
                TreeNode SonNode2 = new TreeNode("儿子2");

                RootNode.Text = "报表统计";

                RootNode.Nodes.Add("节点1");
                RootNode.Nodes.Add("节点2");
                RootNode.Nodes.Add("节点3");


                SonNode1.Nodes.Add("节点11");
                SonNode1.Nodes.Add("节点12");

                SonNode2.Nodes.Add("节点21");
                SonNode2.Nodes.Add("节点22");

                RootNode.Nodes.Add(SonNode1);
                RootNode.Nodes.Add(SonNode2);
                treeView1.Nodes.Add(RootNode);

    --------------------------------------------------------------------------------------------
     //String 拆分

    String[] s1 = new String[] {"----" };
                linktxt_array = fieldStr1.linktxt.Split(s1, StringSplitOptions.RemoveEmptyEntries);

  • 相关阅读:
    【Ionic+AngularJS 开发】之『个人日常管理』App(一)
    [热拔插] 轻量级Winform插件式框架
    Electron开发
    Cordova+Ionic之坑
    Unity学习笔记
    【树结构数据同步】公司部门—通讯录数据同步
    java enum用法
    Java中哈希表(Hashtable)是如何实现的
    注意for循环中变量的作用域
    BI-日期维度表-SQL SERVER
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668454.html
Copyright © 2020-2023  润新知