C#单击metrogrid或datagridview中的按钮后如何查看图像 [英] C# how to see image after clicking on button in metrogrid or datagridview

查看:368
本文介绍了C#单击metrogrid或datagridview中的按钮后如何查看图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有注册表单,用户可以在其中填写数据名称,姓氏等,并可以从计算机上传图像。上传图像后,当我点击按钮注册时,该用户的数据保存在数据库中。然后我有另一种形式,我可以在metroGrid中看到所有注册用户,但只有他们的名字,姓氏,日期,国家和我在metroGrid中也有详细信息按钮。当我点击详细信息按钮,打开另一个表格,我可以看到用户的所有数据`图像也一样。一切都没关系,我可以看到除了Image之外的所有数据,它给了我错误。问题是什么?



这是注册表格 [ ^ ]

这是用户的表格 [ ^ ]

这是表单,我可以看到用户的所有数据和例外 [ ^ ]

这是数据库中的用户表 [ ^ ]



我尝试过:



I have register form,where Users can fill their datas`Name,Surname and so on, and can upload image from computer.After uploading image, when i click on button Register,that user's datas saving in database.Then i have another form where i can see all registered users in metroGrid,but only their Name,Surname,Date,Country and i also have Details button in metroGrid.when i click on Details button,opens another form where i can see user's all data` the image too.Everything is okay,i can see all datas except Image, it gives me error.What's the problem?

This is Register form[^]
This is User's form[^]
This is the form,where i can see user's all datas,and Exception[^]
This is Users table in Database[^]

What I have tried:

 //Upload button click
 private void bunifuImageButton6_Click(object sender, EventArgs e)
        {
            this.op = new OpenFileDialog();
            if (op.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = new Bitmap(op.FileName);
            }
            this.n = Path.GetFileName(op.SafeFileName);
        }
//Register button click
            string a = textBox1.Text;
            string b = textBox2.Text;
            string c = textBox3.Text;
            string d = textBox4.Text;
            string f = textBox5.Text;
            n = pictureBox1.Image.ToString();
            DateTime g = dateTimePicker1.Value;
                using (var context = new Suren_BankEntities())
                {
                    User user = new User()
                    {
                        Name = a,
                        Surname = b,
                        Country = c,
                        Login = d,
                        Password = f,
                        Date = g,
                        Photo = n,
                    };
               }
//MetroGrid's CellContentClick
 private void metroGrid1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = metroGrid1.CurrentCell.RowIndex;
            int id = (int)metroGrid1.Rows[index].Cells["Id"].Value;
            if (metroGrid1.Columns[e.ColumnIndex].Name == "Details")
            {
                    UserDatas u = new UserDatas(id);
                    u.Show();
            }
        }

private void UserDatas_Load(object sender, EventArgs e)
        {
            using (var context = new Suren_BankEntities())
            {
                User founded = context.Users.Find(id);
                label20.Text = founded.Name;
                label19.Text = founded.Surname;
                label18.Text = founded.Date.ToString();
                label17.Text = founded.Country;
                label16.Text = founded.CardNumber.ToString();
                label15.Text = founded.Login;
                label14.Text = founded.Password;
                label13.Text = founded.AMD.ToString();
                label12.Text = founded.RUR.ToString();
                label11.Text = founded.USD.ToString();
                pictureBox1.Image = new Bitmap(founded.Photo);
            }
        }

推荐答案

n = pictureBox1.Image.ToString();



在图像上使用ToString()不会得到照片的二进制。



它为您提供了一个.NET类名。



(之后与图像有关的内容并不多。)


Using "ToString()" on an image doesn't get you a "binary" of a "photo".

It get you a .NET "class name".

(Not much relating to "images" makes sense after that).


这篇关于C#单击metrogrid或datagridview中的按钮后如何查看图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆