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

Generic Property Window

Rate me:
Please Sign up or sign in to vote.
3.43/5 (21 votes)
16 Feb 2006CPOL8 min read 49.4K   337   40  
Article that demostrates how to create generic property windows.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GenericPropertyWindows
{
    public partial class MainFrame : Form
    {
        public MainFrame()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Employee emp = new Employee();
            emp.Name = "Kith";
            emp.LastName = "Kanan";
            emp.Age = 22;

            PropertyWindow<Employee> wndProp = new PropertyWindow<Employee>(emp);
            wndProp.ShowDialog(this);

            MessageBox.Show(string.Format(
                "After modifying Employee:\nName: {0}\nLastName: {1}\nAge: {2}",
                emp.Name,
                emp.LastName,
                emp.Age)
            );
        }

        private void button2_Click(object sender, EventArgs e)
        {
            PropertyWindow<Account> wndProp = new PropertyWindow<Account>();
            wndProp.ShowDialog(this);

            Account acc = wndProp.Property;

            MessageBox.Show(string.Format(
                "After modifying Account:\nName: {0}\nBalance: {1}\nExpiration: {2}\nPIN:{3}",
                acc.AccountName,
                acc.Balance,
                acc.ExpirationDate,
                acc.PIN)
            );
        }
    }
}

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
Chief Technology Officer Blendwerk TI & Media
Mexico Mexico
42

Comments and Discussions