ControlManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using System.Xml.Linq;
  10. //using OTSIncAReporttApp.OTSDataMgrFunction;
  11. namespace OTSReportTemplate
  12. {
  13. public delegate void formdel(Control ctr);
  14. public class ControlManager//:OTSReportInterfaceBase
  15. {
  16. #region 定义字段部分
  17. private Panel _panel;
  18. private PictureBox _picturebox;
  19. private Mainframe _fram = null;
  20. Pen _pen = null;
  21. Brush _brush = null;
  22. public Control _selectCtr = null;
  23. List<Control> _ctrLst = new List<Control>();
  24. int btnnumber = 0;
  25. int labnumber = 0;
  26. int textboxnumber = 0;
  27. int richtxtnumber = 0;
  28. int radionumber = 0;
  29. int chknumber = 0;
  30. int comboxnumber = 0;
  31. int picnumber = 0;
  32. int datagridview = 0;
  33. int lisnumber = 0;
  34. int parnumber = 0;
  35. int siznumber = 0;
  36. // int trinumber = 0;
  37. int elenumber = 0;
  38. int parcnumber = 0;
  39. int sizenumber = 0;
  40. int tricnumber = 0;
  41. int iconnumber = 0;
  42. public bool ismousedown = false;
  43. Point CtrlMouseDownPt;
  44. bool isMoveCtr = false;
  45. bool isMouseResize = false;
  46. public bool isctrclick = false;
  47. public event formdel myEvent;
  48. #endregion
  49. public void Show()
  50. {
  51. Mainframe frm = new Mainframe();
  52. frm.Show();
  53. }
  54. public ControlManager(Panel pan)
  55. {
  56. _panel = pan;
  57. //_picturebox = picturebox;
  58. _brush = new SolidBrush(Color.LightGray);
  59. _pen = new Pen(_brush);
  60. }
  61. public ControlManager()
  62. {
  63. }
  64. //点击控件
  65. private void Ctrl_MouseClick(object sender, MouseEventArgs e)
  66. {
  67. _selectCtr = sender as Control;
  68. if (_selectCtr != null)
  69. {
  70. myEvent(_selectCtr);
  71. isctrclick = true;
  72. }
  73. }
  74. //键盘删除事件
  75. private void Ctr_KeyDown(object sender, KeyEventArgs e)
  76. {
  77. if (e.KeyCode == Keys.Delete)
  78. {
  79. if (_selectCtr != null)
  80. {
  81. _selectCtr.Dispose();
  82. _ctrLst.Remove(_selectCtr);
  83. _panel.Controls.Remove(_selectCtr);
  84. //_picturebox.Controls.Remove(_selectCtr);
  85. }
  86. }
  87. }
  88. //移动控件及控制其大小
  89. private void Ctr_MoveCtrl(object sender, MouseEventArgs e)
  90. {
  91. if (isctrclick == false)
  92. {
  93. _selectCtr = sender as Control;
  94. if (_selectCtr != null)
  95. {
  96. if (_selectCtr.GetType() == typeof(RichTextBox))
  97. {
  98. if (e.X > _selectCtr.Width / 2 - 15 && e.X < _selectCtr.Width / 2 + 15 && e.Y > _selectCtr.Height / 2 + 10)
  99. {
  100. _selectCtr.Cursor = Cursors.SizeNS;
  101. if (ismousedown)
  102. {
  103. _selectCtr.Size = new System.Drawing.Size(_selectCtr.Width, e.Y);//5%1%a%s%p%x
  104. }
  105. }
  106. else if (e.X > _selectCtr.Width - 10 && e.Y > _selectCtr.Height / 2 - 10 && e.Y < _selectCtr.Height / 2 + 10)
  107. {
  108. _selectCtr.Cursor = Cursors.SizeWE;
  109. if (ismousedown)
  110. {
  111. _selectCtr.Size = new System.Drawing.Size(e.X, _selectCtr.Height);
  112. }
  113. }
  114. else
  115. {
  116. _selectCtr.Cursor = Cursors.SizeAll;
  117. if (ismousedown)
  118. {
  119. int x = e.X - CtrlMouseDownPt.X;
  120. int y = e.Y - CtrlMouseDownPt.Y;
  121. _selectCtr.Location = new System.Drawing.Point(_selectCtr.Location.X + x, _selectCtr.Location.Y + y);
  122. }
  123. }
  124. }
  125. else
  126. {
  127. if (ismousedown)
  128. {
  129. if (isMouseResize)
  130. {
  131. _selectCtr.Size = new System.Drawing.Size(e.X, _selectCtr.Height);
  132. }
  133. else if (isMoveCtr)
  134. {
  135. int x = e.X - CtrlMouseDownPt.X;
  136. int y = e.Y - CtrlMouseDownPt.Y;
  137. _selectCtr.Location = new System.Drawing.Point(_selectCtr.Location.X + x, _selectCtr.Location.Y + y);
  138. }
  139. }
  140. else if (e.X > _selectCtr.Width - 10 && e.Y > _selectCtr.Height / 2 - 10 && e.Y < _selectCtr.Height / 2 + 10)
  141. {
  142. _selectCtr.Cursor = Cursors.SizeWE;
  143. }
  144. else
  145. {
  146. _selectCtr.Cursor = Cursors.SizeAll;
  147. }
  148. }
  149. }
  150. }
  151. else
  152. {
  153. if (_selectCtr != null)
  154. {
  155. if (_selectCtr.GetType() == typeof(RichTextBox))
  156. {
  157. if (e.X > _selectCtr.Width / 2 - 15 && e.X < _selectCtr.Width / 2 + 15 && e.Y > _selectCtr.Height / 2 + 10)
  158. {
  159. _selectCtr.Cursor = Cursors.SizeNS;
  160. if (ismousedown)
  161. {
  162. _selectCtr.Size = new System.Drawing.Size(_selectCtr.Width, e.Y);
  163. }
  164. }
  165. else if (e.X > _selectCtr.Width - 10 && e.Y > _selectCtr.Height / 2 - 10 && e.Y < _selectCtr.Height / 2 + 10)
  166. {
  167. _selectCtr.Cursor = Cursors.SizeWE;
  168. if (ismousedown)
  169. {
  170. _selectCtr.Size = new System.Drawing.Size(e.X, _selectCtr.Height);
  171. }
  172. }
  173. else
  174. {
  175. _selectCtr.Cursor = Cursors.SizeAll;
  176. if (ismousedown)
  177. {
  178. int x = e.X - CtrlMouseDownPt.X;
  179. int y = e.Y - CtrlMouseDownPt.Y;
  180. _selectCtr.Location = new System.Drawing.Point(_selectCtr.Location.X + x, _selectCtr.Location.Y + y);
  181. }
  182. }
  183. }
  184. else
  185. {
  186. if (ismousedown)
  187. {
  188. if (isMouseResize)
  189. {
  190. _selectCtr.Size = new System.Drawing.Size(e.X, _selectCtr.Height);
  191. }
  192. else if (isMoveCtr)
  193. {
  194. int x = e.X - CtrlMouseDownPt.X;
  195. int y = e.Y - CtrlMouseDownPt.Y;
  196. _selectCtr.Location = new System.Drawing.Point(_selectCtr.Location.X + x, _selectCtr.Location.Y + y);
  197. }
  198. }
  199. else if (e.X > _selectCtr.Width - 10 && e.Y > _selectCtr.Height / 2 - 10 && e.Y < _selectCtr.Height / 2 + 10)
  200. {
  201. _selectCtr.Cursor = Cursors.SizeWE;
  202. }
  203. else
  204. {
  205. _selectCtr.Cursor = Cursors.SizeAll;
  206. }
  207. }
  208. }
  209. }
  210. }
  211. internal Control CreateCtr(Point origPt, int v1, int v2, string ctrType, object comTable)
  212. {
  213. throw new NotImplementedException();
  214. }
  215. //鼠标按下控件
  216. private void Ctr_MouseDown(object sender, MouseEventArgs e)
  217. {
  218. _selectCtr = sender as Control;
  219. ismousedown = true;
  220. CtrlMouseDownPt.X = e.X;
  221. CtrlMouseDownPt.Y = e.Y;
  222. if (e.X > _selectCtr.Width - 10 && e.Y > _selectCtr.Height / 2 - 10 && e.Y < _selectCtr.Height / 2 + 10)
  223. {
  224. isMouseResize = true;
  225. isMoveCtr = false;
  226. }
  227. else
  228. {
  229. isMouseResize = false;
  230. isMoveCtr = true;
  231. }
  232. // e = null;
  233. }
  234. //鼠标离开控件
  235. private void Ctr_MouseUp(object sender, MouseEventArgs e)
  236. {
  237. ismousedown = false;
  238. isMoveCtr = false;
  239. isMouseResize = false;
  240. }
  241. //创建控件
  242. public Control CreateCtr(Point pt, int w, int h, string ctrType, Image img)
  243. {
  244. int y = pt.Y; ;
  245. int temp = y / 45;
  246. pt.Y = 45 * temp;
  247. int height = 300;
  248. if (-45 < w && w < 45)
  249. {
  250. return null;
  251. }
  252. if (_ctrLst.Count > 0)
  253. {
  254. for (int i = 0; i < _ctrLst.Count; i++)
  255. {
  256. if (_ctrLst[i].Location.Y == pt.Y)
  257. {
  258. if (pt.X + w > _ctrLst[i].Location.X && pt.X < _ctrLst[i].Location.X)
  259. {
  260. w = _ctrLst[i].Location.X - pt.X - 5;
  261. }
  262. else if (pt.X < _ctrLst[i].Location.X + _ctrLst[i].Width)
  263. {
  264. w -= (_ctrLst[i].Location.X + _ctrLst[i].Width - pt.X);
  265. w -= 5;
  266. pt.X = _ctrLst[i].Location.X + _ctrLst[i].Width + 5;
  267. }
  268. }
  269. else
  270. {
  271. if (pt.X > _ctrLst[i].Location.X && pt.X + w < _ctrLst[i].Location.X + _ctrLst[i].Width)
  272. {
  273. w = -pt.X + (_ctrLst[i].Location.X + _ctrLst[i].Width) + 5;
  274. }
  275. }
  276. }
  277. }
  278. Control ctr = null;
  279. if (ctrType == "Button")
  280. {
  281. btnnumber++;
  282. ctr = new Button();
  283. ctr.Name = "Button" + btnnumber.ToString();
  284. ctr.Text = "Button" + btnnumber.ToString();
  285. }
  286. else if (ctrType == "Label")
  287. {
  288. labnumber++;
  289. ctr = new Label();
  290. ctr.Name = "label" + labnumber.ToString();
  291. ctr.Text = "label" + labnumber.ToString();
  292. }
  293. //成分分布表
  294. else if (ctrType == "PictureBox")
  295. {
  296. picnumber++;
  297. PictureBox ctrPBox = new PictureBox();
  298. ctrPBox.Name = "PictureBox" + picnumber.ToString();
  299. ctrPBox.Text = "PictureBox" + picnumber.ToString();
  300. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  301. ctrPBox.BackgroundImage = img;
  302. ctr = ctrPBox;
  303. // ctrOne = ctrPBox;
  304. }
  305. else if (ctrType == "ListTable")
  306. {
  307. lisnumber++;
  308. PictureBox ctrPBox = new PictureBox();
  309. ctrPBox.Name = "ListTable" + lisnumber.ToString();
  310. ctrPBox.Text = "ListTable" + lisnumber.ToString();
  311. ctrPBox.BackgroundImage = img;
  312. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  313. ctr = ctrPBox;
  314. // ctrOne = ctrPBox;
  315. }
  316. else if (ctrType == "ParTable")
  317. {
  318. parnumber++;
  319. PictureBox ctrPBox = new PictureBox();
  320. ctrPBox.Name = "ParTable" + parnumber.ToString();
  321. ctrPBox.Text = "ParTable" + parnumber.ToString();
  322. ctrPBox.BackgroundImage = img;
  323. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  324. ctr = ctrPBox;
  325. // ctrOne = ctrPBox;
  326. }
  327. else if (ctrType == "SizTable")
  328. {
  329. siznumber++;
  330. PictureBox ctrPBox = new PictureBox();
  331. ctrPBox.Name = "SizTable" + siznumber.ToString();
  332. ctrPBox.Text = "SizTable" + siznumber.ToString();
  333. ctrPBox.BackgroundImage = img;
  334. ctrPBox.SizeMode = PictureBoxSizeMode.Zoom;
  335. ctr = ctrPBox;
  336. // ctrOne = ctrPBox;
  337. }
  338. else if (ctrType == "EleChart")
  339. {
  340. elenumber++;
  341. PictureBox ctrPBox = new PictureBox();
  342. ctrPBox.Name = "EleChart" + elenumber.ToString();
  343. ctrPBox.Text = "EleChart" + elenumber.ToString();
  344. ctrPBox.BackgroundImage = img;
  345. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  346. ctr = ctrPBox;
  347. // ctrOne = ctrPBox;
  348. }
  349. else if (ctrType == "ParChart")
  350. {
  351. parcnumber++;
  352. PictureBox ctrPBox = new PictureBox();
  353. ctrPBox.Name = "ParChart" + parcnumber.ToString();
  354. ctrPBox.Text = "ParChart" + parcnumber.ToString();
  355. ctrPBox.BackgroundImage = img;
  356. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  357. ctr = ctrPBox;
  358. // ctrOne = ctrPBox;
  359. }
  360. else if (ctrType == "SizChart")
  361. {
  362. sizenumber++;
  363. PictureBox ctrPBox = new PictureBox();
  364. ctrPBox.Name = "SizChart" + sizenumber.ToString();
  365. ctrPBox.Text = "SizChart" + sizenumber.ToString();
  366. ctrPBox.BackgroundImage = img;
  367. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  368. ctr = ctrPBox;
  369. // ctrOne = ctrPBox;
  370. }
  371. else if (ctrType == "TriTable")
  372. {
  373. tricnumber++;
  374. PictureBox ctrPBox = new PictureBox();
  375. ctrPBox.Name = "TriTable" + tricnumber.ToString();
  376. ctrPBox.Text = "TriTable" + tricnumber.ToString();
  377. ctrPBox.BackgroundImage = img;
  378. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  379. ctr = ctrPBox;
  380. // ctrOne = ctrPBox;
  381. }
  382. else if (ctrType == "Icon")
  383. {
  384. iconnumber++;
  385. PictureBox ctrPBox = new PictureBox();
  386. ctrPBox.Name = "Icon" + iconnumber.ToString();
  387. ctrPBox.Text = "Icon" + iconnumber.ToString();
  388. ctrPBox.BackgroundImage = img;
  389. ctrPBox.SizeMode = PictureBoxSizeMode.StretchImage;
  390. ctr = ctrPBox;
  391. height = h;
  392. }
  393. else if (ctrType == "TextBox")
  394. {
  395. textboxnumber++;
  396. ctr = new TextBox();
  397. ctr.Name = "TextBox" + textboxnumber.ToString();
  398. ctr.Text = "TextBox" + textboxnumber.ToString();
  399. }
  400. else if (ctrType == "RichTextBox")
  401. {
  402. richtxtnumber++;
  403. ctr = new RichTextBox();
  404. ctr.Name = "RichTextBox" + richtxtnumber.ToString();
  405. ctr.Text = "公司名" + richtxtnumber.ToString();
  406. height = h;
  407. }
  408. else if (ctrType == "RadioButton")
  409. {
  410. radionumber++;
  411. ctr = new RadioButton();
  412. ctr.Name = "RadioButton" + radionumber.ToString();
  413. ctr.Text = "RadioButton" + radionumber.ToString();
  414. }
  415. else if (ctrType == "CheckBox")
  416. {
  417. chknumber++;
  418. ctr = new CheckBox();
  419. ctr.Name = "CheckBox" + chknumber.ToString();
  420. ctr.Text = "CheckBox" + chknumber.ToString();
  421. }
  422. else if (ctrType == "ComBox")
  423. {
  424. comboxnumber++;
  425. ctr = new ComboBox();
  426. ctr.Name = "ComboBox" + comboxnumber.ToString();
  427. ctr.Text = "ComboBox" + comboxnumber.ToString();
  428. }
  429. //添加grid
  430. else if (ctrType == "DataGridView")
  431. {
  432. datagridview++;
  433. DataGridView ctrDGrid = new DataGridView();
  434. ctrDGrid.Name = "DataGridView" + comboxnumber.ToString();
  435. ctrDGrid.Text = "DataGridView" + comboxnumber.ToString();
  436. ctr = ctrDGrid;
  437. }
  438. if (ctr != null)
  439. {
  440. ctr.Location = new System.Drawing.Point(pt.X, pt.Y);
  441. ctr.Size = new System.Drawing.Size(w, height);
  442. _panel.Controls.Add(ctr);
  443. ctr.MouseClick += new System.Windows.Forms.MouseEventHandler(Ctrl_MouseClick);
  444. ctr.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Ctr_MoveCtrl);
  445. ctr.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Ctr_MouseDown);
  446. ctr.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Ctr_MouseUp);
  447. ctr.KeyDown += new KeyEventHandler(this.Ctr_KeyDown);
  448. AddCtrl(ctr);
  449. }
  450. return ctr;
  451. }
  452. //判断绘制位置是否已有控件
  453. public Control PontTest(int x, int y)
  454. {
  455. if (_ctrLst.Count > 0)
  456. {
  457. for (int i = 0; i < _ctrLst.Count; i++)
  458. {
  459. if (_ctrLst[i].Location.X < x && x < _ctrLst[i].Location.X + _ctrLst[i].Width && y > _ctrLst[i].Location.Y && y < _ctrLst[i].Location.Y + _ctrLst[i].Height)
  460. {
  461. return _ctrLst[i];
  462. }
  463. }
  464. }
  465. return null;
  466. }
  467. //添加控件到列表
  468. public void AddCtrl(Control ctrl)
  469. {
  470. _ctrLst.Add(ctrl);
  471. }
  472. //控件排序
  473. public void Sort()
  474. {
  475. for (int i = 0; i < _ctrLst.Count; i++)
  476. {
  477. for (int j = i + 1; j < _ctrLst.Count; j++)
  478. {
  479. Control temp = _ctrLst[i];
  480. if (_ctrLst[i].Location.Y > _ctrLst[j].Location.Y)
  481. {
  482. _ctrLst[i] = _ctrLst[j];
  483. _ctrLst[j] = temp;
  484. }
  485. else if (_ctrLst[i].Location.X > _ctrLst[j].Location.X && _ctrLst[j].Location.Y - _ctrLst[i].Location.Y < 20)
  486. {
  487. _ctrLst[i] = _ctrLst[j];
  488. _ctrLst[j] = temp;
  489. }
  490. }
  491. }
  492. }
  493. //绘制矩形框
  494. public void DrawRect(Point p1, Point p2)
  495. {
  496. Graphics g = _panel.CreateGraphics();
  497. g.Clear(Color.White);
  498. if (p2.X < p1.X)
  499. {
  500. int temp = p2.X;
  501. p2.X = p1.X;
  502. p1.X = temp;
  503. }
  504. if (p2.Y < p1.Y)
  505. {
  506. int temp = p2.Y;
  507. p2.Y = p1.Y;
  508. p1.Y = temp;
  509. }
  510. g.DrawRectangle(_pen, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y);
  511. }
  512. //生成HTML代码
  513. public string Execute()
  514. {
  515. string sqlHead = "create table test(ID int IDENTITY(1,1) NOT NULL,";
  516. string str = "";
  517. string head = "<html><head> this is test</head><title>this is title test</title><body><form action=\"http://www.baidu.com\"><table>";
  518. string end = "</td></tr></table></from></body></html>";
  519. int y = -1;
  520. for (int i = 0; i < _ctrLst.Count; i++)
  521. {
  522. string temp = "";
  523. Control ctr = _ctrLst[i];
  524. //文本框
  525. if (ctr.GetType() == typeof(TextBox))
  526. {
  527. temp = "<tr><td><input type=\"text\" name=" + ctr.Name.ToString() + "/>";
  528. sqlHead += ctr.Name.ToString() + " varchar(50),";
  529. if (ctr.Location.Y - y >= 30 && y != -1)
  530. {
  531. temp = "</td></tr>" + temp;
  532. }
  533. }
  534. else if (ctr.GetType() == typeof(Button))
  535. {
  536. temp = "<tr><td><input type=\"submit\" value=\"" + ctr.Text.ToString() + " \" style =\" width:" + ctr.Width + "; height:" + ctr.Height + " \">";
  537. if (ctr.Location.Y - y > 30 && y != -1)
  538. {
  539. temp = "</td></tr>" + temp;
  540. }
  541. }
  542. else if (ctr.GetType() == typeof(RichTextBox))
  543. {
  544. temp = "<tr><td><textarea id=\"" + ctr.Name.ToString() + "\" style=\"width:" + ctr.Width.ToString() + ";height:" + ctr.Height.ToString() + "\"; ></textarea>";
  545. sqlHead += ctr.Name.ToString() + " varchar(1024),";
  546. if (ctr.Location.Y - y > 30 && y != -1)
  547. {
  548. temp = "</td></tr>" + temp;
  549. }
  550. }
  551. else if (ctr.GetType() == typeof(Label))
  552. {
  553. temp = "<tr><td><span id=\" " + ctr.Name.ToString() + " \" style =\"width: " + ctr.Width.ToString() + ";height:" + ctr.Height.ToString() + "\";>" + ctr.Text.ToString() + "</span>";
  554. if (ctr.Location.Y - y > 30 && y != -1)
  555. {
  556. temp = "</td></tr>" + temp;
  557. }
  558. }
  559. else if (ctr.GetType() == typeof(RadioButton))
  560. {
  561. temp = "<tr><td><span style =\"width:" + ctr.Width.ToString() + ";height:" + ctr.Height.ToString() + "\"><input id=\"" + ctr.Name + "\" type=\"radio\" checked=\"checked\"/><lable for=\"" + ctr.Name.ToString() + "\">" + ctr.Text.ToString() + "</label></span>";
  562. if (ctr.Location.Y - y > 30 && y != -1)
  563. {
  564. temp = "</td></tr>" + temp;
  565. }
  566. }
  567. else if (ctr.GetType() == typeof(CheckBox))
  568. {
  569. temp = "<tr><td><span style =\"width:" + ctr.Width.ToString() + ";height:" + ctr.Height.ToString() + "\"><input id=\"" + ctr.Name + "\" type=\"checkbox\" checked=\"checked\"/><lable for=\"" + ctr.Name.ToString() + "\">" + ctr.Text.ToString() + "</label></span>";
  570. if (ctr.Location.Y - y > 30 && y != -1)
  571. {
  572. temp = "</td></tr>" + temp;
  573. }
  574. }
  575. else if (ctr.GetType() == typeof(ComboBox))
  576. {
  577. ComboBox ctrl = ctr as ComboBox;
  578. string optionStr = "</td></tr>";
  579. for (int j = 0; j < ctrl.Items.Count; j++)
  580. {
  581. optionStr += "<option>" + ctrl.Items[j].ToString() + "</option>";
  582. }
  583. temp = "<select name=\"" + ctr.Name + "\" id=\"" + ctr.Name + "\" style=\"height:" + ctr.Height + "; width:" + ctr.Width + "\">" + optionStr + "</select>";
  584. if (ctr.Location.Y - y > 30 && y != -1)
  585. {
  586. temp = "</td></tr>" + temp;
  587. }
  588. }
  589. y = ctr.Location.Y;
  590. str = str + temp;
  591. }
  592. if (sqlHead.EndsWith(","))
  593. {
  594. sqlHead = sqlHead.Substring(0, sqlHead.Length - 1);
  595. }
  596. sqlHead += ")";
  597. str = head + str + end;
  598. return str;
  599. }
  600. //生成XML代码
  601. public string ExecuteXML()
  602. {
  603. XElement root = new XElement("Form");
  604. XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), root);
  605. int removeLen = "System.Windows.Forms.".Length;
  606. for (int i = 0; i < _ctrLst.Count; i++)
  607. {
  608. Control ctr = _ctrLst[i];
  609. string t = ctr.GetType().ToString();
  610. t = t.Substring(removeLen, t.Length - removeLen);
  611. XElement node = new XElement(t);
  612. XAttribute X = new XAttribute("X", ctr.Location.X.ToString());
  613. XAttribute Y = new XAttribute("Y", ctr.Location.Y.ToString());
  614. XAttribute W = new XAttribute("W", ctr.Width.ToString());
  615. XAttribute H = new XAttribute("H", ctr.Height.ToString());
  616. XAttribute name = new XAttribute("name", ctr.Name);
  617. node.Add(X);
  618. node.Add(Y);
  619. node.Add(W);
  620. node.Add(H);
  621. node.Add(name);
  622. root.Add(node);
  623. }
  624. xdoc.Save("D:\\test.xml");
  625. return "dd";
  626. }
  627. }
  628. }