using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Xml;
using Microsoft.CSharp;
namespace DarkWynter.Shell
{
public class UCAD_Tab : TabPage
{
static int UCAD_TabIndex = 0;
// Control spacing of Labels and Buttons
int cursorPositionX = 3;
int cursorPositionY = 0;
int cursorButtonIndentX = 5;
int cursorIncrementY = 25;
public Panel panel = new Panel();
// "Name of DLL where UserControls are found. (eg - "AccountingControls.dll")"
string assemblyName;
Assembly assembly;
///
///
///
/// Text used in TabControl
/// Name of DLL where UserControls are found. (eg - "AccountingControls.dll")
/// Root Namespace for all UserControls
public UCAD_Tab(XmlNode tabNode)
{
// Suspend this tabs control-layout logic
this.SuspendLayout();
// "Text used in TabControl"
this.Text = tabNode.Attributes["tabText"].Value;
this.ForeColor = UCAD_Settings.defaultForeColor;
this.BackColor = UCAD_Settings.defaultBackColor;
// "Load the assembly associated with this tab. (eg - "AccountingControls.dll")"
assemblyName = tabNode.Attributes["assemblyName"].Value;
string path = GetSolutionDirectory() + assemblyName;
assembly = Assembly.LoadFile(path);
// Set up an embedded panel in the tab
// Nicer effect
panel.SuspendLayout();
panel.Name = "panel_" + tabNode.Attributes["tabText"].Value;
panel.BackColor = UCAD_Settings.defaultBackColor;
panel.TabIndex = UCAD_Tab.UCAD_TabIndex++;
panel.Dock = System.Windows.Forms.DockStyle.Fill;
panel.Location = UCAD_Settings.tabLocation;
panel.Size = UCAD_Settings.tabSize;
#region Labels and Buttons
foreach (XmlNode itemNode in tabNode.ChildNodes)
{
if (itemNode.Name == "Label")
{
// Move cursor to next empty spot
cursorPositionY += cursorIncrementY + cursorIncrementY;
// Create a sub-catagory label
Label label = CreateLabel(itemNode,
new Point(cursorPositionX, cursorPositionY));
// Add Button to the panel
panel.Controls.Add(label);
}
if (itemNode.Name == "Button")
{
// Move cursor to next empty spot
cursorPositionY += cursorIncrementY;
// Create Button
UCAD_Button button = new UCAD_Button(
itemNode,
new Point(cursorPositionX + cursorButtonIndentX, cursorPositionY),
assembly);
// Add Button to the panel
panel.Controls.Add(button);
}
}
#endregion
panel.ResumeLayout(false);
panel.PerformLayout();
this.Controls.Add(panel);
this.ResumeLayout(false);
}
private Label CreateLabel(XmlNode labelNode, Point location)
{
Label label = new Label();
// "Text applied as a header to button groups"
label.Text = labelNode.Attributes["labelText"].Value;
label.AutoSize = true;
label.Font = new System.Drawing.Font("Verdana", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label.ForeColor = System.Drawing.Color.DarkSlateGray;
label.Location = location;
label.Name = "label4";
label.Size = new System.Drawing.Size(121, 18);
label.TabIndex = 6;
return label;
}
///
/// Gets the Solution directory containing UserControl Dlls.
///
///
public static String GetSolutionDirectory()
{
string curDir = Directory.GetCurrentDirectory();
DirectoryInfo parentDir = Directory.GetParent(curDir);
//String workDir = curDir.Substring(0, curDir.IndexOf("SmallBusinessEngine\\bin\\Debug"));
return parentDir.FullName + "\\";
}
///
/// Deactivate this Tabs buttons and reset to defaults.
///
public void ResetButtonDefaults()
{
for (int i = 0; i < this.panel.Controls.Count; i++)
{
if (this.panel.Controls[i] is Button)
{
this.panel.Controls[i].BackColor = UCAD_Settings.defaultBackColor;
this.panel.Controls[i].ForeColor = UCAD_Settings.defaultForeColor;
}
}
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
}
}