MFC cgridctrl 合并单元格 10
哪位大神可以帮我在MFCGridcontrol2.27版本中帮我重绘一个合并单元格的程序,所有的源文件都必须包含在程序中...
哪位大神可以帮我在MFC Grid control 2.27版本中帮我重绘一个合并单元格的程序,所有的源文件都必须包含在程序中
展开
1个回答
展开全部
仅供参考:
private void FormChart_Load(object sender, EventArgs e)
{
//生成DataTable
DataTable dta = new DataTable("Test");
dta.Columns.Add("ID", typeof(System.Int32));
dta.Columns.Add("Name", typeof(System.String));
dta.Columns.Add("Address", typeof(System.String));
dta.Columns.Add("Image",typeof(System.Byte[]));
//图片路径
string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\image\\Status_OK.png";
Image img = new Bitmap(filePath);
byte[] imgBytes = ImageToBytes(img);
dta.Rows.Add(new object[] { 1, "张三", "北京市海淀区" , imgBytes });
dta.Rows.Add(new object[] { 1, "李四", "北京市朝阳区", imgBytes });
dta.Rows.Add(new object[] { 1, "王五", "北京市东城区", imgBytes });
dta.Rows.Add(new object[] { 1, "赵六", "北京市西城区", imgBytes });
dta.AcceptChanges();
//设置行高
gv.RowHeight = 32;
//格式化图片列
RepositoryItemPictureEdit pic = new RepositoryItemPictureEdit();
//图片居中
pic.PictureAlignment = ContentAlignment.MiddleCenter;
//图片垂直拉伸
pic.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
gv.Columns["Image"].ColumnEdit = pic;
//绑定
grid.DataSource = dta;
}
/// <summary>
/// Image 转成 Byte[]
/// </summary>
/// <param name="image">图片</param>
/// <returns></returns>
public static byte[] ImageToBytes(Image image)
{
ImageFormat format = image.RawFormat;
using (MemoryStream ms = new MemoryStream())
{
if (format.Equals(ImageFormat.Jpeg))
{
image.Save(ms, ImageFormat.Jpeg);
}
else if (format.Equals(ImageFormat.Png))
{
image.Save(ms, ImageFormat.Png);
}
else if (format.Equals(ImageFormat.Bmp))
{
image.Save(ms, ImageFormat.Bmp);
}
else if (format.Equals(ImageFormat.Gif))
{
image.Save(ms, ImageFormat.Gif);
}
else if (format.Equals(ImageFormat.Icon))
{
image.Save(ms, ImageFormat.Icon);
}
byte[] buffer = new byte[ms.Length];
//Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin
ms.Seek(0, SeekOrigin.Begin);
ms.Read(buffer, 0, buffer.Length);
return buffer;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询