GE.cs 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320
  1. /*****************************************************************************************
  2. ** ***************************************** **
  3. ** **********File name:Ge.cs, Version 1.0, 8 November 2004** **
  4. ** *************************Authors: MingZhang and Mayank Bansal******************** **
  5. ** ***************************************** **
  6. ** **
  7. ** This class provides an interface between user and functions. The form gets loaded **
  8. ** when software is opened. It captures various actions performed by user and it calls **
  9. ** corresponding functions to be implemented for the actions. **
  10. ** The following classes are defined here: **
  11. ** 1.GE: This class loads the form and it is the main entry point of software. **
  12. ** 2.Canvas: All the drawing in Graphical Editor is done on the canvas. **
  13. ** Canvas class is used to define the drawing area **
  14. ** 3.GraEditStackMgr: This class is used to perform Redo and Undo operations **
  15. ** **
  16. ******************************************************************************************/
  17. using System;
  18. using System.Drawing;
  19. using System.Drawing.Drawing2D;
  20. using System.Collections;
  21. using System.ComponentModel;
  22. using System.Windows.Forms;
  23. using System.Data;
  24. using System.Drawing.Imaging;
  25. using System.IO;
  26. using System.Drawing.Printing;
  27. using System.Diagnostics;
  28. using DockToolbar;
  29. using GraEditor.DrawTools;
  30. using GraEditor.Elements;
  31. namespace GraEditor
  32. {
  33. /// <summary>
  34. ///Main windows of Graphic Editor
  35. /// </summary>
  36. public class GE : System.Windows.Forms.Form
  37. {
  38. private MainView mainView; //Inherit from System.Windows.Forms.Panel
  39. private System.Windows.Forms.ContextMenu contextMenu1;
  40. private System.Windows.Forms.ToolBarButton tlBtnLine;
  41. private System.Windows.Forms.ToolBarButton tlBtnFrameRect;
  42. private System.Windows.Forms.ToolBarButton tlBtnFillRect;
  43. private System.Windows.Forms.ToolBarButton tlBtnZoomIn;
  44. private System.Windows.Forms.ToolBarButton tlBtnZoomOut;
  45. private System.Windows.Forms.ToolBarButton tlBtnZoomResume;
  46. private System.Windows.Forms.MenuItem pasteMenuItem;
  47. private System.Windows.Forms.ToolBarButton tlBtnFrameEllipse;
  48. private System.Windows.Forms.ToolBarButton tlBtnFillEllipse;
  49. private System.Windows.Forms.ToolBarButton tlBtnImage;
  50. private System.Windows.Forms.ToolBarButton tlBtnText;
  51. private System.Windows.Forms.ToolBarButton tlBtnLines;
  52. private System.Windows.Forms.MainMenu mainMenu1;
  53. private System.Windows.Forms.MenuItem menuItem12;
  54. private System.Windows.Forms.MenuItem menuNew;
  55. private System.Windows.Forms.MenuItem menuFile;
  56. private System.Windows.Forms.MenuItem menuOpen;
  57. private System.Windows.Forms.MenuItem menuSave;
  58. private System.Windows.Forms.MenuItem menuSaveAs;
  59. private System.Windows.Forms.MenuItem menuExit;
  60. private System.Windows.Forms.MenuItem menuUndo;
  61. private System.Windows.Forms.MenuItem menuRedo;
  62. private System.Windows.Forms.MenuItem menuCopy;
  63. private System.Windows.Forms.MenuItem menuCut;
  64. private System.Windows.Forms.MenuItem menuView;
  65. private System.Windows.Forms.MenuItem menuImgSetting;
  66. private System.Windows.Forms.MenuItem menuHelp;
  67. private System.Windows.Forms.ToolBarButton tlBtnErase;
  68. private System.Windows.Forms.MenuItem menuItemCanvasBackColor;
  69. private System.Windows.Forms.ToolBarButton sep2;
  70. private System.Windows.Forms.ToolBarButton sep3;
  71. private System.Windows.Forms.ToolBarButton sep4;
  72. private System.Windows.Forms.MenuItem menuItem1;
  73. private System.Windows.Forms.MenuItem menuItem5;
  74. private System.Windows.Forms.MenuItem menuItem4;
  75. private System.Windows.Forms.MenuItem menuItem24;
  76. private System.Windows.Forms.MenuItem menuPrint;
  77. private System.Windows.Forms.MenuItem menuRecentFiles;
  78. private System.Windows.Forms.MenuItem menuEdit;
  79. private System.Windows.Forms.MenuItem menuZoom;
  80. private System.Windows.Forms.MenuItem menuZoomIn;
  81. private System.Windows.Forms.MenuItem menuZoomOut;
  82. private System.Windows.Forms.MenuItem menuResume;
  83. private System.Windows.Forms.MenuItem menuColorSettings;
  84. private System.Windows.Forms.MenuItem menuHelpIndex;
  85. private System.Windows.Forms.MenuItem menuAboutGE;
  86. private System.Windows.Forms.MenuItem menuStatusBar;
  87. private System.Windows.Forms.ImageList GE_imageList;
  88. private System.Windows.Forms.ToolBar GE_toolBar;
  89. private System.Windows.Forms.StatusBar GE_statusBar;
  90. private System.ComponentModel.IContainer components;
  91. private Chris.Beckett.MenuImageLib.MenuImage _menuImages;
  92. private System.Windows.Forms.MenuItem menuToolbar;
  93. private System.Windows.Forms.ToolBar GE_toolBar1;
  94. private System.Windows.Forms.ToolBarButton tlBtnNew;
  95. private System.Windows.Forms.ToolBarButton tlBtnOpen;
  96. private System.Windows.Forms.ToolBarButton tlBtnSave;
  97. private System.Windows.Forms.ToolBarButton sp1;
  98. private System.Windows.Forms.ToolBarButton tlBtnSelect;
  99. private System.Windows.Forms.ToolBarButton tlBtnCopy;
  100. private System.Windows.Forms.ToolBarButton tlBtnCut;
  101. private System.Windows.Forms.ToolBarButton sp2;
  102. private System.Windows.Forms.ToolBarButton sp5;
  103. private System.Windows.Forms.ToolBarButton tlBtnUndo;
  104. private System.Windows.Forms.ToolBarButton tlBtnRedo;
  105. private System.Windows.Forms.ToolBarButton tlBtnFont;
  106. private System.Windows.Forms.ToolBarButton tlBtnColor;
  107. private System.Drawing.Printing.PrintDocument printDocument1;
  108. private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
  109. private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
  110. private System.Windows.Forms.MenuItem menuPrintPreview;
  111. private System.Windows.Forms.MenuItem menuPageSetting;
  112. private System.Windows.Forms.ToolBarButton tlBtnPenWidth;
  113. private System.Windows.Forms.ContextMenu muPenWidth;
  114. private System.Windows.Forms.StatusBarPanel sbPanelTip;
  115. private System.Windows.Forms.StatusBarPanel sbPanelViewScale;
  116. private System.Windows.Forms.StatusBarPanel sbPanelMousePos;
  117. private System.Windows.Forms.MenuItem menuItemCanvasSize;
  118. private System.Windows.Forms.ToolBarButton tlBtnFreehand;
  119. private System.Windows.Forms.StatusBarPanel sbPanelFont;
  120. ToolBarManager _toolBarManager;
  121. public GE()
  122. {
  123. //
  124. // Required for Windows Form Designer support.
  125. //
  126. InitializeComponent();
  127. InitPenWidthToolBarButton();
  128. //
  129. // TODO: InitializeComponent
  130. //
  131. this.sbPanelViewScale.Text ="100%";
  132. Canvas canvas = Canvas.Instance;
  133. canvas.MainView = this.mainView;
  134. canvas.Modified +=new EventHandler(canvas_Modified);
  135. canvas.Init(null,new Size(600,600),Color.White);
  136. // The parameter to the constructor sets the form where the toolbars can be docked.
  137. // This would be your application main form
  138. _toolBarManager = new ToolBarManager(this, this);
  139. // The control Text property is used to draw the bar name while floating
  140. // and on view/hide menu.
  141. //_toolBar1.Text = "Bar #1";
  142. GE_toolBar.Text = "Drawing Toolbar";
  143. GE_toolBar1.Text = "File Operations";
  144. _toolBarManager.AddControl(GE_toolBar, DockStyle.Left);
  145. _toolBarManager.AddControl(GE_toolBar1,DockStyle.Top);
  146. InitGraDrawTool();
  147. UpdateColorBtnImage(DrawEnvMgr.Instance.Color);
  148. InitRecentFilesMgr();
  149. GraDrawTool.ActiveStateChanged +=new EventHandler(GraDrawTool_ActiveStateChanged);
  150. this.mainView.MouseMove += new MouseEventHandler(mainView_MouseMove);
  151. InitEditStackMgr();
  152. UpdateFontPanel();
  153. //Set Freehand draw tool as default
  154. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Freehand);
  155. this.tlBtnFreehand.Pushed = true;
  156. }
  157. /// <summary>
  158. /// Clean up any resources being used
  159. /// </summary>
  160. protected override void Dispose( bool disposing )
  161. {
  162. if( disposing )
  163. {
  164. if (components != null)
  165. {
  166. components.Dispose();
  167. }
  168. }
  169. base.Dispose( disposing );
  170. }
  171. #region Windows
  172. /// <summary>
  173. /// Required method for Designer support - do not modify
  174. /// the contents of this method with the code editor.
  175. /// </summary>
  176. private void InitializeComponent()
  177. {
  178. this.components = new System.ComponentModel.Container();
  179. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GE));
  180. this.GE_toolBar = new System.Windows.Forms.ToolBar();
  181. this.tlBtnErase = new System.Windows.Forms.ToolBarButton();
  182. this.sep2 = new System.Windows.Forms.ToolBarButton();
  183. this.tlBtnLine = new System.Windows.Forms.ToolBarButton();
  184. this.tlBtnLines = new System.Windows.Forms.ToolBarButton();
  185. this.tlBtnFreehand = new System.Windows.Forms.ToolBarButton();
  186. this.tlBtnFrameRect = new System.Windows.Forms.ToolBarButton();
  187. this.tlBtnFillRect = new System.Windows.Forms.ToolBarButton();
  188. this.tlBtnFrameEllipse = new System.Windows.Forms.ToolBarButton();
  189. this.tlBtnFillEllipse = new System.Windows.Forms.ToolBarButton();
  190. this.tlBtnImage = new System.Windows.Forms.ToolBarButton();
  191. this.tlBtnText = new System.Windows.Forms.ToolBarButton();
  192. this.sep3 = new System.Windows.Forms.ToolBarButton();
  193. this.tlBtnZoomIn = new System.Windows.Forms.ToolBarButton();
  194. this.tlBtnZoomOut = new System.Windows.Forms.ToolBarButton();
  195. this.tlBtnZoomResume = new System.Windows.Forms.ToolBarButton();
  196. this.sep4 = new System.Windows.Forms.ToolBarButton();
  197. this.GE_imageList = new System.Windows.Forms.ImageList(this.components);
  198. this.mainView = new GraEditor.MainView();
  199. this.contextMenu1 = new System.Windows.Forms.ContextMenu();
  200. this.pasteMenuItem = new System.Windows.Forms.MenuItem();
  201. this.menuItemCanvasBackColor = new System.Windows.Forms.MenuItem();
  202. this.menuItemCanvasSize = new System.Windows.Forms.MenuItem();
  203. this.GE_statusBar = new System.Windows.Forms.StatusBar();
  204. this.sbPanelTip = new System.Windows.Forms.StatusBarPanel();
  205. this.sbPanelFont = new System.Windows.Forms.StatusBarPanel();
  206. this.sbPanelViewScale = new System.Windows.Forms.StatusBarPanel();
  207. this.sbPanelMousePos = new System.Windows.Forms.StatusBarPanel();
  208. this.mainMenu1 = new System.Windows.Forms.MainMenu();
  209. this.menuFile = new System.Windows.Forms.MenuItem();
  210. this.menuNew = new System.Windows.Forms.MenuItem();
  211. this.menuOpen = new System.Windows.Forms.MenuItem();
  212. this.menuSave = new System.Windows.Forms.MenuItem();
  213. this.menuSaveAs = new System.Windows.Forms.MenuItem();
  214. this.menuItem5 = new System.Windows.Forms.MenuItem();
  215. this.menuPrint = new System.Windows.Forms.MenuItem();
  216. this.menuPrintPreview = new System.Windows.Forms.MenuItem();
  217. this.menuPageSetting = new System.Windows.Forms.MenuItem();
  218. this.menuItem4 = new System.Windows.Forms.MenuItem();
  219. this.menuRecentFiles = new System.Windows.Forms.MenuItem();
  220. this.menuItem1 = new System.Windows.Forms.MenuItem();
  221. this.menuExit = new System.Windows.Forms.MenuItem();
  222. this.menuEdit = new System.Windows.Forms.MenuItem();
  223. this.menuUndo = new System.Windows.Forms.MenuItem();
  224. this.menuRedo = new System.Windows.Forms.MenuItem();
  225. this.menuItem12 = new System.Windows.Forms.MenuItem();
  226. this.menuCut = new System.Windows.Forms.MenuItem();
  227. this.menuCopy = new System.Windows.Forms.MenuItem();
  228. this.menuView = new System.Windows.Forms.MenuItem();
  229. this.menuToolbar = new System.Windows.Forms.MenuItem();
  230. this.menuStatusBar = new System.Windows.Forms.MenuItem();
  231. this.menuItem24 = new System.Windows.Forms.MenuItem();
  232. this.menuZoom = new System.Windows.Forms.MenuItem();
  233. this.menuZoomIn = new System.Windows.Forms.MenuItem();
  234. this.menuZoomOut = new System.Windows.Forms.MenuItem();
  235. this.menuResume = new System.Windows.Forms.MenuItem();
  236. this.menuImgSetting = new System.Windows.Forms.MenuItem();
  237. this.menuColorSettings = new System.Windows.Forms.MenuItem();
  238. this.menuHelp = new System.Windows.Forms.MenuItem();
  239. this.menuHelpIndex = new System.Windows.Forms.MenuItem();
  240. this.menuAboutGE = new System.Windows.Forms.MenuItem();
  241. this._menuImages = new Chris.Beckett.MenuImageLib.MenuImage(this.components);
  242. this.GE_toolBar1 = new System.Windows.Forms.ToolBar();
  243. this.tlBtnNew = new System.Windows.Forms.ToolBarButton();
  244. this.tlBtnOpen = new System.Windows.Forms.ToolBarButton();
  245. this.tlBtnSave = new System.Windows.Forms.ToolBarButton();
  246. this.sp1 = new System.Windows.Forms.ToolBarButton();
  247. this.tlBtnSelect = new System.Windows.Forms.ToolBarButton();
  248. this.tlBtnCopy = new System.Windows.Forms.ToolBarButton();
  249. this.tlBtnCut = new System.Windows.Forms.ToolBarButton();
  250. this.sp2 = new System.Windows.Forms.ToolBarButton();
  251. this.sp5 = new System.Windows.Forms.ToolBarButton();
  252. this.tlBtnUndo = new System.Windows.Forms.ToolBarButton();
  253. this.tlBtnRedo = new System.Windows.Forms.ToolBarButton();
  254. this.tlBtnFont = new System.Windows.Forms.ToolBarButton();
  255. this.tlBtnColor = new System.Windows.Forms.ToolBarButton();
  256. this.tlBtnPenWidth = new System.Windows.Forms.ToolBarButton();
  257. this.muPenWidth = new System.Windows.Forms.ContextMenu();
  258. this.printDocument1 = new System.Drawing.Printing.PrintDocument();
  259. this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
  260. this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
  261. ((System.ComponentModel.ISupportInitialize)(this.sbPanelTip)).BeginInit();
  262. ((System.ComponentModel.ISupportInitialize)(this.sbPanelFont)).BeginInit();
  263. ((System.ComponentModel.ISupportInitialize)(this.sbPanelViewScale)).BeginInit();
  264. ((System.ComponentModel.ISupportInitialize)(this.sbPanelMousePos)).BeginInit();
  265. this.SuspendLayout();
  266. //
  267. // GE_toolBar
  268. //
  269. this.GE_toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  270. this.tlBtnErase,
  271. this.sep2,
  272. this.tlBtnLine,
  273. this.tlBtnLines,
  274. this.tlBtnFreehand,
  275. this.tlBtnFrameRect,
  276. this.tlBtnFillRect,
  277. this.tlBtnFrameEllipse,
  278. this.tlBtnFillEllipse,
  279. this.tlBtnImage,
  280. this.tlBtnText,
  281. this.sep3,
  282. this.tlBtnZoomIn,
  283. this.tlBtnZoomOut,
  284. this.tlBtnZoomResume,
  285. this.sep4});
  286. this.GE_toolBar.DropDownArrows = true;
  287. this.GE_toolBar.ImageList = this.GE_imageList;
  288. this.GE_toolBar.Location = new System.Drawing.Point(0, 0);
  289. this.GE_toolBar.Name = "GE_toolBar";
  290. this.GE_toolBar.ShowToolTips = true;
  291. this.GE_toolBar.Size = new System.Drawing.Size(591, 28);
  292. this.GE_toolBar.TabIndex = 0;
  293. this.GE_toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.GE_toolBar_ButtonClick);
  294. //
  295. // tlBtnErase
  296. //
  297. this.tlBtnErase.ImageIndex = 23;
  298. this.tlBtnErase.ToolTipText = "Erase";
  299. //
  300. // sep2
  301. //
  302. this.sep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  303. //
  304. // tlBtnLine
  305. //
  306. this.tlBtnLine.ImageIndex = 6;
  307. this.tlBtnLine.ToolTipText = "Draw Line";
  308. //
  309. // tlBtnLines
  310. //
  311. this.tlBtnLines.ImageIndex = 19;
  312. this.tlBtnLines.ToolTipText = "Draw Multiple Lines, double click to stop";
  313. //
  314. // tlBtnFreehand
  315. //
  316. this.tlBtnFreehand.ImageIndex = 32;
  317. this.tlBtnFreehand.ToolTipText = "Free Hand Drawing";
  318. //
  319. // tlBtnFrameRect
  320. //
  321. this.tlBtnFrameRect.ImageIndex = 4;
  322. this.tlBtnFrameRect.ToolTipText = "Draw Rectangle";
  323. //
  324. // tlBtnFillRect
  325. //
  326. this.tlBtnFillRect.ImageIndex = 3;
  327. this.tlBtnFillRect.ToolTipText = "Draw Filled Rectangle";
  328. //
  329. // tlBtnFrameEllipse
  330. //
  331. this.tlBtnFrameEllipse.ImageIndex = 15;
  332. this.tlBtnFrameEllipse.ToolTipText = "Draw Ellipse";
  333. //
  334. // tlBtnFillEllipse
  335. //
  336. this.tlBtnFillEllipse.ImageIndex = 16;
  337. this.tlBtnFillEllipse.ToolTipText = "Draw Filled Ellipse";
  338. //
  339. // tlBtnImage
  340. //
  341. this.tlBtnImage.ImageIndex = 17;
  342. this.tlBtnImage.ToolTipText = "Insert Image";
  343. //
  344. // tlBtnText
  345. //
  346. this.tlBtnText.ImageIndex = 18;
  347. this.tlBtnText.ToolTipText = "Insert Text";
  348. //
  349. // sep3
  350. //
  351. this.sep3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  352. //
  353. // tlBtnZoomIn
  354. //
  355. this.tlBtnZoomIn.ImageIndex = 12;
  356. this.tlBtnZoomIn.ToolTipText = "ZoomIn";
  357. //
  358. // tlBtnZoomOut
  359. //
  360. this.tlBtnZoomOut.ImageIndex = 13;
  361. this.tlBtnZoomOut.ToolTipText = "ZoomOut";
  362. //
  363. // tlBtnZoomResume
  364. //
  365. this.tlBtnZoomResume.ImageIndex = 14;
  366. this.tlBtnZoomResume.ToolTipText = "Resume";
  367. //
  368. // sep4
  369. //
  370. this.sep4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  371. //
  372. // GE_imageList
  373. //
  374. this.GE_imageList.ImageSize = new System.Drawing.Size(16, 16);
  375. this.GE_imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("GE_imageList.ImageStream")));
  376. this.GE_imageList.TransparentColor = System.Drawing.Color.Transparent;
  377. //
  378. // mainView
  379. //
  380. this.mainView.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(192)));
  381. this.mainView.ContextMenu = this.contextMenu1;
  382. this.mainView.Dock = System.Windows.Forms.DockStyle.Fill;
  383. this.mainView.Location = new System.Drawing.Point(0, 56);
  384. this.mainView.Name = "mainView";
  385. this.mainView.Size = new System.Drawing.Size(591, 353);
  386. this.mainView.TabIndex = 3;
  387. this.mainView.Paint += new System.Windows.Forms.PaintEventHandler(this.mainView_Paint);
  388. //
  389. // contextMenu1
  390. //
  391. this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  392. this.pasteMenuItem,
  393. this.menuItemCanvasBackColor,
  394. this.menuItemCanvasSize});
  395. this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
  396. //
  397. // pasteMenuItem
  398. //
  399. this.pasteMenuItem.Index = 0;
  400. this._menuImages.SetMenuImage(this.pasteMenuItem, null);
  401. this.pasteMenuItem.OwnerDraw = true;
  402. this.pasteMenuItem.Text = "Paste";
  403. this.pasteMenuItem.Click += new System.EventHandler(this.pasteMenuItem_Click);
  404. //
  405. // menuItemCanvasBackColor
  406. //
  407. this.menuItemCanvasBackColor.Index = 1;
  408. this._menuImages.SetMenuImage(this.menuItemCanvasBackColor, null);
  409. this.menuItemCanvasBackColor.OwnerDraw = true;
  410. this.menuItemCanvasBackColor.Text = "CanvasBackColor";
  411. this.menuItemCanvasBackColor.Click += new System.EventHandler(this.menuItemCanvasBackColor_Click);
  412. //
  413. // menuItemCanvasSize
  414. //
  415. this.menuItemCanvasSize.Index = 2;
  416. this._menuImages.SetMenuImage(this.menuItemCanvasSize, null);
  417. this.menuItemCanvasSize.OwnerDraw = true;
  418. this.menuItemCanvasSize.Text = "CanvasSize";
  419. this.menuItemCanvasSize.Click += new System.EventHandler(this.menuItemCanvasSize_Click);
  420. //
  421. // GE_statusBar
  422. //
  423. this.GE_statusBar.Location = new System.Drawing.Point(0, 409);
  424. this.GE_statusBar.Name = "GE_statusBar";
  425. this.GE_statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
  426. this.sbPanelTip,
  427. this.sbPanelFont,
  428. this.sbPanelViewScale,
  429. this.sbPanelMousePos});
  430. this.GE_statusBar.ShowPanels = true;
  431. this.GE_statusBar.Size = new System.Drawing.Size(591, 23);
  432. this.GE_statusBar.TabIndex = 2;
  433. //
  434. // sbPanelTip
  435. //
  436. this.sbPanelTip.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
  437. this.sbPanelTip.Width = 265;
  438. //
  439. // sbPanelFont
  440. //
  441. this.sbPanelFont.Width = 150;
  442. //
  443. // sbPanelViewScale
  444. //
  445. this.sbPanelViewScale.Width = 60;
  446. //
  447. // mainMenu1
  448. //
  449. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  450. this.menuFile,
  451. this.menuEdit,
  452. this.menuView,
  453. this.menuImgSetting,
  454. this.menuHelp});
  455. //
  456. // menuFile
  457. //
  458. this.menuFile.Index = 0;
  459. this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  460. this.menuNew,
  461. this.menuOpen,
  462. this.menuSave,
  463. this.menuSaveAs,
  464. this.menuItem5,
  465. this.menuPrint,
  466. this.menuPrintPreview,
  467. this.menuPageSetting,
  468. this.menuItem4,
  469. this.menuRecentFiles,
  470. this.menuItem1,
  471. this.menuExit});
  472. this.menuFile.Text = "File";
  473. //
  474. // menuNew
  475. //
  476. this.menuNew.Index = 0;
  477. this._menuImages.SetMenuImage(this.menuNew, "36");
  478. this.menuNew.OwnerDraw = true;
  479. this.menuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
  480. this.menuNew.Text = "New";
  481. this.menuNew.Click += new System.EventHandler(this.menuNew_Click);
  482. //
  483. // menuOpen
  484. //
  485. this.menuOpen.Index = 1;
  486. this._menuImages.SetMenuImage(this.menuOpen, "33");
  487. this.menuOpen.OwnerDraw = true;
  488. this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
  489. this.menuOpen.Text = "Open";
  490. this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);
  491. //
  492. // menuSave
  493. //
  494. this.menuSave.Index = 2;
  495. this._menuImages.SetMenuImage(this.menuSave, "35");
  496. this.menuSave.OwnerDraw = true;
  497. this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
  498. this.menuSave.Text = "Save";
  499. this.menuSave.Click += new System.EventHandler(this.menuSave_Click);
  500. //
  501. // menuSaveAs
  502. //
  503. this.menuSaveAs.Index = 3;
  504. this._menuImages.SetMenuImage(this.menuSaveAs, "35");
  505. this.menuSaveAs.OwnerDraw = true;
  506. this.menuSaveAs.Text = "Save as...";
  507. this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click);
  508. //
  509. // menuItem5
  510. //
  511. this.menuItem5.Index = 4;
  512. this._menuImages.SetMenuImage(this.menuItem5, null);
  513. this.menuItem5.OwnerDraw = true;
  514. this.menuItem5.Text = "-";
  515. //
  516. // menuPrint
  517. //
  518. this.menuPrint.Index = 5;
  519. this._menuImages.SetMenuImage(this.menuPrint, "31");
  520. this.menuPrint.OwnerDraw = true;
  521. this.menuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP;
  522. this.menuPrint.Text = "Print";
  523. this.menuPrint.Click += new System.EventHandler(this.menuPrint_Click);
  524. //
  525. // menuPrintPreview
  526. //
  527. this.menuPrintPreview.Index = 6;
  528. this._menuImages.SetMenuImage(this.menuPrintPreview, null);
  529. this.menuPrintPreview.OwnerDraw = true;
  530. this.menuPrintPreview.Text = "PrintPreview";
  531. this.menuPrintPreview.Click += new System.EventHandler(this.menuPrintPreview_Click);
  532. //
  533. // menuPageSetting
  534. //
  535. this.menuPageSetting.Index = 7;
  536. this._menuImages.SetMenuImage(this.menuPageSetting, null);
  537. this.menuPageSetting.OwnerDraw = true;
  538. this.menuPageSetting.Text = "PageSetting";
  539. this.menuPageSetting.Click += new System.EventHandler(this.menuPageSetting_Click);
  540. //
  541. // menuItem4
  542. //
  543. this.menuItem4.Index = 8;
  544. this._menuImages.SetMenuImage(this.menuItem4, null);
  545. this.menuItem4.OwnerDraw = true;
  546. this.menuItem4.Text = "-";
  547. //
  548. // menuRecentFiles
  549. //
  550. this.menuRecentFiles.Index = 9;
  551. this._menuImages.SetMenuImage(this.menuRecentFiles, null);
  552. this.menuRecentFiles.OwnerDraw = true;
  553. this.menuRecentFiles.Text = "Recent Files";
  554. //
  555. // menuItem1
  556. //
  557. this.menuItem1.Index = 10;
  558. this._menuImages.SetMenuImage(this.menuItem1, null);
  559. this.menuItem1.OwnerDraw = true;
  560. this.menuItem1.Text = "-";
  561. //
  562. // menuExit
  563. //
  564. this.menuExit.Index = 11;
  565. this._menuImages.SetMenuImage(this.menuExit, "34");
  566. this.menuExit.OwnerDraw = true;
  567. this.menuExit.Text = "Exit";
  568. this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
  569. //
  570. // menuEdit
  571. //
  572. this.menuEdit.Index = 1;
  573. this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  574. this.menuUndo,
  575. this.menuRedo,
  576. this.menuItem12,
  577. this.menuCut,
  578. this.menuCopy});
  579. this.menuEdit.Text = "Edit";
  580. //
  581. // menuUndo
  582. //
  583. this.menuUndo.Index = 0;
  584. this._menuImages.SetMenuImage(this.menuUndo, "11");
  585. this.menuUndo.OwnerDraw = true;
  586. this.menuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
  587. this.menuUndo.Text = "Undo";
  588. this.menuUndo.Click += new System.EventHandler(this.menuUndo_Click);
  589. //
  590. // menuRedo
  591. //
  592. this.menuRedo.Index = 1;
  593. this._menuImages.SetMenuImage(this.menuRedo, "9");
  594. this.menuRedo.OwnerDraw = true;
  595. this.menuRedo.Shortcut = System.Windows.Forms.Shortcut.CtrlY;
  596. this.menuRedo.Text = "Redo";
  597. this.menuRedo.Click += new System.EventHandler(this.menuRedo_Click);
  598. //
  599. // menuItem12
  600. //
  601. this.menuItem12.Index = 2;
  602. this._menuImages.SetMenuImage(this.menuItem12, null);
  603. this.menuItem12.OwnerDraw = true;
  604. this.menuItem12.Text = "-";
  605. //
  606. // menuCut
  607. //
  608. this.menuCut.Index = 3;
  609. this._menuImages.SetMenuImage(this.menuCut, "1");
  610. this.menuCut.OwnerDraw = true;
  611. this.menuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
  612. this.menuCut.Text = "Cut";
  613. this.menuCut.Click += new System.EventHandler(this.menuCut_Click);
  614. //
  615. // menuCopy
  616. //
  617. this.menuCopy.Index = 4;
  618. this._menuImages.SetMenuImage(this.menuCopy, "0");
  619. this.menuCopy.OwnerDraw = true;
  620. this.menuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
  621. this.menuCopy.Text = "Copy";
  622. this.menuCopy.Click += new System.EventHandler(this.menuCopy_Click);
  623. //
  624. // menuView
  625. //
  626. this.menuView.Index = 2;
  627. this.menuView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  628. this.menuToolbar,
  629. this.menuStatusBar,
  630. this.menuItem24,
  631. this.menuZoom,
  632. this.menuResume});
  633. this.menuView.Text = "View";
  634. this.menuView.Popup += new System.EventHandler(this.menuView_Popup);
  635. //
  636. // menuToolbar
  637. //
  638. this.menuToolbar.Index = 0;
  639. this._menuImages.SetMenuImage(this.menuToolbar, null);
  640. this.menuToolbar.OwnerDraw = true;
  641. this.menuToolbar.Text = "Toolbar";
  642. this.menuToolbar.Click += new System.EventHandler(this.menuToolbar_Click_1);
  643. //
  644. // menuStatusBar
  645. //
  646. this.menuStatusBar.Checked = true;
  647. this.menuStatusBar.Index = 1;
  648. this._menuImages.SetMenuImage(this.menuStatusBar, null);
  649. this.menuStatusBar.OwnerDraw = true;
  650. this.menuStatusBar.Text = "Status Bar";
  651. this.menuStatusBar.Click += new System.EventHandler(this.menuStatusBar_Click);
  652. //
  653. // menuItem24
  654. //
  655. this.menuItem24.Index = 2;
  656. this._menuImages.SetMenuImage(this.menuItem24, null);
  657. this.menuItem24.OwnerDraw = true;
  658. this.menuItem24.Text = "-";
  659. //
  660. // menuZoom
  661. //
  662. this.menuZoom.Index = 3;
  663. this._menuImages.SetMenuImage(this.menuZoom, null);
  664. this.menuZoom.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  665. this.menuZoomIn,
  666. this.menuZoomOut});
  667. this.menuZoom.OwnerDraw = true;
  668. this.menuZoom.Text = "Zoom";
  669. //
  670. // menuZoomIn
  671. //
  672. this.menuZoomIn.Index = 0;
  673. this._menuImages.SetMenuImage(this.menuZoomIn, "12");
  674. this.menuZoomIn.OwnerDraw = true;
  675. this.menuZoomIn.Text = "Zoom In";
  676. this.menuZoomIn.Click += new System.EventHandler(this.menuZoomIn_Click);
  677. //
  678. // menuZoomOut
  679. //
  680. this.menuZoomOut.Index = 1;
  681. this._menuImages.SetMenuImage(this.menuZoomOut, "13");
  682. this.menuZoomOut.OwnerDraw = true;
  683. this.menuZoomOut.Text = "Zoom Out";
  684. this.menuZoomOut.Click += new System.EventHandler(this.menuZoomOut_Click);
  685. //
  686. // menuResume
  687. //
  688. this.menuResume.Index = 4;
  689. this._menuImages.SetMenuImage(this.menuResume, "14");
  690. this.menuResume.OwnerDraw = true;
  691. this.menuResume.Text = "Resume";
  692. this.menuResume.Click += new System.EventHandler(this.menuResume_Click);
  693. //
  694. // menuImgSetting
  695. //
  696. this.menuImgSetting.Index = 3;
  697. this.menuImgSetting.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  698. this.menuColorSettings});
  699. this.menuImgSetting.Text = "Image Settings";
  700. //
  701. // menuColorSettings
  702. //
  703. this.menuColorSettings.Index = 0;
  704. this._menuImages.SetMenuImage(this.menuColorSettings, "27");
  705. this.menuColorSettings.OwnerDraw = true;
  706. this.menuColorSettings.Text = "Color Settings";
  707. this.menuColorSettings.Click += new System.EventHandler(this.menuColorSettings_Click);
  708. //
  709. // menuHelp
  710. //
  711. this.menuHelp.Index = 4;
  712. this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  713. this.menuHelpIndex,
  714. this.menuAboutGE});
  715. this.menuHelp.Text = "Help";
  716. //
  717. // menuHelpIndex
  718. //
  719. this.menuHelpIndex.Index = 0;
  720. this._menuImages.SetMenuImage(this.menuHelpIndex, "29");
  721. this.menuHelpIndex.OwnerDraw = true;
  722. this.menuHelpIndex.Shortcut = System.Windows.Forms.Shortcut.F1;
  723. this.menuHelpIndex.Text = "Help Index";
  724. this.menuHelpIndex.Click += new System.EventHandler(this.menuHelpIndex_Click);
  725. //
  726. // menuAboutGE
  727. //
  728. this.menuAboutGE.Index = 1;
  729. this._menuImages.SetMenuImage(this.menuAboutGE, "30");
  730. this.menuAboutGE.OwnerDraw = true;
  731. this.menuAboutGE.Text = "About Graphical Editor";
  732. this.menuAboutGE.Click += new System.EventHandler(this.menuAboutGE_Click);
  733. //
  734. // _menuImages
  735. //
  736. this._menuImages.ImageList = this.GE_imageList;
  737. //
  738. // GE_toolBar1
  739. //
  740. this.GE_toolBar1.AutoSize = false;
  741. this.GE_toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  742. this.tlBtnNew,
  743. this.tlBtnOpen,
  744. this.tlBtnSave,
  745. this.sp1,
  746. this.tlBtnSelect,
  747. this.tlBtnCopy,
  748. this.tlBtnCut,
  749. this.sp2,
  750. this.sp5,
  751. this.tlBtnUndo,
  752. this.tlBtnRedo,
  753. this.tlBtnFont,
  754. this.tlBtnColor,
  755. this.tlBtnPenWidth});
  756. this.GE_toolBar1.DropDownArrows = true;
  757. this.GE_toolBar1.ImageList = this.GE_imageList;
  758. this.GE_toolBar1.Location = new System.Drawing.Point(0, 28);
  759. this.GE_toolBar1.Name = "GE_toolBar1";
  760. this.GE_toolBar1.ShowToolTips = true;
  761. this.GE_toolBar1.Size = new System.Drawing.Size(591, 28);
  762. this.GE_toolBar1.TabIndex = 4;
  763. this.GE_toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.GE_toolBar1_ButtonClick);
  764. //
  765. // tlBtnNew
  766. //
  767. this.tlBtnNew.ImageIndex = 36;
  768. this.tlBtnNew.ToolTipText = "New";
  769. //
  770. // tlBtnOpen
  771. //
  772. this.tlBtnOpen.ImageIndex = 33;
  773. this.tlBtnOpen.ToolTipText = "Open";
  774. //
  775. // tlBtnSave
  776. //
  777. this.tlBtnSave.ImageIndex = 35;
  778. this.tlBtnSave.ToolTipText = "Save";
  779. //
  780. // sp1
  781. //
  782. this.sp1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  783. //
  784. // tlBtnSelect
  785. //
  786. this.tlBtnSelect.ImageIndex = 10;
  787. this.tlBtnSelect.ToolTipText = "Select";
  788. //
  789. // tlBtnCopy
  790. //
  791. this.tlBtnCopy.ImageIndex = 0;
  792. this.tlBtnCopy.ToolTipText = "Copy";
  793. //
  794. // tlBtnCut
  795. //
  796. this.tlBtnCut.ImageIndex = 1;
  797. this.tlBtnCut.ToolTipText = "Cut";
  798. //
  799. // sp2
  800. //
  801. this.sp2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  802. //
  803. // sp5
  804. //
  805. this.sp5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
  806. //
  807. // tlBtnUndo
  808. //
  809. this.tlBtnUndo.ImageIndex = 11;
  810. this.tlBtnUndo.ToolTipText = "Undo";
  811. //
  812. // tlBtnRedo
  813. //
  814. this.tlBtnRedo.ImageIndex = 9;
  815. this.tlBtnRedo.ToolTipText = "Redo";
  816. //
  817. // tlBtnFont
  818. //
  819. this.tlBtnFont.ImageIndex = 25;
  820. this.tlBtnFont.ToolTipText = "Font";
  821. //
  822. // tlBtnColor
  823. //
  824. this.tlBtnColor.ImageIndex = 24;
  825. this.tlBtnColor.ToolTipText = "Color";
  826. //
  827. // tlBtnPenWidth
  828. //
  829. this.tlBtnPenWidth.DropDownMenu = this.muPenWidth;
  830. this.tlBtnPenWidth.ImageIndex = 37;
  831. this.tlBtnPenWidth.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
  832. this.tlBtnPenWidth.ToolTipText = "Line Width ";
  833. //
  834. // printDocument1
  835. //
  836. this.printDocument1.OriginAtMargins = true;
  837. this.printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_BeginPrint);
  838. this.printDocument1.EndPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_EndPrint);
  839. this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
  840. //
  841. // printPreviewDialog1
  842. //
  843. this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
  844. this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
  845. this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
  846. this.printPreviewDialog1.Document = this.printDocument1;
  847. this.printPreviewDialog1.Enabled = true;
  848. this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
  849. this.printPreviewDialog1.Location = new System.Drawing.Point(22, 22);
  850. this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
  851. this.printPreviewDialog1.Name = "printPreviewDialog1";
  852. this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
  853. this.printPreviewDialog1.Visible = false;
  854. this.printPreviewDialog1.Paint += new System.Windows.Forms.PaintEventHandler(this.printPreviewDialog1_Paint);
  855. //
  856. // pageSetupDialog1
  857. //
  858. this.pageSetupDialog1.Document = this.printDocument1;
  859. this.pageSetupDialog1.MinMargins = new System.Drawing.Printing.Margins(0, 20, 0, 20);
  860. //
  861. // GE
  862. //
  863. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  864. this.ClientSize = new System.Drawing.Size(591, 432);
  865. this.Controls.Add(this.mainView);
  866. this.Controls.Add(this.GE_toolBar1);
  867. this.Controls.Add(this.GE_statusBar);
  868. this.Controls.Add(this.GE_toolBar);
  869. this.Menu = this.mainMenu1;
  870. this.Name = "GE";
  871. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  872. this.Text = "Graphic Editor";
  873. this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  874. this.Closing += new System.ComponentModel.CancelEventHandler(this.GE_Closing);
  875. this.Load += new System.EventHandler(this.GE_Load);
  876. ((System.ComponentModel.ISupportInitialize)(this.sbPanelTip)).EndInit();
  877. ((System.ComponentModel.ISupportInitialize)(this.sbPanelFont)).EndInit();
  878. ((System.ComponentModel.ISupportInitialize)(this.sbPanelViewScale)).EndInit();
  879. ((System.ComponentModel.ISupportInitialize)(this.sbPanelMousePos)).EndInit();
  880. this.ResumeLayout(false);
  881. }
  882. #endregion
  883. /// <summary>
  884. /// The main entry point for the application.
  885. /// </summary>
  886. [STAThread]
  887. static void Main()
  888. {
  889. Application.Run(new GE());
  890. }
  891. /// <summary>
  892. /// Initial draw tool types
  893. /// </summary>
  894. private void InitGraDrawTool()
  895. {
  896. //Get the instance of GraDrawToolMgr
  897. GraDrawToolMgr drawToolMgr = GraDrawToolMgr.Instance;
  898. //Add Select draw tool type into GraDrawToolMgr
  899. SelectDrawTool selectTool = SelectDrawTool.Instance;
  900. selectTool.TblBtn = this.tlBtnSelect;
  901. selectTool.StateChanged +=new EventHandler(selectTool_StateChanged);
  902. this.selectTool_StateChanged(selectTool,EventArgs.Empty);
  903. GraDrawToolMgr.Instance.AddDrawTool(selectTool);
  904. //Add line draw tool type into GraDrawToolMgr
  905. LineDrawTool lineTool = new LineDrawTool();
  906. lineTool.TblBtn = this.tlBtnLine;
  907. GraDrawToolMgr.Instance.AddDrawTool(lineTool);
  908. //Add lines draw tool type into GraDrawToolMgr
  909. LinesDrawTool linesTool = new LinesDrawTool();
  910. linesTool.TblBtn = this.tlBtnLines;
  911. GraDrawToolMgr.Instance.AddDrawTool(linesTool);
  912. //Add freehand draw tool type into GraDrawToolMgr
  913. FreehandDrawTool freehandTool = new FreehandDrawTool();
  914. freehandTool.TblBtn = this.tlBtnFreehand;
  915. GraDrawToolMgr.Instance.AddDrawTool(freehandTool);
  916. //Add erase draw tool type into GraDrawToolMgr
  917. EraseDrawTool eraseTool = new EraseDrawTool();
  918. eraseTool.TblBtn = this.tlBtnErase;
  919. GraDrawToolMgr.Instance.AddDrawTool(eraseTool);
  920. //Add frame rectangle draw tool type into GraDrawToolMgr
  921. FrameRectDrawTool frameRectTool = new FrameRectDrawTool();
  922. frameRectTool.TblBtn = this.tlBtnFrameRect;
  923. GraDrawToolMgr.Instance.AddDrawTool(frameRectTool);
  924. //Add solid rectangle draw tool type into GraDrawToolMgr
  925. FillRectDrawTool fillRectTool = new FillRectDrawTool();
  926. fillRectTool.TblBtn = this.tlBtnFillRect;
  927. GraDrawToolMgr.Instance.AddDrawTool(fillRectTool);
  928. //Add frame ellipse draw tool type into GraDrawToolMgr
  929. FrameEllipseDrawTool frameEllipseTool = new FrameEllipseDrawTool();
  930. frameEllipseTool.TblBtn = this.tlBtnFrameEllipse;
  931. GraDrawToolMgr.Instance.AddDrawTool(frameEllipseTool);
  932. //Add solid ellipse draw tool type into GraDrawToolMgr
  933. FillEllipseDrawTool fillEllipseTool = new FillEllipseDrawTool();
  934. fillEllipseTool.TblBtn = this.tlBtnFillEllipse;
  935. GraDrawToolMgr.Instance.AddDrawTool(fillEllipseTool);
  936. //Add insert image draw tool type into GraDrawToolMgr
  937. ImageDrawTool imageDrawTool = new ImageDrawTool();
  938. imageDrawTool.TblBtn = this.tlBtnImage;
  939. GraDrawToolMgr.Instance.AddDrawTool(imageDrawTool);
  940. //Add insert text draw tool type into GraDrawToolMgr
  941. TextDrawTool textDrawTool = TextDrawTool.Instance;
  942. textDrawTool.TblBtn = this.tlBtnText;
  943. GraDrawToolMgr.Instance.AddDrawTool(textDrawTool);
  944. }
  945. private void GE_toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)//Toolbar button click events
  946. {
  947. ToolBarButton b = e.Button;//clicked Toolbar button
  948. if(b != this.tlBtnText)
  949. TextDrawTool.Instance.EndTextEditing(true);
  950. if(b == this.tlBtnLine)//Line button is clicked
  951. tlBtnLine_Click();
  952. else if(b == this.tlBtnLines)//Lines button is clicked
  953. tlBtnLines_Click();
  954. else if(b == this.tlBtnFreehand)//Freehand button is clicked
  955. tlBtnFreehand_Click();
  956. else if(b == this.tlBtnFrameRect)//Frame rectangle button is clicked
  957. tlBtnFrameRect_Click();
  958. else if(b == this.tlBtnFillRect)//Solid rectangle button is clicked
  959. tlBtnFillRect_Click();
  960. else if(b == this.tlBtnFrameEllipse)//Frame ellipse button is clicked
  961. tlBtnFrameEllipse_Click();
  962. else if(b == this.tlBtnFillEllipse)//Solid ellipse button is clicked
  963. tlBtnFillEllipse_Click();
  964. else if(b == this.tlBtnZoomIn)//Zoom in button is clicked
  965. tlBtnZoomIn_Click();
  966. else if(b == this.tlBtnZoomOut)//Zoom out button is clicked
  967. tlBtnZoomOut_Click();
  968. else if(b == this.tlBtnZoomResume)//Zoom resume button is clicked
  969. tlBtnZoomResume_Click();
  970. else if(b == this.tlBtnImage)//Zoom resume button is clicked
  971. tlBtnImage_Click();
  972. else if(b == this.tlBtnText)//Zoom resume button is clicked
  973. tlBtnText_Click();
  974. else if(b == this.tlBtnErase) // erase button is clicked
  975. tlBtnErase_Click();
  976. }
  977. private void tlBtnFont_Click()
  978. {
  979. FontDialog dlg = new FontDialog(); //instantiating a new fontdialog box
  980. dlg.Font = DrawEnvMgr.Instance.Font;
  981. if(DialogResult.OK == dlg.ShowDialog(this))
  982. {
  983. DrawEnvMgr.Instance.Font = dlg.Font; // assigning the font selected by the user to DrawEnvMgr.Instance.Font
  984. UpdateFontPanel();
  985. }
  986. }
  987. private void UpdateFontPanel()
  988. {
  989. Font f = DrawEnvMgr.Instance.Font;
  990. string info = string.Format("{0} -- {1}",f.Name,f.Size);
  991. this.sbPanelFont.Text = info;
  992. }
  993. private MenuItem selectedPenWidthMenuItem;
  994. private void InitPenWidthToolBarButton()
  995. {
  996. MenuItem[] items = new MenuItem[16];//6
  997. for(int i=0; i< items.Length; i++)
  998. {
  999. items[i] = new MenuItem(i.ToString());//
  1000. items[i].MeasureItem += new MeasureItemEventHandler(GE_MeasureItem);
  1001. items[i].DrawItem +=new DrawItemEventHandler(PenWidthMenu_DrawItem);
  1002. items[i].Click +=new EventHandler(PenWidthMenu_Click);
  1003. items[i].OwnerDraw = true;
  1004. }
  1005. this.muPenWidth.MenuItems.AddRange(items);
  1006. this.selectedPenWidthMenuItem = items[0];
  1007. this.selectedPenWidthMenuItem.Checked = true;
  1008. }
  1009. private void GE_MeasureItem(object sender, MeasureItemEventArgs e)
  1010. {
  1011. e.ItemHeight = 20;
  1012. e.ItemWidth = 80;//(int)stringSize.Width;
  1013. }
  1014. /// <summary>
  1015. /// OwnerDraw PenWidth toolBar button menu
  1016. /// </summary>
  1017. /// <param name="sender"></param>
  1018. /// <param name="e"></param>
  1019. private void PenWidthMenu_DrawItem(object sender, DrawItemEventArgs e)
  1020. {
  1021. Point pt1 = new Point(e.Bounds.X+6,e.Bounds.Y+e.Bounds.Height/2);
  1022. Point pt2 = new Point(e.Bounds.Right-6,pt1.Y);
  1023. MenuItem item = sender as MenuItem;
  1024. using(Pen p = new Pen(Color.Black,item.Index+1))
  1025. {
  1026. e.Graphics.DrawLine(p,pt1,pt2);
  1027. }
  1028. if(item.Checked)
  1029. {
  1030. Rectangle r = e.Bounds;
  1031. r.Inflate(-4,0);
  1032. e.Graphics.DrawRectangle(Pens.Red,r);
  1033. }
  1034. }
  1035. private void PenWidthMenu_Click(object sender, EventArgs e)
  1036. {
  1037. MenuItem item = sender as MenuItem;
  1038. if(item == this.selectedPenWidthMenuItem)
  1039. return;
  1040. this.selectedPenWidthMenuItem.Checked = false;
  1041. this.selectedPenWidthMenuItem = item;
  1042. this.selectedPenWidthMenuItem.Checked = true;
  1043. DrawEnvMgr.Instance.PenWidth = item.Index +1;
  1044. }
  1045. //Assigns an image to the button from the image list
  1046. private void UpdateColorBtnImage(Color color)
  1047. {
  1048. int imageIndex = tlBtnColor.ImageIndex;
  1049. Image image = this.GE_imageList.Images[imageIndex];
  1050. using(Graphics g = Graphics.FromImage(image))
  1051. {
  1052. using(SolidBrush b = new SolidBrush(color))
  1053. {
  1054. g.FillRectangle(b,new Rectangle(2,11,12,4));
  1055. }
  1056. }
  1057. this.GE_imageList.Images[imageIndex]=image;
  1058. tlBtnColor.ImageIndex = 0;
  1059. tlBtnColor.ImageIndex = imageIndex;
  1060. }
  1061. // Shows the color dialog box and gets the color selection of the user
  1062. private void tlBtnColor_Click()
  1063. {
  1064. ColorDialog dlg = new ColorDialog(); // instantiating new color dialog box
  1065. dlg.Color = DrawEnvMgr.Instance.Color; //assigning the DrawEnvMgr.Instance.Color to the dialog
  1066. if(DialogResult.OK == dlg.ShowDialog())
  1067. {
  1068. DrawEnvMgr.Instance.Color = dlg.Color;
  1069. UpdateColorBtnImage(dlg.Color); //updating the image with the color selected by user in the dialog box
  1070. }
  1071. }
  1072. // select button is clicked
  1073. private void tlBtnSelect_Click()
  1074. {
  1075. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Select);//Set SelectDrawTool as active
  1076. }
  1077. // line button is clicked
  1078. private void tlBtnLine_Click()
  1079. {
  1080. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Line);//Set LineDrawTool as active
  1081. }
  1082. // lines button is clicked
  1083. private void tlBtnLines_Click()
  1084. {
  1085. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Lines);//Set LineDrawTool as active
  1086. }
  1087. // freehand button is clicked
  1088. private void tlBtnFreehand_Click()
  1089. {
  1090. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Freehand);//Set FreehandDrawTool as active
  1091. }
  1092. // erase button is clicked
  1093. private void tlBtnErase_Click()
  1094. {
  1095. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Erase);//Set SelectDrawTool as active
  1096. }
  1097. // frame rectangle button is clicked
  1098. private void tlBtnFrameRect_Click()
  1099. {
  1100. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FrameRect);//Set FrameRectDrawTool as active
  1101. }
  1102. // solid button is clicked
  1103. private void tlBtnFillRect_Click()
  1104. {
  1105. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FillRect);//Set FillRectDrawTool as active
  1106. }
  1107. // frame ellipse button is clicked
  1108. private void tlBtnFrameEllipse_Click()
  1109. {
  1110. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FrameEllipse);//Set FrameEllipseDrawTool as active
  1111. }
  1112. // solid ellipse button is clicked
  1113. private void tlBtnFillEllipse_Click()
  1114. {
  1115. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.FillEllipse);//Set FillEllipseDrawTool as active
  1116. }
  1117. // sets the insert image as the active tool
  1118. private void tlBtnImage_Click()
  1119. {
  1120. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Image);//Set FillEllipseDrawTool as active
  1121. }
  1122. // sets the insert text as the active tool
  1123. private void tlBtnText_Click()
  1124. {
  1125. GraDrawToolMgr.Instance.SetActiveTool(GraDrawType.Text);//Set FillEllipseDrawTool as active
  1126. }
  1127. // cut button is clicked
  1128. private void tlBtnCut_Click( )
  1129. {
  1130. SelectDrawTool.Instance.Cut();//cut operation
  1131. }
  1132. // move button is clicked
  1133. private void tlBtnMove_Click( )
  1134. {
  1135. // to be added
  1136. }
  1137. // zoom in button is clicked
  1138. private void tlBtnZoomIn_Click()
  1139. {
  1140. this.mainView.ScaleView(1.2f);//Zoom in 1.2 times
  1141. OnViewZoomChanged();
  1142. }
  1143. // zoom out button is clicked
  1144. private void tlBtnZoomOut_Click()
  1145. {
  1146. this.mainView.ScaleView(0.8f);//Zoom out 0.8 time
  1147. OnViewZoomChanged();
  1148. }
  1149. private void OnViewZoomChanged()
  1150. {
  1151. float scale = this.mainView.ViewMatrix.Elements[0];
  1152. string text = scale.ToString("p0");
  1153. this.sbPanelViewScale.Text = text;
  1154. }
  1155. // zoom resume button is clicked
  1156. private void tlBtnZoomResume_Click()
  1157. {
  1158. this.mainView.ResetScale();//Resume to original size
  1159. OnViewZoomChanged();
  1160. }
  1161. // copy button is clicked
  1162. private void tlBtnCopy_Click( )
  1163. {
  1164. SelectDrawTool.Instance.Copy();
  1165. }
  1166. // paste button is clicked
  1167. // private void tlBtnPaste_Click( )
  1168. // {
  1169. //
  1170. // }
  1171. // undo button is clicked
  1172. private void tlBtnUndo_Click( )
  1173. {
  1174. GraEditStackMgr.Instance.Undo();//Undo operation
  1175. if(Canvas.Instance.GraList.Count == 0)
  1176. {
  1177. this.tlBtnUndo.Enabled = false;
  1178. this.menuUndo.Enabled = false;
  1179. }
  1180. if(GraEditStackMgr.Instance.GraRedoList.Count > 0)
  1181. {
  1182. this.tlBtnRedo.Enabled = true;
  1183. this.menuRedo.Enabled = true;
  1184. }
  1185. }
  1186. // redo button is clicked
  1187. private void tlBtnRedo_Click( )
  1188. {
  1189. GraEditStackMgr.Instance.Redo();//Redo operation
  1190. if(GraEditStackMgr.Instance.GraRedoList.Count == 0)
  1191. {
  1192. this.tlBtnRedo.Enabled = false;
  1193. this.menuRedo.Enabled = false;
  1194. }
  1195. if(Canvas.Instance.GraList.Count > 0)
  1196. {
  1197. this.tlBtnUndo.Enabled = true;
  1198. this.menuUndo.Enabled = true;
  1199. }
  1200. }
  1201. private void InitEditStackMgr()
  1202. {
  1203. this.tlBtnUndo.Enabled = false;
  1204. this.tlBtnRedo.Enabled = false;
  1205. this.menuRedo.Enabled = false;
  1206. this.menuUndo.Enabled = false;
  1207. GraEditStackMgr.Instance.Clear();
  1208. GraDrawTool tool = GraDrawToolMgr.Instance.ActiveDrawTool;
  1209. if(tool != null)
  1210. tool.IsActive = false;
  1211. }
  1212. // new file button is clicked
  1213. private void tlBtnNew_Click()
  1214. {
  1215. if(!this.SaveFile(true))
  1216. return;
  1217. Canvas.Instance.Close();
  1218. NewCanvasCfg dlg = new NewCanvasCfg();
  1219. dlg.Text ="Create New Canvas";
  1220. if(DialogResult.OK != dlg.ShowDialog())
  1221. return;
  1222. SelectDrawTool.Instance.IsActive = false;
  1223. Canvas.Instance.Init(null,dlg.CanvasSize,dlg.CanvasBackColor);
  1224. InitEditStackMgr();
  1225. Canvas.Instance.Update();
  1226. }
  1227. // open file button is clicked
  1228. private void tlBtnOpen_Click()
  1229. {
  1230. if(!Canvas.Instance.Open())
  1231. return;
  1232. SelectDrawTool.Instance.IsActive = false;
  1233. InitEditStackMgr();
  1234. }
  1235. // save file button is clicked
  1236. private void tlBtnSave_Click()
  1237. {
  1238. this.SaveFile(false);
  1239. }
  1240. private bool SaveFile(bool isNeedWarning)
  1241. {
  1242. if(!Canvas.Instance.IsModified)
  1243. return true;
  1244. if(isNeedWarning)
  1245. {
  1246. DialogResult r = MessageBox.Show(this,"The file has been modified,do you need save it?","Warning",
  1247. MessageBoxButtons.YesNoCancel);
  1248. if( r == DialogResult.Cancel)
  1249. return false;
  1250. if(r == DialogResult.No)
  1251. return true;
  1252. }
  1253. SaveFileDialog dlg = new SaveFileDialog();
  1254. dlg.Filter = this.fileFilter;
  1255. dlg.RestoreDirectory = true ;
  1256. if(Canvas.Instance.Name == null ||
  1257. Canvas.Instance.Name.Length == 0)
  1258. {
  1259. dlg.FilterIndex = 1 ;
  1260. if(dlg.ShowDialog() == DialogResult.OK)
  1261. {
  1262. Canvas.Instance.Name = dlg.FileName;
  1263. this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
  1264. }
  1265. else
  1266. return false;
  1267. }
  1268. else if(!Canvas.Instance.IsSavedOnce)
  1269. {
  1270. dlg.FileName = Canvas.Instance.Name;
  1271. dlg.FilterIndex = GetFilterIndexByFileName(dlg.FileName);
  1272. if(dlg.ShowDialog() == DialogResult.OK)
  1273. {
  1274. Canvas.Instance.Name = dlg.FileName;
  1275. this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
  1276. }
  1277. else
  1278. return false;
  1279. }
  1280. Canvas.Instance.Save();
  1281. return true;
  1282. }
  1283. private string fileFilter ="Bitmap files (*.bmp)|*.bmp|Jpg files (*.jpg)|*.jpg|Gif files (*.gif)|*.gif" ;
  1284. private int GetFilterIndexByFileName(string fileName)
  1285. {
  1286. string ext = Path.GetExtension(fileName);
  1287. if(ext == ".bmp")
  1288. return 1;
  1289. else if(ext ==".jpg")
  1290. return 2;
  1291. else if(ext ==".5gif")
  1292. return 3;
  1293. else
  1294. return 1;
  1295. }
  1296. // pop-up menu is clicked
  1297. private void pasteMenuItem_Click(object sender, System.EventArgs e)
  1298. {
  1299. //Console.WriteLine("{0} {1}",pt.X,pt.Y);
  1300. SelectDrawTool.Instance.Paste();//paste operation
  1301. }
  1302. //Pop-up menu
  1303. private void contextMenu1_Popup(object sender, System.EventArgs e)
  1304. {
  1305. this.mainView.contextMenu1_Popup(sender,e);//Get the click item in pop-up menu
  1306. // Point pt = Cursor.Position;
  1307. // pt = this.PointToClient(pt);
  1308. // SelectDrawTool.Instance.ContextMenuMousePos = pt;
  1309. }
  1310. //Main menu items
  1311. //Exit
  1312. private void menuExit_Click(object sender, System.EventArgs e)
  1313. {
  1314. //Application.Exit();
  1315. this.Close();
  1316. }
  1317. //Undo
  1318. private void menuUndo_Click(object sender, System.EventArgs e)
  1319. {
  1320. this.tlBtnUndo_Click();
  1321. }
  1322. //Open
  1323. private void menuOpen_Click(object sender, System.EventArgs e)
  1324. {
  1325. this.tlBtnOpen_Click();
  1326. }
  1327. //New
  1328. private void menuNew_Click(object sender, System.EventArgs e)
  1329. {
  1330. this.tlBtnNew_Click();
  1331. }
  1332. //Save as
  1333. private void menuSaveAs_Click(object sender, System.EventArgs e)
  1334. {
  1335. SaveFileDialog dlg = new SaveFileDialog();
  1336. dlg.Filter = this.fileFilter;
  1337. //dlg.FilterIndex = 1 ;
  1338. dlg.RestoreDirectory = true ;
  1339. dlg.FileName = Canvas.Instance.Name;
  1340. dlg.FilterIndex = GetFilterIndexByFileName(dlg.FileName);
  1341. if(dlg.ShowDialog() == DialogResult.OK)
  1342. {
  1343. Canvas.Instance.Name = dlg.FileName;
  1344. this.recentFilesMgr.FilesList.Insert(0,Canvas.Instance.Name);
  1345. Canvas.Instance.Save();
  1346. }
  1347. }
  1348. //Save
  1349. private void menuSave_Click(object sender, System.EventArgs e)
  1350. {
  1351. this.tlBtnSave_Click();
  1352. }
  1353. //Redo
  1354. private void menuRedo_Click(object sender, System.EventArgs e)
  1355. {
  1356. this.tlBtnRedo_Click();
  1357. }
  1358. //Copy
  1359. private void menuCopy_Click(object sender, System.EventArgs e)
  1360. {
  1361. this.tlBtnCopy_Click();
  1362. }
  1363. //Cut
  1364. private void menuCut_Click(object sender, System.EventArgs e)
  1365. {
  1366. this.tlBtnCut_Click();
  1367. }
  1368. // Paste
  1369. private void menuPaste_Click(object sender, System.EventArgs e)
  1370. {
  1371. // this.tlBtnPaste_Click();
  1372. }
  1373. // Zoom In
  1374. private void menuZoomIn_Click(object sender, System.EventArgs e)
  1375. {
  1376. this.tlBtnZoomIn_Click();
  1377. }
  1378. //ZoomOut
  1379. private void menuZoomOut_Click(object sender, System.EventArgs e)
  1380. {
  1381. this.tlBtnZoomOut_Click();
  1382. }
  1383. //Resume
  1384. private void menuResume_Click(object sender, System.EventArgs e)
  1385. {
  1386. this.tlBtnZoomResume_Click();
  1387. }
  1388. // Assigns the pen width to the DrawEnvMgr.Instance.PenWidth from the selection in the combo box
  1389. // private void cboPenWidth_SelectedIndexChanged(object sender, EventArgs e)
  1390. // {
  1391. // int penWidth = (int)this.cboPenWidth.SelectedItem;
  1392. // DrawEnvMgr.Instance.PenWidth = penWidth;
  1393. // }
  1394. //Gets the background color for the image from the user using Color DialogBox
  1395. private void menuItemCanvasBackColor_Click(object sender, System.EventArgs e)
  1396. {
  1397. ColorDialog dlg = new ColorDialog();
  1398. dlg.Color = Canvas.Instance.BackColor;
  1399. if(DialogResult.OK == dlg.ShowDialog())
  1400. {
  1401. foreach(GraElement gra in Canvas.Instance.GraList)
  1402. {
  1403. if(gra is EraseLinesGra)
  1404. {
  1405. gra.PenExt.Color = dlg.Color;
  1406. }
  1407. if(gra is EraseRectGra)
  1408. {
  1409. gra.PenExt.Color = dlg.Color;
  1410. gra.BrushExt.Color = dlg.Color;
  1411. }
  1412. }
  1413. Canvas.Instance.BackColor = dlg.Color;
  1414. }
  1415. }
  1416. // Shows the help Dialog box
  1417. // private void menuHelp_Click(object sender, System.EventArgs e)
  1418. // {
  1419. //
  1420. //
  1421. // }
  1422. private void GE_toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  1423. {
  1424. ToolBarButton b = e.Button;//clicked Toolbar button
  1425. if(b != this.tlBtnText)
  1426. TextDrawTool.Instance.EndTextEditing(true);
  1427. if(b == this.tlBtnNew) // new image button is clicked
  1428. tlBtnNew_Click();
  1429. else if(b == this.tlBtnOpen) // open an existing image button is clicked
  1430. tlBtnOpen_Click();
  1431. else if(b == this.tlBtnSave) // save the current image button is clicked
  1432. tlBtnSave_Click();
  1433. else if(b == this.tlBtnUndo)//Undo button is clicked
  1434. tlBtnUndo_Click();
  1435. else if(b == this.tlBtnRedo)//Redo button is clicked
  1436. tlBtnRedo_Click();
  1437. else if(b == this.tlBtnColor)
  1438. tlBtnColor_Click();
  1439. else if(b == this.tlBtnFont)
  1440. tlBtnFont_Click();
  1441. else if(b == this.tlBtnCut)//Cut button is clicked
  1442. tlBtnCut_Click( );
  1443. // else if(b == this.tlBtnMove)//Move button is clicked
  1444. // tlBtnMove_Click( );
  1445. else if(b == this.tlBtnCopy)//Copy button is clicked
  1446. tlBtnCopy_Click( );
  1447. // else if(b == this.tlBtnPaste)//Paste button is clicked
  1448. // tlBtnPaste_Click( );
  1449. else if(b == this.tlBtnSelect)//Select button is clicked
  1450. tlBtnSelect_Click();
  1451. }
  1452. private void menuView_Popup(object sender, System.EventArgs e)
  1453. {
  1454. menuToolbar.MenuItems.Clear();
  1455. foreach (Control c in _toolBarManager.GetControls())
  1456. {
  1457. ToolBarDockHolder holder = _toolBarManager.GetHolder(c);
  1458. MenuItem mi = new MenuItem(holder.ToolbarTitle, new EventHandler(this.menuToolbar_Click));
  1459. mi.Checked = holder.Visible;
  1460. menuToolbar.MenuItems.Add(mi);
  1461. }
  1462. }
  1463. private void GE_Load(object sender, System.EventArgs e)
  1464. {
  1465. }
  1466. private void menuToolbar_Click(object sender, System.EventArgs e)
  1467. {
  1468. MenuItem mi = sender as MenuItem;
  1469. ToolBarDockHolder holder = _toolBarManager.GetHolder(mi.Text);
  1470. _toolBarManager.ShowControl(holder.Control, !holder.Control.Visible);
  1471. }
  1472. private void menuColorToolbox_Click(object sender, System.EventArgs e)
  1473. {
  1474. tlBtnColor_Click();
  1475. }
  1476. private void menuColorSettings_Click(object sender, System.EventArgs e)
  1477. {
  1478. tlBtnColor_Click();
  1479. }
  1480. private void menuToolbar_Click_1(object sender, System.EventArgs e)
  1481. {
  1482. MenuItem mi = sender as MenuItem;
  1483. ToolBarDockHolder holder = _toolBarManager.GetHolder(mi.Text);
  1484. _toolBarManager.ShowControl(holder.Control, !holder.Control.Visible);
  1485. }
  1486. private void menuAboutGE_Click(object sender, System.EventArgs e)
  1487. {
  1488. AboutDialog dlg = new AboutDialog();
  1489. dlg.ShowDialog();
  1490. }
  1491. private void printPreviewDialog1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  1492. {
  1493. }
  1494. private void menuPrintPreview_Click(object sender, System.EventArgs e)
  1495. {
  1496. this.printPreviewDialog1.ShowDialog();
  1497. }
  1498. private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  1499. {
  1500. }
  1501. private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  1502. {
  1503. }
  1504. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  1505. {
  1506. //e.p
  1507. try
  1508. {
  1509. Graphics g = e.Graphics;
  1510. Region r = new Region(new Rectangle(new Point(0,0),Canvas.Instance.Size));
  1511. Region old = g.Clip;
  1512. g.Clip = r;
  1513. ArrayList list = Canvas.Instance.GraList;
  1514. foreach(GraElement gra in list)
  1515. {
  1516. if(gra is EraseLinesGra)
  1517. {
  1518. gra.PenExt.Color = Color.White;
  1519. gra.Draw(g);
  1520. gra.PenExt.Color = Canvas.Instance.BackColor;
  1521. }
  1522. else if(gra is EraseRectGra)
  1523. {
  1524. gra.PenExt.Color = Color.White;
  1525. gra.BrushExt.Color = Color.White;
  1526. gra.Draw(g);
  1527. gra.PenExt.Color = Canvas.Instance.BackColor;
  1528. gra.BrushExt.Color = Canvas.Instance.BackColor;
  1529. }
  1530. else
  1531. gra.Draw(g);
  1532. }
  1533. g.Clip = old;
  1534. }
  1535. catch(Exception ex)
  1536. {
  1537. MessageBox.Show("Error when print document - " + ex.Message);
  1538. }
  1539. }
  1540. private void menuPageSetting_Click(object sender, System.EventArgs e)
  1541. {
  1542. try
  1543. {
  1544. this.pageSetupDialog1.ShowDialog();
  1545. }
  1546. catch(Exception ex)
  1547. {
  1548. MessageBox.Show("Error - " + ex.Message);
  1549. }
  1550. }
  1551. private void menuItem2_Click(object sender, System.EventArgs e)
  1552. {
  1553. }
  1554. private RecentFilesMgr recentFilesMgr;
  1555. private void InitRecentFilesMgr()
  1556. {
  1557. string path = Application.StartupPath;
  1558. string logFileName = path +"/RecentFiles.txt";
  1559. this.recentFilesMgr = new RecentFilesMgr(logFileName);
  1560. this.recentFilesMgr.ReadRecentFiles();
  1561. if(this.recentFilesMgr.FilesList.Count == 0)
  1562. return;
  1563. MenuItem[] items = new MenuItem[this.recentFilesMgr.FilesList.Count];
  1564. for(int i=0; i< items.Length; i++)
  1565. {
  1566. items[i] = new MenuItem(this.recentFilesMgr.FilesList[i] as string);
  1567. items[i].Click +=new EventHandler(RecentFileMenuItem_Click);
  1568. }
  1569. this.menuRecentFiles.MenuItems.AddRange(items);
  1570. }
  1571. private void RecentFileMenuItem_Click(object sender, EventArgs e)
  1572. {
  1573. MenuItem item = sender as MenuItem;
  1574. if(!Canvas.Instance.OpenFile(item.Text))
  1575. return;
  1576. InitEditStackMgr();
  1577. }
  1578. private void GE_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  1579. {
  1580. DialogResult r = MessageBox.Show(this,"Do you want exit?","Warning",MessageBoxButtons.OKCancel);
  1581. if(r == DialogResult.Cancel)
  1582. {
  1583. e.Cancel = true;
  1584. return;
  1585. }
  1586. this.tlBtnSave_Click();
  1587. Canvas.Instance.Close();
  1588. this.recentFilesMgr.SaveRecentFiles();
  1589. }
  1590. private void menuStatusBar_Click(object sender, System.EventArgs e)
  1591. {
  1592. MenuItem item = sender as MenuItem;
  1593. item.Checked = !item.Checked;
  1594. this.GE_statusBar.Visible = item.Checked;
  1595. }
  1596. private class RecentFilesMgr
  1597. {
  1598. public RecentFilesMgr(string logFileName)
  1599. {
  1600. this.filesList = new ArrayList();
  1601. this.logFileName = logFileName;
  1602. }
  1603. private ArrayList filesList;
  1604. public ArrayList FilesList
  1605. {
  1606. get { return filesList; }
  1607. }
  1608. private string logFileName;
  1609. public void ReadRecentFiles()
  1610. {
  1611. FileInfo fi = new FileInfo(logFileName);
  1612. if(!fi.Exists)
  1613. return;
  1614. StreamReader s = fi.OpenText();
  1615. string line = null;
  1616. while(( line = s.ReadLine()) != null)
  1617. {
  1618. FileInfo f = new FileInfo(line);
  1619. if(!f.Exists)
  1620. continue;
  1621. filesList.Add(line);
  1622. if(filesList.Count == 10)
  1623. break;
  1624. }
  1625. }
  1626. public void SaveRecentFiles( )
  1627. {
  1628. using (StreamWriter sw = new StreamWriter(this.logFileName,false))
  1629. {
  1630. foreach(string line in this.filesList)
  1631. {
  1632. sw.WriteLine(line);
  1633. }
  1634. }
  1635. }
  1636. }
  1637. private void GraDrawTool_ActiveStateChanged(object sender, EventArgs e)
  1638. {
  1639. GraDrawTool drawTool = sender as GraDrawTool;
  1640. this.sbPanelTip.Text = drawTool.Tip;
  1641. }
  1642. private void mainView_MouseMove(object sender, MouseEventArgs e)
  1643. {
  1644. Point pos = new Point(e.X,e.Y);//Temporary end point
  1645. pos = GraDrawTool.GetRoundPoint(pos);//Round the end point. The min mouse movement distance is 6.
  1646. string text =string.Format("X= {0} Y= {1}",pos.X,pos.Y);
  1647. this.sbPanelMousePos.Text = text;
  1648. }
  1649. private void canvas_Modified(object sender, EventArgs e)
  1650. {
  1651. Canvas c = Canvas.Instance;
  1652. string title = "Graphic Editor -- ";
  1653. if(c.Name != null && c.Name.Length >0)
  1654. title += c.Name;
  1655. else
  1656. title += "Unnamed.bmp";
  1657. if(c.IsModified)
  1658. title +="*";
  1659. this.Text = title;
  1660. if(Canvas.Instance.GraList.Count > 0)
  1661. {
  1662. this.tlBtnUndo.Enabled = true;
  1663. this.menuUndo.Enabled = true;
  1664. }
  1665. }
  1666. private void selectTool_StateChanged(object sender, EventArgs e)
  1667. {
  1668. SelectDrawTool tool = sender as SelectDrawTool;
  1669. if(tool.SelectRectGra != null)
  1670. {
  1671. this.tlBtnCut.Enabled = true;
  1672. this.tlBtnCopy.Enabled = true;
  1673. this.menuCopy.Enabled = true;
  1674. this.menuCut.Enabled = true;
  1675. }
  1676. else
  1677. {
  1678. this.tlBtnCut.Enabled = false;
  1679. this.tlBtnCopy.Enabled = false;
  1680. this.menuCopy.Enabled = false;
  1681. this.menuCut.Enabled = false;
  1682. }
  1683. if(tool.CopyImage != null)
  1684. {
  1685. this.pasteMenuItem.Enabled = true;
  1686. //this.menuPaste.Enabled = true;
  1687. }
  1688. else
  1689. {
  1690. this.pasteMenuItem.Enabled = false;
  1691. //this.menuPaste.Enabled = false;
  1692. }
  1693. }
  1694. private void menuItemCanvasSize_Click(object sender, System.EventArgs e)
  1695. {
  1696. NewCanvasCfg dlg = new NewCanvasCfg();
  1697. dlg.Text ="Change Canvas Size";
  1698. dlg.CanvasSize = Canvas.Instance.Size;
  1699. if(DialogResult.OK == dlg.ShowDialog())
  1700. {
  1701. Canvas.Instance.Size = dlg.CanvasSize;
  1702. Canvas.Instance.Update();
  1703. }
  1704. }
  1705. private void menuPrint_Click(object sender, System.EventArgs e)
  1706. {
  1707. try
  1708. {
  1709. this.printDocument1.Print();
  1710. }
  1711. catch(Exception ex)
  1712. {
  1713. MessageBox.Show("Print file error - " + ex.Message);
  1714. }
  1715. }
  1716. private void menuHelpIndex_Click(object sender, System.EventArgs e)
  1717. {
  1718. try
  1719. {
  1720. string s = Application.ExecutablePath;
  1721. s = s.Replace("GE.exe","help.chm");
  1722. Process.Start(s);
  1723. }
  1724. catch(Exception e1)
  1725. {
  1726. MessageBox.Show(e1.Message);
  1727. }
  1728. }
  1729. private void mainView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  1730. {
  1731. }
  1732. }
  1733. /// <summary>
  1734. /// All the drawing in Graphical Editor is done on the canvas.
  1735. /// Canvas class is used to define the drawing area.
  1736. /// </summary>
  1737. public class Canvas
  1738. {
  1739. //Construct graList to save the drawing actions
  1740. protected Canvas()
  1741. {
  1742. this.graList = new ArrayList(); // define an arraylist with name gralist for saving all the drawing actions
  1743. }
  1744. //Initialize the canvas. Set name,size and background color of canvas
  1745. public void Init(string name, Size size,Color backColor)
  1746. {
  1747. this.name = name;//Set name of canvas
  1748. this.Size = size;//Set size of canvas
  1749. this.backColor = backColor;//Set background color of canvas
  1750. this.graList.Clear();//Clear all the elements in graList
  1751. //this.mainView.AutoScrollMinSize = this.Size;//this.Size;//Set the size of mainView as canvas size
  1752. this.isSavedOnce = false;
  1753. this.IsModified = false;
  1754. }
  1755. private static Canvas _single;
  1756. public static Canvas Instance
  1757. {
  1758. //Get canvas instance
  1759. get
  1760. {
  1761. if( _single == null)
  1762. _single = new Canvas();
  1763. return _single;
  1764. }
  1765. }
  1766. public event EventHandler Modified;
  1767. protected void OnModified()
  1768. {
  1769. if(Modified != null)
  1770. Modified(this,EventArgs.Empty);
  1771. }
  1772. //Dirty flag
  1773. private bool isModified;
  1774. public bool IsModified
  1775. {
  1776. get { return this.isModified; }
  1777. set
  1778. {
  1779. this.isModified = value;
  1780. OnModified();
  1781. }
  1782. }
  1783. private bool isSavedOnce;
  1784. public bool IsSavedOnce
  1785. {
  1786. get { return this.isSavedOnce; }
  1787. set { this.isSavedOnce = value;}
  1788. }
  1789. private MainView mainView;//private Mainview variable of canvas
  1790. public MainView MainView
  1791. {
  1792. get { return mainView; }
  1793. set { mainView = value;}
  1794. }
  1795. public void Update()//Refresh canvas
  1796. {
  1797. this.mainView.UpdateView();
  1798. }
  1799. private string name;//canvas name
  1800. public string Name
  1801. {
  1802. get { return name; }
  1803. set { name = value; }
  1804. }
  1805. private Size size;//canvas size
  1806. public Size Size
  1807. {
  1808. get { return size; }
  1809. set
  1810. {
  1811. size = value;
  1812. this.mainView.AutoScrollMinSize = this.size;//this.Size;//Set the size of mainView as canvas size
  1813. }
  1814. }
  1815. private Color backColor;//canvas color i.e. background color of the image
  1816. public Color BackColor
  1817. {
  1818. get { return backColor; }
  1819. set
  1820. {
  1821. backColor = value;
  1822. this.Update();
  1823. }
  1824. }
  1825. private ArrayList graList;//Save drawing action on canvas
  1826. public ArrayList GraList
  1827. {
  1828. get { return graList; }
  1829. }
  1830. public void AddGra(GraElement gra)
  1831. {
  1832. this.graList.Add(gra);
  1833. this.IsModified = true;
  1834. this.Update();
  1835. }
  1836. public void DelGra(GraElement gra)
  1837. {
  1838. this.graList.Remove(gra);
  1839. this.IsModified = true;
  1840. this.Update();
  1841. }
  1842. //Draw function of canvas
  1843. public void Draw(Graphics g)
  1844. {
  1845. foreach(GraElement gra in graList)//Draw all the element in the graList
  1846. gra.Draw(g);
  1847. }
  1848. public bool Open()
  1849. {
  1850. OpenFileDialog dlg = new OpenFileDialog(); // new open dialog box is instantiated
  1851. dlg.Filter = "Image files (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif" ;
  1852. dlg.FilterIndex = 1 ;
  1853. dlg.RestoreDirectory = true ;
  1854. bool bRtn = false;
  1855. if(dlg.ShowDialog() == DialogResult.OK)
  1856. {
  1857. try
  1858. {
  1859. bRtn = this.OpenFile(dlg.FileName);
  1860. }
  1861. catch(Exception ex)
  1862. {
  1863. MessageBox.Show("Open file error - " + ex.Message);
  1864. }
  1865. }
  1866. return bRtn;
  1867. }
  1868. private FileStream canvasStream;
  1869. public bool OpenFile(string fileName)
  1870. {
  1871. FileInfo fi = new FileInfo(fileName);
  1872. if(!fi.Exists)
  1873. {
  1874. MessageBox.Show("Can't find this file!","Open File");
  1875. return false;
  1876. }
  1877. try
  1878. {
  1879. canvasStream = File.Open(fileName,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
  1880. }
  1881. catch(Exception ex)
  1882. {
  1883. MessageBox.Show("Open File Error - " + ex.Message);
  1884. }
  1885. Bitmap bmp = new Bitmap(canvasStream);
  1886. //fs.Close();
  1887. if(bmp != null)
  1888. {
  1889. Canvas.Instance.Init(fileName,bmp.Size,Color.White);
  1890. ImageGra imageGra = new ImageGra(bmp,new Rectangle(new Point(0,0),bmp.Size));
  1891. Canvas.Instance.GraList.Add(imageGra);//Add to GraList
  1892. Canvas.Instance.Update();//Update canvas
  1893. }
  1894. return true;
  1895. }
  1896. private ImageFormat GetImageFormatByFileName(string fileName)
  1897. {
  1898. string ext = Path.GetExtension(fileName);
  1899. ImageFormat format = ImageFormat.Bmp;
  1900. switch(ext)
  1901. {
  1902. case ".jpg":
  1903. format =ImageFormat.Jpeg;
  1904. break;
  1905. case ".gif":
  1906. format = ImageFormat.Gif;
  1907. break;
  1908. default:
  1909. format = ImageFormat.Bmp;
  1910. break;
  1911. }
  1912. return format;
  1913. }
  1914. public void Save()
  1915. {
  1916. //if(this.canvasStream == null)
  1917. // return;
  1918. if(this.name == null ||
  1919. this.name.Length == 0)
  1920. {
  1921. MessageBox.Show("Invalid file name!","Warning");
  1922. return;
  1923. }
  1924. Size s = Canvas.Instance.Size;
  1925. Bitmap bmp = new Bitmap(s.Width,s.Height);
  1926. Graphics gBmp = Graphics.FromImage(bmp);
  1927. gBmp.Clear(Canvas.Instance.BackColor);
  1928. this.Draw(gBmp);
  1929. try
  1930. {
  1931. if(this.canvasStream != null)
  1932. this.canvasStream.Close();
  1933. ImageFormat format = GetImageFormatByFileName(Canvas.Instance.Name);
  1934. bmp.Save(Canvas.Instance.Name,format);
  1935. bmp.Dispose();
  1936. this.IsModified = false;
  1937. this.IsSavedOnce = true;
  1938. this.canvasStream = File.Open(this.name,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
  1939. }
  1940. catch(Exception ex)
  1941. {
  1942. MessageBox.Show("Save file error - " + ex.Message);
  1943. }
  1944. }
  1945. public bool Close()
  1946. {
  1947. if(canvasStream != null)
  1948. {
  1949. canvasStream.Close();
  1950. canvasStream = null;
  1951. }
  1952. return true;
  1953. }
  1954. }
  1955. //Redo & Undo operation
  1956. public class GraEditStackMgr
  1957. {
  1958. private GraEditStackMgr()//construct a redo list
  1959. {
  1960. this.graRedoList = new ArrayList();
  1961. }
  1962. private static GraEditStackMgr instance;
  1963. public static GraEditStackMgr Instance
  1964. {
  1965. get
  1966. {
  1967. if(instance == null)
  1968. instance = new GraEditStackMgr();
  1969. return instance;
  1970. }
  1971. }
  1972. private ArrayList graRedoList;//Redo list
  1973. public ArrayList GraRedoList
  1974. {
  1975. get { return graRedoList;}
  1976. }
  1977. public void Clear()
  1978. {
  1979. this.graRedoList.Clear();
  1980. }
  1981. //Redo operation
  1982. public void Redo()
  1983. {
  1984. if(this.graRedoList.Count == 0)//no undo happen
  1985. return;
  1986. int lastIndex = this.graRedoList.Count -1;//Get the last undo action
  1987. //Save last undo action to graLast
  1988. GraElement graLast = this.graRedoList[lastIndex] as GraElement;
  1989. this.graRedoList.RemoveAt(lastIndex);//Remove the last undo action from redo list
  1990. //Canvas.Instance.GraList.Add(graLast);//Save the last undo action to GraList
  1991. //Canvas.Instance.Update();//Update canvas
  1992. Canvas.Instance.AddGra(graLast);
  1993. }
  1994. //Undo operation
  1995. public void Undo()
  1996. {
  1997. ArrayList graList = Canvas.Instance.GraList;//Get the GraList of Canvas
  1998. if(graList.Count == 0)//No drawing action happen
  1999. return;
  2000. int lastIndex = graList.Count -1;//Last drawing action position in graList
  2001. //Save the last drawing action to graLast
  2002. GraElement graLast = graList[lastIndex] as GraElement;
  2003. graList.RemoveAt(lastIndex);//Remove the last drawing action
  2004. this.graRedoList.Add(graLast);//Add the last drawing action to redo list
  2005. Canvas.Instance.Update();//Update canvas
  2006. Canvas.Instance.IsModified = true;
  2007. }
  2008. }
  2009. }