Click here to Skip to main content
15,884,986 members
Articles / Desktop Programming / Windows Forms

A Practical Use of the MVC Pattern

Rate me:
Please Sign up or sign in to vote.
4.55/5 (41 votes)
8 Jan 2007CPOL5 min read 179.1K   2.7K   145  
Another approach to the MVC pattern
using System;
using System.Windows.Forms;
using MvcExample.Controllers;

namespace MvcExample
{
	public class MvcExample : Form
	{
		#region Windows Form Designer generated code
		private System.Windows.Forms.Button butListView;
		private System.Windows.Forms.Button butGraphView;
		private System.Windows.Forms.GroupBox grpDesc;
		private System.ComponentModel.Container components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.butListView = new System.Windows.Forms.Button();
			this.butGraphView = new System.Windows.Forms.Button();
			this.grpDesc = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// butListView
			// 
			this.butListView.Location = new System.Drawing.Point(8, 208);
			this.butListView.Name = "butListView";
			this.butListView.Size = new System.Drawing.Size(112, 32);
			this.butListView.TabIndex = 0;
			this.butListView.Text = "Show list";
			this.butListView.Click += new System.EventHandler(this.butListView_Click);
			// 
			// butGraphView
			// 
			this.butGraphView.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.butGraphView.Location = new System.Drawing.Point(168, 208);
			this.butGraphView.Name = "butGraphView";
			this.butGraphView.Size = new System.Drawing.Size(112, 32);
			this.butGraphView.TabIndex = 1;
			this.butGraphView.Text = "Show graph";
			this.butGraphView.Click += new System.EventHandler(this.butGraphView_Click);
			// 
			// grpDesc
			// 
			this.grpDesc.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
				| System.Windows.Forms.AnchorStyles.Left)
				| System.Windows.Forms.AnchorStyles.Right)));
			this.grpDesc.Location = new System.Drawing.Point(8, 8);
			this.grpDesc.Name = "grpDesc";
			this.grpDesc.Size = new System.Drawing.Size(272, 192);
			this.grpDesc.TabIndex = 2;
			this.grpDesc.TabStop = false;
			this.grpDesc.Text = "Description";
			// 
			// MvcExample
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(288, 245);
			this.Controls.Add(this.grpDesc);
			this.Controls.Add(this.butGraphView);
			this.Controls.Add(this.butListView);
			this.MaximizeBox = false;
			this.Name = "MvcExample";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "A demo of the MVC pattern";
			this.ResumeLayout(false);

		}
		#endregion

		#region constructor
		public MvcExample()
		{
			InitializeComponent();
		}
		#endregion constructor

		#region button eventhandlers
		private void butListView_Click(object sender, EventArgs e)
		{
			RptController controller = new RptController(RptControllerType.List);
		}

		private void butGraphView_Click(object sender, EventArgs e)
		{
			RptController controller = new RptController(RptControllerType.Graph);
		}
		#endregion button eventhandlers
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Romania Romania
I've did some programming for Macintosh a few years back and working with Microsoft technologies since then.

Comments and Discussions