📄 addpicture.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AddEditDeleteDataGridView
{
public delegate void SaveByte(byte[] PicByte);
public partial class AddPicture : Form
{
public byte[] Content;
private System.Windows.Forms.DataGridViewCell Curcell;
public AddPicture(System.Windows.Forms.DataGridViewCell cell)
{
InitializeComponent();
this.Curcell = cell;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void ShowDialogCmd_Click(object sender, EventArgs e)
{
this.openFileDialog1.FileName = "";
this.openFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.PicNameTxt.Text = openFileDialog1.FileName;
}
//用文件的路径信息创建一个文件对象
System.IO.FileInfo MyPicture = new System.IO.FileInfo(this.PicNameTxt.Text);
//检查文件的存在性
if (!MyPicture.Exists)
{
MessageBox.Show("文件不存在!");
}
else
{
//创建一字节数组,用来存储图像文件.(数组的长度是图像文件的长度)
Content = new byte[MyPicture.Length];
//打开文件并用他初始化一个文件流对象
System.IO.FileStream ImageFileStream = MyPicture.OpenRead();
//将文件内容写入字节数组
ImageFileStream.Read(Content, 0, Content.Length);
//关闭文件流
this.ShowPicBox.Image = Image.FromStream(ImageFileStream);
ImageFileStream.Close();
//用Content存储
}
}
//保存数据到UserGridView
private void button1_Click(object sender, EventArgs e)
{
this.Curcell.Value = this.Content;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -