Click here to Skip to main content
15,884,537 members
Articles / Web Development / ASP.NET

Part II: Web & Window Form Unification: Synchronous And Asynchronous Event Handling For Controls Created At Runtime

Rate me:
Please Sign up or sign in to vote.
5.00/5 (14 votes)
13 Jul 20027 min read 128.1K   1.3K   81  
This is the second part of a multipart article on unifying web and window form application development. This part demonstrates synchronous and asynchronous event handling of GUI control events, abstracting the implementation of web/window forms to be technology independant.
using System;
using System.Drawing;
using System.Windows.Forms;		// for MessageBox

using dynFormLib;

class AppMain
{
	static void Main()
	{
		EventManager.EventCollection.Add("ClearForm", new System.EventHandler(AppEvents.ClearForm));

		ControlInfo[] ctrlInfo=new ControlInfo[46];

		// Customer Information GUI

		ctrlInfo[0]=new ControlInfo("label", new Point(20, 33), new Size(80, 15), "lblLastName", "Last Name:", "", "");
		ctrlInfo[1]=new ControlInfo("imageButton", new Point(100, 30), new Size(20, 20), "btnClearForm", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\clearForm.ico", "", "", "onClick=*ClearForm");
		ctrlInfo[2]=new ControlInfo("edit", new Point(120, 30), new Size(200, 20), "edLastName", "", "", "");
		ctrlInfo[3]=new ControlInfo("imageButton", new Point(320, 30), new Size(20, 20), "btnFind", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\binocs.ico", "", "");
		ctrlInfo[4]=new ControlInfo("imageButton", new Point(340, 30), new Size(20, 20), "btnNew", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\new.ico", "", "");
		ctrlInfo[5]=new ControlInfo("imageButton", new Point(360, 30), new Size(20, 20), "btnPrint", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\print.ico", "", "");
		ctrlInfo[6]=new ControlInfo("imageButton", new Point(380, 30), new Size(20, 20), "btnDelete", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\delete.ico", "", "");

		ctrlInfo[7]=new ControlInfo("label", new Point(425, 33), new Size(65, 15), "lblFirstName", "First Name:", "", "");
		ctrlInfo[8]=new ControlInfo("edit", new Point(490, 30), new Size(200, 20), "edFirstName", "", "", "");

		ctrlInfo[9]=new ControlInfo("label", new Point(20, 53), new Size(100, 15), "lblAddr1", "Address1:", "", "");
		ctrlInfo[10]=new ControlInfo("edit", new Point(120, 50), new Size(200, 20), "edAddr1", "", "", "");
		ctrlInfo[11]=new ControlInfo("label", new Point(20, 73), new Size(100, 15), "lblAddr2", "Address2:", "", "");
		ctrlInfo[12]=new ControlInfo("edit", new Point(120, 70), new Size(200, 20), "edAddr2", "", "", "");
		ctrlInfo[13]=new ControlInfo("label", new Point(20, 93), new Size(100, 15), "lblCity", "City:", "", "");
		ctrlInfo[14]=new ControlInfo("edit", new Point(120, 90), new Size(200, 20), "edCity", "", "", "");

		ctrlInfo[15]=new ControlInfo("label", new Point(340, 93), new Size(40, 15), "lblState", "State:", "", "");
		ctrlInfo[16]=new ControlInfo("edit", new Point(380, 90), new Size(50, 20), "edState", "", "", "");

		ctrlInfo[17]=new ControlInfo("label", new Point(450, 93), new Size(40, 15), "lblZip5", "Zip5:", "", "");
		ctrlInfo[18]=new ControlInfo("edit", new Point(490, 90), new Size(50, 20), "edZip5", "", "", "");

		ctrlInfo[19]=new ControlInfo("label", new Point(560, 93), new Size(40, 15), "lblZip4", "Zip4:", "", "");
		ctrlInfo[20]=new ControlInfo("edit", new Point(600, 90), new Size(50, 20), "edZip4", "", "", "");

		ctrlInfo[21]=new ControlInfo("label", new Point(20, 113), new Size(100, 15), "lblPhone", "Phone:", "", "");
		ctrlInfo[22]=new ControlInfo("edit", new Point(120, 110), new Size(200, 20), "edPhone", "", "", "");
		ctrlInfo[23]=new ControlInfo("label", new Point(330, 113), new Size(50, 15), "lblTaxID", "Tax ID:", "", "");
		ctrlInfo[24]=new ControlInfo("edit", new Point(380, 110), new Size(100, 20), "edTaxID", "", "", "");
		ctrlInfo[25]=new ControlInfo("checkBox", new Point(500, 113), new Size(150, 20), "ckTaxExempt", "Always tax exempt", "", "");

		ctrlInfo[26]=new ControlInfo("label", new Point(20, 133), new Size(100, 15), "lblEmail", "Email:", "", "");
		ctrlInfo[27]=new ControlInfo("edit", new Point(120, 130), new Size(200, 20), "edEmail", "", "", "");

		ctrlInfo[28]=new ControlInfo("groupBox", new Point(10, 10), new Size(730, 150), "gb1", "Customer Information:", "", "");

		// Customer/Yard Boats GUI

		ctrlInfo[29]=new ControlInfo("listView", new Point(20, 200), new Size(250, 120), "lcBoats", "ID:0,Boat Name:245", "", "");
		ctrlInfo[30]=new ControlInfo("imageButton", new Point(280, 200), new Size(20, 20), "btnAddBoat", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\add.ico", "", "");
		ctrlInfo[31]=new ControlInfo("imageButton", new Point(280, 220), new Size(20, 20), "btnRemoveBoat", "c:\\projects.net\\AutoFormPrototype\\csform\\icons\\delete.ico", "", "");
		ctrlInfo[32]=new ControlInfo("groupBox", new Point(10, 180), new Size(400, 150), "gb2", "Customer/Yard Boats:", "", "");

		// Account Setup GUI

		ctrlInfo[33]=new ControlInfo("label", new Point(430, 203), new Size(100, 15), "lblCCType", "CC Type:", "", "");
		ctrlInfo[34]=new ControlInfo("comboBox", new Point(540, 200), new Size(150, 100), "cbCCType", "", "", "");
		ctrlInfo[35]=new ControlInfo("label", new Point(430, 223), new Size(100, 15), "lblCreditCard", "Credit Card:", "", "");
		ctrlInfo[36]=new ControlInfo("edit", new Point(540, 220), new Size(150, 20), "edCreditCard", "", "", "");
		ctrlInfo[37]=new ControlInfo("label", new Point(430, 243), new Size(100, 15), "lblExpDate", "Exp. Date:", "", "");
		ctrlInfo[38]=new ControlInfo("edit", new Point(540, 240), new Size(100, 20), "edExpDate", "", "", "");
		ctrlInfo[39]=new ControlInfo("checkBox", new Point(430, 280), new Size(100, 20), "ckTransient", "Transient?", "", "");
		ctrlInfo[40]=new ControlInfo("checkBox", new Point(540, 280), new Size(100, 20), "ckYardAcct", "Yard Account?", "", "");
		ctrlInfo[41]=new ControlInfo("label", new Point(430, 303), new Size(110, 15), "lblPMRate", "Parts/Material Rate:", "", "");
		ctrlInfo[42]=new ControlInfo("comboBox", new Point(540, 300), new Size(100, 100), "cbPMRate", "", "", "");

		ctrlInfo[43]=new ControlInfo("groupBox", new Point(420, 180), new Size(320, 150), "gb3", "Account Setup:", "", "");

		// Open WorkOrders GUI

		ctrlInfo[44]=new ControlInfo("listView", new Point(20, 370), new Size(690, 120), "lcBoats", "ID:0,WO #:100,Open Date:100,Close Date:100", "", "");
		ctrlInfo[45]=new ControlInfo("groupBox", new Point(10, 350), new Size(730, 150), "gb4", "Open Work Orders:", "", "");

		DynWindowForm mainForm=new DynWindowForm();
		mainForm.Init(new System.Windows.Forms.Form());
		mainForm.Create(0, 0, 800, 600, "Dynamic Form", "dynForm");
		mainForm.LoadControls(ctrlInfo);
		mainForm.Run();
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions