/// <summary> /// 确定 /// </summary> /// <param Name="sender"></param> /// <param Name="e"></param> private void okBtn_Click(object sender, EventArgs e) { SVPageNode node = _svTreeView.SelectedNode as SVPageNode; if (node == null || node.Level != 2) { SVMessageBox msgBox = new SVMessageBox(); msgBox.content(Resource.提示, Resource.请选择页面); msgBox.ShowDialog(); return; } SVPageWidget widget = node.Addtionobj as SVPageWidget; ///模板文件 String file = Path.Combine(SVProData.TemplatePath, node.Text); if (File.Exists(file)) { SVMessageBox msgBox = new SVMessageBox(); msgBox.content(Resource.提示, node.Text + " " + Resource.模板已经存在); msgBox.ShowDialog(); return; } //保存文件 SVXml pageXML = new SVXml(); pageXML.createRootEle("Page"); widget.saveXML(pageXML); pageXML.writeXml(file); //保存缩略图 Bitmap ctlbitmap = new Bitmap(widget.Width, widget.Height); widget.DrawToBitmap(ctlbitmap, widget.ClientRectangle); ctlbitmap.Save(file + ".jpg"); //记录日志 SVLog.WinLog.Info(String.Format("模板{0}保存成功", node.Text)); this.DialogResult = System.Windows.Forms.DialogResult.Yes; }
/// <summary> /// 删除模板 /// </summary> /// <param Name="sender"></param> /// <param Name="e"></param> void delItem_Click(object sender, EventArgs e) { ListViewItem item = listView.SelectedItems[0]; SVMessageBox msg = new SVMessageBox(); msg.content("提示", String.Format("是否删除模板 {0}?", item.Text)); if (msg.ShowDialog() == System.Windows.Forms.DialogResult.No) { return; } ///将文件句柄释放,不然会被占用。无法删除文件。 if (this.pictureBox.Image != null) { this.pictureBox.Image.Dispose(); this.pictureBox.Image = null; GC.Collect(); } ///获取文件路径 String picFile = Path.Combine(SVProData.TemplatePath, item.Text + ".jpg"); String file = Path.Combine(SVProData.TemplatePath, item.Text); try { ///把文件从磁盘移除 File.Delete(picFile); File.Delete(file); ///列表中删除 listView.Items.Remove(item); } catch { SVLog.WinLog.Info("文件已经打开,删除不成功"); } }