• 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);

  • 相关阅读:
    在Ubuntu20.04上安装MySQL8.0及正确配置[已验证]
    Linux Ubuntu 20.04 —添加开机启动(服务/脚本)
    Ubuntu进入文件夹路径及查看文件夹目录
    Ubuntu20.04安装JDK
    How to install shutter on Linux 20.04
    在Ubuntu 20.04 中以管理员Root 身份用可视化的方式打开根目录文件夹
    在Ubuntu 20.04 上安装Chromium
    Ubuntu20.04安装搜狗输入法的详细步骤
    Ubuntu 20.04换国内源 清华源 阿里源 中科大源 163源
    linux Deepin 20 系统更新源.txt
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668454.html
Copyright © 2020-2023  润新知