//************************************************************************
// //
// SQL Power Injector 1.2 Copyright (c) 2006-2007 Francois Larouche //
// //
// Authors : Francois Larouche //
// Inspired on source code from MSDN website by Matthew A. //
// Stoecker, Microsoft Corporation //
// Web Site: http://msdn.microsoft.com/library/default.asp?url=/ //
// library/en-us/dv_vstechart/html/ //
// vbtchCreatingControlArraysInVisualBasicNETVisualCNET.asp //
// //
//**********************************************************************//
using System;
using System.Windows.Forms;
using System.Drawing;
namespace SQLPowerInjector{
public delegate void ClickEventHandler(object sender, EventArgs e);
/// <summary>
/// Summary description for ButtonCollection.
/// </summary>
public class ButtonCollection : System.Collections.CollectionBase
{
#region Members
#region Private
private readonly Form _hostForm;
#endregion
#endregion
#region Constructor
public ButtonCollection(Form host)
{
_hostForm = host;
}
#endregion
#region Public Attributes
public Button this[int Index]
{
get
{
return (Button)this.List[Index];
}
}
#endregion
public event ClickEventHandler Clicked;
public Button AddNewButton(int topPos, int leftPos, int sizeWidth, int sizeHeight, string buttonText)
{
Button curButton = new Button();
// Add the button to the collection's internal list.
this.List.Add(curButton);
// Add the button to the controls collection of the form
// referenced by the _hostForm field.
_hostForm.Controls.Add(curButton);
curButton.Top = topPos;
curButton.Left = leftPos;
curButton.Size = new System.Drawing.Size(sizeWidth, sizeHeight);
curButton.Tag = this.Count - 1;
curButton.Text = buttonText;
curButton.Click += new System.EventHandler(ClickHandler);
return curButton;
}
public void Remove(int buttonIndex)
{
// Check to be sure there is a button to remove.
if (this.Count > 0 && buttonIndex <= this.Count)
{
_hostForm.Controls.Remove(this[buttonIndex]);
this.List.RemoveAt(buttonIndex);
}
}
public void ClickHandler(Object sender, System.EventArgs e)
{
if(Clicked != null)
Clicked(sender, e);
}
}
}
|