C#相关控件使用总结

1、ComBox控件

这里写图片描述

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            int Dimethod=comboBox1.SelectedIndex.ToString();    //所选择的数据的索引号

            textBox1.Text += "\r\n"+"差异图生成方法为:";
            textBox1.Text += comboBox1.SelectedItem.ToString() + "\r\n";

        }

2、Button保存图片

这里写图片描述

private void button4_Click(object sender, EventArgs e)
        {
            //save change detection result
            SaveFileDialog savefiledialog = new SaveFileDialog();
            savefiledialog.Title = "图片另存为";
            savefiledialog.Filter = "jpg图片|*.JPG|png图片|*.PNG|jpeg图片|*.JPEG|gif图片|*.GIF|tif图片|*.TIF";
            savefiledialog.FilterIndex = 1;
            savefiledialog.RestoreDirectory = true;
            if (savefiledialog.ShowDialog() == DialogResult.OK)
            {
                //System.IO.FileStream fs = (System.IO.FileStream)savefiledialog.OpenFile();  //输出文件
                string filename = savefiledialog.FileName;
                pictureBox3.Image.Save(filename);

            }

        }

3、textBox

这里写图片描述
右击属性设置为多行,多行当长度超出textBox长度时可以自动换行。
这里写图片描述

滑动到底部

 private void textBox1_TextChanged(object sender, EventArgs e)
        {

           // textBox1.Select(textBox1.Text.Length,0);
            this.textBox1.Focus(); //获取焦点
            this.textBox1.Select(this.textBox1.TextLength,0);
            this.textBox1.ScrollToCaret();
            //textBox1.SelectionStart = textBox1.Text.Length;
        }

在textBox中显示内容如下:
+=表示接着上面的内容输出,不清空先前的内容;
回车换行用”\r\n”

textBox1.Text += System.Environment.NewLine + "差异图分析方法为:";
textBox1.Text += comboBox2.SelectedItem.ToString() + "\r\n";

4、button

更新pictureBox中的图片,,如果已经存在图片则释放旧图片重新加载新的图片;

        private void button3_Click_1(object sender, EventArgs e)
        {

            if (string.IsNullOrEmpty(pathname1) || string.IsNullOrEmpty(pathname2))
            {
                MessageBox.Show("请选择进行检测的图片");
            }


            if (string.IsNullOrEmpty(Dimethod))
            {
                MessageBox.Show("请选择生成差异图方法");
            }

             if (string.IsNullOrEmpty(DiAnalysismethod))
            {
                MessageBox.Show("请选择差异图分析方法");
            }

             if ((!string.IsNullOrEmpty(pathname1)) && (!string.IsNullOrEmpty(pathname2)) & (!string.IsNullOrEmpty(Dimethod)) && (!string.IsNullOrEmpty(DiAnalysismethod)))
             {
                 textBox1.Text += System.Environment.NewLine + "开始执行变化检测部分......" + "\r\n";
                     unsafe
                   {

                    int Dimethod1 = int.Parse(Dimethod);
                    int DiAnalysismethod2 = int.Parse(DiAnalysismethod);


                    if (pictureBox3.Image != null)     //zhi shi fang , hui zi dong fu gai
                    {
                        pictureBox3.Image.Dispose();   //PictureBox3显示这个进程占用了输出图片;释放掉。
                    }

                    string args = string.Format("{0} {1} {2} {3} {4} ", pathname1, pathname2, Dimethod1, DiAnalysismethod2, outPath);
                    //args = args.Replace("\\", "/");

                  //  StartCallbackProcess(@"M:\CDWindow\x64\Debug\CDexe.exe", args);
                    //StartCallbackProcess(@"M:\MyCD\CDWindow\x64\Debug\CDexe.exe", args);

                    StartCallbackProcess(exepath, args);


                    //    MyChangeDetection(Intptr1, Intptr2, Dimethod1, DiAnalysismethod2, Intptr3);
                    textBox1.Text += System.Environment.NewLine + "变化检测完成!" + "\r\n";

               //     String  outPath=new String(outpathname);
                    Image image = Image.FromFile(@outPath);
                    pictureBox3.Image = image;

                   }

              }


          }

5、groupBox可以分组管理控件,-》集合

这里写图片描述

6、【学习OpenCV】通过DLL实现图像数据从.dat导入Mat

链接:http://lib.csdn.net/article/opencv/26184

猜你喜欢

转载自blog.csdn.net/zhenaoxi1077/article/details/81477996