using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using Stone.Common; namespace Stone.WinModule.MyControl { public partial class MyImageEdit : UserControl { public bool IsPicEdit = false; private bool _ReadOnly = false; [CategoryAttribute(""), DescriptionAttribute("设为只读")] public bool ReadOnly { get { return _ReadOnly; } set { _ReadOnly = value; if (_ReadOnly) { this.panel1.Visible = false; } } } public MyImageEdit() { InitializeComponent(); } public string GetImage() { string ret = ""; if (IsPicEdit) { if (this.SummaryPic.Image != null) { byte[] buff = MyImage.ImageToBuffer(this.SummaryPic.Image, System.Drawing.Imaging.ImageFormat.Jpeg); ret = MyImage.BufferToString(buff); } } return ret; } public void SetImage(string ImgStr) { IsPicEdit = true; if (ImgStr == "") { this.SummaryPic.Image = null; } else { byte[] buff = MyImage.StringToBuffer(ImgStr); this.SummaryPic.Image = MyImage.BufferToImage(buff); } } private void btnPicSelect_Click(object sender, EventArgs e) { try { if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { //this.SummaryPic.Image = MyImage.ReadImageFile(this.openFileDialog1.FileName); Bitmap bmp = new Bitmap(this.openFileDialog1.FileName); this.SummaryPic.Image = bmp; IsPicEdit = true; } } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnPicRemove_Click(object sender, EventArgs e) { try { if (this.SummaryPic.Image == null) throw new Exception("没有可删除的图片"); if (!MyMessageBox.ShowQuestion("是否要删除图片?")) return; this.SummaryPic.Image = null; IsPicEdit = true; } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnPicSave_Click(object sender, EventArgs e) { try { if (this.SummaryPic.Image == null) throw new Exception("没有可另存的图片"); if (this.saveFileDialog1.ShowDialog() == DialogResult.OK) { this.SummaryPic.Image.Save(this.saveFileDialog1.FileName); MyMessageBox.ShowInfoMessage(this.saveFileDialog1.FileName + " 另存成功"); } } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void SummaryPic_Click(object sender, EventArgs e) { try { if (this.SummaryPic.Image == null) throw new Exception("没有图片"); frmImageView frm = new frmImageView(); frm.pic.Image = this.SummaryPic.Image; frm.ShowDialog(); frm.Dispose(); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } } }