ExportWord.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.IO;
  9. using System.Windows.Forms;
  10. using System.Xml.Linq;
  11. namespace OTSReportTemplate
  12. {
  13. public partial class Mainframe : Form
  14. {
  15. public Mainframe()
  16. {
  17. InitializeComponent();
  18. _ctrlmsg = new ControlManager(this.designPanel);
  19. _ctrlmsg.myEvent += new formdel(GetCtrAttribute);
  20. }
  21. #region 字段定义部分
  22. private ControlManager _ctrlmsg = null;
  23. private string _ctrType = null;
  24. private bool _isLeftMouse = false;
  25. private bool _isHasSelectCtr = false;
  26. private Point origPt;
  27. private Point desPt;
  28. double x;
  29. double y;
  30. double lx;
  31. double ly;
  32. // string FileName = saveFileDialog1.FileName;
  33. #endregion
  34. //设计器鼠标按下消息
  35. private void designPanel_MouseDown(object sender, MouseEventArgs e)
  36. {
  37. _isLeftMouse = true;
  38. Graphics g = designPanel.CreateGraphics();
  39. g.Clear(Color.White);
  40. Control ctr = _ctrlmsg.PontTest(e.X, e.Y);
  41. if (ctr != null)
  42. {
  43. //_ctrlmsg.DrawCtrOuter(ctr);
  44. _isHasSelectCtr = true;
  45. }
  46. if (e.Button.ToString() == "Left")
  47. {
  48. _isLeftMouse = true;
  49. origPt.X = e.X;
  50. origPt.Y = e.Y;
  51. }
  52. }
  53. //设计器鼠标移动消息
  54. private void designPanel_MouseMove(object sender, MouseEventArgs e)
  55. {
  56. //Control ctrl = sender as Control;
  57. if (_isHasSelectCtr == false)
  58. {
  59. if (_isLeftMouse)
  60. {
  61. desPt.X = e.X;
  62. desPt.Y = e.Y;
  63. designPanel.Cursor = Cursors.Cross;
  64. _ctrlmsg.DrawRect(origPt, desPt);//5~1-a-s-p-x
  65. }
  66. }
  67. }
  68. //设计器鼠标抬起消息
  69. private void designPanel_MouseUp(object sender, MouseEventArgs e)
  70. {
  71. _isLeftMouse = false;
  72. _ctrlmsg.ismousedown = false;
  73. x = e.X / toolStripButton2.Width;
  74. y = e.Y / toolStripButton2.Height;
  75. lx = toolStripButton2.Image.Width * x;
  76. ly = toolStripButton2.Image.Height * y;
  77. if (e.X - origPt.X > 10 || e.X - origPt.X < -10)
  78. {
  79. // Control ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ComTable);
  80. Control ctr = null;
  81. if (_ctrType == "RichTextBox")
  82. {
  83. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ComTable);
  84. }
  85. if (_ctrType == "PictureBox")
  86. {
  87. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ComTable);
  88. }
  89. if (_ctrType == "ListTable")
  90. {
  91. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ListTable);
  92. }
  93. if (_ctrType == "ParTable")
  94. {
  95. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ParTable);
  96. }
  97. if (_ctrType == "SizTable")
  98. {
  99. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.SizTable);
  100. }
  101. if (_ctrType == "EleChart")
  102. {
  103. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.EleChart);
  104. }
  105. if (_ctrType == "ParChart")
  106. {
  107. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.ParChart);
  108. }
  109. if (_ctrType == "SizChart")
  110. {
  111. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.SizChart);
  112. }
  113. if (_ctrType == "TriTable")
  114. {
  115. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.TriTable);
  116. }
  117. if (_ctrType == "Icon")
  118. {
  119. ctr = _ctrlmsg.CreateCtr(origPt, e.X - origPt.X, e.Y - origPt.Y, _ctrType, Properties.Resources.optonIcon);
  120. }
  121. if (ctr == null)
  122. {
  123. MessageBox.Show("请创符合大小的控件!");
  124. }
  125. this.GetCtrAttribute(ctr);
  126. Graphics g = designPanel.CreateGraphics();
  127. g.Clear(Color.White);
  128. MessageBox.Show("图片上位置 X:" + lx, " 图片上位置Y:" + ly);
  129. }
  130. }
  131. //保存Html文件
  132. private void btn_SaveHtml_Click(object sender, EventArgs e)
  133. {
  134. SaveFileDialog dlg = new SaveFileDialog();
  135. dlg.Filter = "网页|*.html";
  136. DialogResult re = dlg.ShowDialog();
  137. {
  138. if (re == DialogResult.OK)
  139. {
  140. string filepath = dlg.FileName;
  141. StreamWriter writer = new StreamWriter(filepath);
  142. // string html = txtHtmlOutput.Text.Trim();
  143. // writer.Write(html);
  144. // writer.Close();
  145. }
  146. }
  147. }
  148. //点击创建按钮事件
  149. private void btn_BUTTON_Click(object sender, EventArgs e)
  150. {
  151. _ctrType = "Button";
  152. designPanel.Cursor = Cursors.Cross;
  153. }
  154. // 点击控件时显示属性
  155. public void SelectCtrAttribute(Control ctrl, bool isctrclick)
  156. {
  157. if (isctrclick)
  158. {
  159. this.GetCtrAttribute(ctrl);
  160. }
  161. else
  162. {
  163. MessageBox.Show("您没有选择相应的控件!");
  164. }
  165. }
  166. private void toolStripButton1_Click(object sender, EventArgs e)
  167. {
  168. _ctrlmsg.Sort();
  169. string html = _ctrlmsg.Execute();
  170. //txtHtmlOutput.Text = "";
  171. // txtHtmlOutput.Text = html;
  172. // mywebBrowser.DocumentText = html;//5+1+a+s+p+x
  173. }
  174. //获取控件属性
  175. public void GetCtrAttribute(Control ctrl)
  176. {
  177. if (ctrl != null)
  178. {
  179. txtCtrName.Text = ctrl.Name;
  180. txtCtrText.Text = ctrl.Text;
  181. txtCtrWidth.Text = ctrl.Width.ToString();
  182. txtCtrHeight.Text = ctrl.Height.ToString();
  183. }
  184. else
  185. {
  186. MessageBox.Show("请创建适合大小的控件!");
  187. }
  188. }
  189. private void btn_AddLable_Click(object sender, EventArgs e)
  190. {
  191. _ctrType = "Label";
  192. designPanel.Cursor = Cursors.Cross;
  193. }
  194. private void btn_AddTextBox_Click(object sender, EventArgs e)
  195. {
  196. _ctrType = "TextBox";
  197. designPanel.Cursor = Cursors.Cross;
  198. }
  199. private void btn_AddRichTextBox_Click(object sender, EventArgs e)
  200. {
  201. _ctrType = "RichTextBox";
  202. designPanel.Cursor = Cursors.Cross;
  203. }
  204. private void btn_AddRadioButton_Click(object sender, EventArgs e)
  205. {
  206. _ctrType = "RadioButton";
  207. designPanel.Cursor = Cursors.Cross;
  208. }
  209. //成分分布表
  210. private void btn_AddPictureBox_Click(object sender, EventArgs e)
  211. {
  212. _ctrType = "PictureBox";
  213. designPanel.Cursor = Cursors.Cross;
  214. }
  215. //颗粒列表
  216. private void btn_AddPictureBoxOne_Click(object sender, EventArgs e)
  217. {
  218. _ctrType = "ListTable";
  219. designPanel.Cursor = Cursors.Cross;
  220. }
  221. //颗粒平均元素成分含量
  222. private void btn_AddPictureBoxTwo_Click(object sender, EventArgs e)
  223. {
  224. _ctrType = "ParTable";
  225. designPanel.Cursor = Cursors.Cross;
  226. }
  227. //颗粒尺寸分布表
  228. private void btn_AddPictureBoxThree_Click(object sender, EventArgs e)
  229. {
  230. _ctrType = "SizTable";
  231. designPanel.Cursor = Cursors.Cross;
  232. }
  233. //元素成分图
  234. private void btn_AddPictureBoxFour_Click(object sender, EventArgs e)
  235. {
  236. _ctrType = "EleChart";
  237. designPanel.Cursor = Cursors.Cross;
  238. }
  239. //元素成分表
  240. private void btn_AddPictureBoxFive_Click(object sender, EventArgs e)
  241. {
  242. _ctrType = "ParChart";
  243. designPanel.Cursor = Cursors.Cross;
  244. }
  245. //颗粒成分图
  246. private void btn_AddPictureBoxSix_Click(object sender, EventArgs e)
  247. {
  248. _ctrType = "SizChart";
  249. designPanel.Cursor = Cursors.Cross;
  250. }
  251. //颗粒尺寸分布图
  252. private void btn_AddPictureBoxSeven_Click(object sender, EventArgs e)
  253. {
  254. _ctrType = "TriTable";
  255. designPanel.Cursor = Cursors.Cross;
  256. }
  257. //公司图标
  258. private void btn_AddPictureBoxEight_Click(object sender, EventArgs e)
  259. {
  260. _ctrType = "Icon";
  261. designPanel.Cursor = Cursors.Cross;
  262. }
  263. private void btn_AddCheckBox_Click(object sender, EventArgs e)
  264. {
  265. _ctrType = "CheckBox";
  266. designPanel.Cursor = Cursors.Cross;
  267. }
  268. private void btn_AddComBox_Click(object sender, EventArgs e)
  269. {
  270. _ctrType = "ComBox";
  271. designPanel.Cursor = Cursors.Cross;
  272. }
  273. private void btn_SaveXML_Click(object sender, EventArgs e)
  274. {
  275. _ctrlmsg.ExecuteXML();
  276. }
  277. //修改控件名
  278. private void txtCtrName_KeyDown(object sender, KeyEventArgs e)
  279. {
  280. if (_ctrlmsg._selectCtr != null)
  281. {
  282. _ctrlmsg._selectCtr.Name = txtCtrName.Text;
  283. }
  284. }
  285. //修改控件文本值
  286. private void txtCtrText_KeyDown(object sender, KeyEventArgs e)
  287. {
  288. if (_ctrlmsg._selectCtr != null)
  289. {
  290. _ctrlmsg._selectCtr.Text = txtCtrText.Text;
  291. }
  292. }
  293. //修改控件宽度
  294. private void txtCtrWidth_KeyDown(object sender, KeyEventArgs e)
  295. {
  296. if (txtCtrWidth.Text.ToString() != "")
  297. {
  298. if (_ctrlmsg._selectCtr != null)
  299. {
  300. _ctrlmsg._selectCtr.Width = Convert.ToInt32(txtCtrWidth.Text.ToString());
  301. }
  302. }
  303. }
  304. //修改控件高度
  305. private void txtCtrHeight_KeyDown(object sender, KeyEventArgs e)
  306. {
  307. if (txtCtrHeight.Text.ToString() != "")
  308. {
  309. if (_ctrlmsg._selectCtr != null)
  310. {
  311. _ctrlmsg._selectCtr.Height = Convert.ToInt32(txtCtrHeight.Text.ToString());//5|1|a|s|p|x
  312. }
  313. }
  314. }
  315. private void toolStripButton2_Click(object sender, EventArgs e)
  316. {
  317. _ctrType = "RadioButton";
  318. designPanel.Cursor = Cursors.Cross;
  319. }
  320. private void btn_Save_Click(object sender, EventArgs e)
  321. {
  322. //SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  323. //if (this.btn_AddRichTextBox.Text == "")
  324. // return;
  325. //saveFileDialog1.DefaultExt = "c:\\test.txt";
  326. //saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  327. //DialogResult a = saveFileDialog1.ShowDialog();
  328. //if (a == DialogResult.Cancel)
  329. // return;
  330. //string FileName = saveFileDialog1.FileName;
  331. //if (a == DialogResult.OK && FileName.Length > 0)
  332. // {
  333. // Save the contents of the RichTextBox into the file.
  334. //richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
  335. try
  336. {
  337. Write();
  338. Write("用户信息编辑模块" + "\r\n" + "报告模板公司:" + "\n\n\n" + btn_AddRichTextBox.Text + "\r\n" + "字体大小:\n\n\n" + comboBox1.SelectedItem + "\r\n" +
  339. "排列方式:\n\n\n" + comboBox2.SelectedItem + "\r\n" + "图片信息:" + "\r\n" + toolStripButton2.Text + "\r\n" + "图片位置" + lx + "\r\n" + "图片位置" + ly);
  340. //转换成word文档
  341. Microsoft.Office.Interop.Word.Application newapp = new Microsoft.Office.Interop.Word.Application();//用这句也能初始化
  342. // Word.Application newapp = new Word.ApplicationClass();
  343. Microsoft.Office.Interop.Word.Document newdoc;
  344. object nothing = System.Reflection.Missing.Value;//用于作为函数的默认参数
  345. newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);//生成一个word文档
  346. newapp.Visible = true;//是否显示word程序界面
  347. object oEndOfDoc = "\\endofdoc";
  348. Microsoft.Office.Interop.Word.Range rang1 = newdoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
  349. //设置居中等问题
  350. Microsoft.Office.Interop.Word.Paragraph oPara1 = newdoc.Content.Paragraphs.Add(ref nothing);
  351. rang1.Text = btn_AddRichTextBox.Text + "-" + comboBox1.SelectedItem + "-" + comboBox2.SelectedItem;
  352. Microsoft.Office.Interop.Word.Font f = new Microsoft.Office.Interop.Word.Font();
  353. //f.Size = Convert.ToSingle(comboBox1.SelectedItem.ToString());
  354. if (comboBox2.SelectedItem == "居中")
  355. {
  356. oPara1.Range.Text = btn_AddRichTextBox.Text; //插入文本
  357. oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
  358. }
  359. if (comboBox2.SelectedItem == "右对齐")
  360. {
  361. oPara1.Range.Text = btn_AddRichTextBox.Text;
  362. oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
  363. }
  364. if (comboBox2.SelectedItem == "左对齐")
  365. {
  366. oPara1.Range.Text = btn_AddRichTextBox.Text;
  367. oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
  368. }
  369. rang1.Start = 0;
  370. rang1.End = btn_AddRichTextBox.Text.Length;
  371. rang1.Font = f;
  372. //插入图片
  373. object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
  374. newapp.Selection.EndKey(ref unite, ref nothing);//将光标移至文末
  375. //newapp.Selection.HomeKey(ref unite, ref nothing);//将光标移至文开头
  376. newapp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;
  377. newapp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
  378. object LinkToFile = false;
  379. object SaveWithDocument = true;
  380. object Anchor = newapp.Selection.Range;
  381. string picname = "d:\\kk.jpg";
  382. // string comtable = "d:\\ComTable.jpg";
  383. string listtable = "d:\\ListTable.jpg";
  384. this.outpicture(picname, Properties.Resources.ComTable);
  385. this.outpicture(listtable, Properties.Resources.ListTable);
  386. newdoc.InlineShapes.AddPicture(picname, ref LinkToFile, ref SaveWithDocument, ref Anchor);
  387. newdoc.InlineShapes.AddPicture(listtable, ref LinkToFile, ref SaveWithDocument, ref Anchor);
  388. newdoc.InlineShapes[1].Height = 100;
  389. newdoc.InlineShapes[1].Width = 100;
  390. newdoc.Content.InsertAfter("\n");
  391. newapp.Selection.EndKey(ref unite, ref nothing);//将光标移至文末
  392. newapp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
  393. newapp.Selection.Font.Size = 10;
  394. // newapp.Selection.TypeText("图1 袁冶\n");
  395. newapp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
  396. newdoc.Content.InsertAfter("\n");
  397. newdoc.Content.InsertAfter("\n");
  398. //用这种方式也可以插入公式,并且这种方法更简单
  399. newapp.Selection.Font.Size = 14;
  400. // newapp.Selection.InsertFormula(ref formula, ref nothing);
  401. newapp.Selection.Font.Size = 10;
  402. // newapp.Selection.TypeText("..............................(式2)\n");
  403. newapp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
  404. // newapp.Selection.TypeText("表1 电子产品\n");
  405. }
  406. catch (IOException ex)
  407. {
  408. Console.WriteLine(ex.ToString());
  409. }
  410. MessageBox.Show("文件已成功保存");
  411. }
  412. //写入txt文件
  413. public void Write()
  414. {
  415. SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  416. DialogResult a = saveFileDialog1.ShowDialog();
  417. string FileName = saveFileDialog1.FileName;
  418. if (a == DialogResult.OK && FileName.Length > 0)
  419. {
  420. FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
  421. //获得字节数组
  422. byte[] data = System.Text.Encoding.Default.GetBytes("用户信息编辑模块" + "\r\n" + "报告模板公司:" + "\n\n\n" + btn_AddRichTextBox.Text + "\r\n" + "字体大小:\n\n\n" + comboBox1.SelectedItem + "\r\n" +
  423. "排列方式:\n\n\n" + comboBox2.SelectedItem + "\r\n" + "图片信息:" + "\r\n" + toolStripButton2.Text + "\r\n" + "图片位置" + lx + "\r\n" + "图片位置" + ly);
  424. //开始写入
  425. fs.Write(data, 0, data.Length);
  426. //清空缓冲区、关闭流
  427. fs.Flush();
  428. fs.Close();
  429. }
  430. }
  431. //读取txt文件
  432. public void Write(string path)
  433. {
  434. SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  435. string FileName = saveFileDialog1.FileName;
  436. if (FileName.Length > 0)
  437. {
  438. FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
  439. StreamWriter sw = new StreamWriter(fs);
  440. //开始写入
  441. sw.Write("用户信息编辑模块" + "\r\n" + "报告模板公司:" + "\n\n\n" + btn_AddRichTextBox.Text + "\r\n" + "字体大小:\n\n\n" + comboBox1.SelectedItem + "\r\n" +
  442. "排列方式:\n\n\n" + comboBox2.SelectedItem + "\r\n" + "图片信息:" + toolStripButton2.Size + "\r\n" + toolStripButton2.Text + "\r\n" + "图片位置" + lx + "\r\n" + "图片位置" + ly);
  443. //清空缓冲区
  444. sw.Flush();
  445. //关闭流
  446. sw.Close();
  447. fs.Close();
  448. }
  449. }
  450. // }
  451. //}
  452. private void CreateImage(string content)
  453. {
  454. //判断字符串不等于空和null
  455. if (content == null || content.Trim() == String.Empty)
  456. return;
  457. //创建一个位图对象
  458. Bitmap image = new Bitmap((int)Math.Ceiling((content.Length * 18.0)), 30);
  459. //创建Graphics
  460. Graphics g = Graphics.FromImage(image);
  461. try
  462. {
  463. //清空图片背景颜色
  464. g.Clear(Color.White);
  465. Font font = new Font("Arial", 15.5f, (FontStyle.Bold));
  466. System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.DarkRed, 1.2f, true);
  467. g.DrawString(content, font, brush, 2, 2);
  468. //画图片的边框线
  469. g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
  470. image.Save("d:/001.jpg");
  471. }
  472. finally
  473. {
  474. g.Dispose();
  475. image.Dispose();
  476. }
  477. }
  478. #region MyRegion
  479. public void GetControlInfo()
  480. {
  481. foreach (var item in this.designPanel.Controls)
  482. {
  483. if (item is PictureBox)
  484. {
  485. int controlType = 0;
  486. int width = ((PictureBox)item).Width;
  487. int height = ((PictureBox)item).Height;
  488. string Name = ((PictureBox)item).Name;
  489. string Text = "";
  490. int ImageWidth = ((PictureBox)item).Image.Size.Width;
  491. int ImageHeight = ((PictureBox)item).Image.Size.Height;
  492. int fontSize = 0;
  493. int sortMode = (int)((PictureBox)item).Dock;
  494. ControlInfoClass aa = new ControlInfoClass();
  495. aa.ControlType = controlType;
  496. aaList.Add(aa);
  497. }
  498. if (item is RichTextBox)
  499. {
  500. int controlTypeText = 0;
  501. int width = ((RichTextBox)item).Width;
  502. int height = ((RichTextBox)item).Height;
  503. string Name = ((RichTextBox)item).Name;
  504. string Text = "";
  505. int fontSizeText = 0;
  506. int sortMode = (int)((RichTextBox)item).Dock;
  507. ControlInfoClass aa = new ControlInfoClass();
  508. aa.ControlType = controlTypeText;
  509. aaList.Add(aa);
  510. }
  511. }
  512. }
  513. #endregion
  514. static List<ControlInfoClass> aaList = new List<ControlInfoClass>();
  515. private void outpicture(string filename, System.Drawing.Bitmap bmap)
  516. {
  517. bmap.Save(filename);
  518. }
  519. public class ControlInfoClass
  520. {
  521. int controlType = 0;
  522. int width = 0;
  523. int height = 0;
  524. string name = "";
  525. string text = "";
  526. int imageWidth = 0;
  527. int imageHeight = 0;
  528. int fontSize = 0;
  529. int sortMode = 0;
  530. public int ControlType
  531. {
  532. get { return controlType; }
  533. set { controlType = value; }
  534. }
  535. public int Width
  536. {
  537. get { return width; }
  538. set { width = value; }
  539. }
  540. public int Height
  541. {
  542. get { return height; }
  543. set { height = value; }
  544. }
  545. public string Name
  546. {
  547. get { return name; }
  548. set { name = value; }
  549. }
  550. public string Text
  551. {
  552. get { return text; }
  553. set { text = value; }
  554. }
  555. public int ImageWidth
  556. {
  557. get { return imageWidth; }
  558. set { imageWidth = value; }
  559. }
  560. public int ImageHeight
  561. {
  562. get { return imageHeight; }
  563. set { imageHeight = value; }
  564. }
  565. public int FontSize
  566. {
  567. get { return fontSize; }
  568. set { fontSize = value; }
  569. }
  570. public int SortMode
  571. {
  572. get { return sortMode; }
  573. set { sortMode = value; }
  574. }
  575. }
  576. private void toolStripButton2_MouseUp(object sender, MouseEventArgs e)
  577. {
  578. int startX;
  579. int startY;
  580. startX = designPanel.Width; //- toolStripButton2.Width / 2;
  581. startY = designPanel.Height;/// - toolStripButton2.Height / 2;
  582. }
  583. private void button1_Click(object sender, EventArgs e)
  584. {
  585. SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  586. DialogResult a = saveFileDialog1.ShowDialog();
  587. string FileName = saveFileDialog1.FileName;
  588. if (a == DialogResult.OK && FileName.Length > 0)
  589. {
  590. try
  591. {
  592. Write("用户信息编辑模块" + "\r\n" + "报告模板公司:" + "\n\n\n" + btn_AddRichTextBox.Text + "\r\n" + "字体大小:\n\n\n" + comboBox1.SelectedItem + "\r\n" +
  593. "排列方式:\n\n\n" + comboBox2.SelectedItem + "\r\n" + "图片信息:" + toolStripButton2.Size + "\r\n" + toolStripButton2.Text + "\r\n" + "图片位置" + lx + "\r\n" + "图片位置" + ly);
  594. }
  595. catch (IOException ex)
  596. {
  597. Console.WriteLine(ex.ToString());
  598. }
  599. MessageBox.Show("成功");
  600. }
  601. }
  602. InformationClass m_class;
  603. InformationClass GetCompanytitle()
  604. {
  605. m_class.Companytitle = btn_AddRichTextBox.Text;
  606. return m_class;
  607. }
  608. InformationClass GetSize()
  609. {
  610. m_class.Size = comboBox1.SelectedItem.ToString();
  611. return m_class;
  612. }
  613. InformationClass GetArrangement()
  614. {
  615. m_class.Arrangement = comboBox2.SelectedItem.ToString();
  616. return m_class;
  617. }
  618. //InformationClass GetCompanyIcon()
  619. //{
  620. // m_class.CompanyIcon = toolStripButton2.Size.ToString();
  621. // return m_class;
  622. //}
  623. GridChartClass g_class;
  624. GridChartClass GetPicSize()
  625. {
  626. g_class.PicSize = toolStripButton2.Size.ToString();
  627. return g_class;
  628. }
  629. //图片横坐标
  630. GridChartClass GetPicPositionX()
  631. {
  632. g_class.PicPosition = lx.ToString();
  633. // g_class.PicPosition = ly.ToString();
  634. return g_class;
  635. }
  636. //图片纵坐标
  637. GridChartClass GetPicPositionY()
  638. {
  639. g_class.PicPosition = ly.ToString();
  640. return g_class;
  641. }
  642. //基本信息类
  643. class InformationClass
  644. {
  645. public string Companytitle; //公司名称
  646. public string Size;//字体大小
  647. public string Arrangement; //排列方式
  648. // public string CompanyIcon;//公司图标
  649. }
  650. //图以及表类
  651. class GridChartClass
  652. {
  653. public string PicSize;//图片大小
  654. public string PicPosition;//图片位置
  655. }
  656. }
  657. }