FrmPrincipal: Lista de ventanas (tipo tabs)

This commit is contained in:
2013-11-24 19:04:06 +01:00
parent 3f994390b9
commit b2d7fda236
8 changed files with 168 additions and 28 deletions

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace ServerExplorer.Controls
{
public class WindowButton : Button
{
#region Properties
private Form window = null;
public Form Window
{
get { return window; }
set { window = value; }
}
private bool active = false;
public bool Active
{
get { return active; }
set
{
active = value;
//Font = active ? fntActive : fntNormal;
ForeColor = active ? Color.Black : Color.Gray;
}
}
#endregion
#region Creator
public WindowButton()
{
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
Click += WindowButton_Click;
}
#endregion
#region Events
void WindowButton_Click(object sender, EventArgs e)
{
if (window == null) { return; }
window.Activate();
}
#endregion
}
}

View File

@@ -78,6 +78,9 @@
<Compile Include="Controls\CustomTextBox.cs"> <Compile Include="Controls\CustomTextBox.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Controls\WindowButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UI\FrmBaseDatos.cs"> <Compile Include="UI\FrmBaseDatos.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@@ -69,6 +69,7 @@
this.txtConString.ReadOnly = true; this.txtConString.ReadOnly = true;
this.txtConString.Size = new System.Drawing.Size(616, 20); this.txtConString.Size = new System.Drawing.Size(616, 20);
this.txtConString.TabIndex = 0; this.txtConString.TabIndex = 0;
this.txtConString.TabWidth = 8;
// //
// lblConString // lblConString
// //
@@ -137,7 +138,7 @@
// btnGenerar // btnGenerar
// //
this.btnGenerar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnGenerar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnGenerar.Location = new System.Drawing.Point(401, 485); this.btnGenerar.Location = new System.Drawing.Point(392, 485);
this.btnGenerar.Name = "btnGenerar"; this.btnGenerar.Name = "btnGenerar";
this.btnGenerar.Size = new System.Drawing.Size(75, 23); this.btnGenerar.Size = new System.Drawing.Size(75, 23);
this.btnGenerar.TabIndex = 10; this.btnGenerar.TabIndex = 10;
@@ -165,7 +166,7 @@
this.lblTituloTabla.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.lblTituloTabla.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.lblTituloTabla.Location = new System.Drawing.Point(3, 0); this.lblTituloTabla.Location = new System.Drawing.Point(3, 0);
this.lblTituloTabla.Name = "lblTituloTabla"; this.lblTituloTabla.Name = "lblTituloTabla";
this.lblTituloTabla.Size = new System.Drawing.Size(473, 37); this.lblTituloTabla.Size = new System.Drawing.Size(464, 37);
this.lblTituloTabla.TabIndex = 12; this.lblTituloTabla.TabIndex = 12;
this.lblTituloTabla.Text = "lblTituloTabla"; this.lblTituloTabla.Text = "lblTituloTabla";
this.lblTituloTabla.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblTituloTabla.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -179,7 +180,7 @@
this.lblTituloDB.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.lblTituloDB.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.lblTituloDB.Location = new System.Drawing.Point(3, 0); this.lblTituloDB.Location = new System.Drawing.Point(3, 0);
this.lblTituloDB.Name = "lblTituloDB"; this.lblTituloDB.Name = "lblTituloDB";
this.lblTituloDB.Size = new System.Drawing.Size(317, 37); this.lblTituloDB.Size = new System.Drawing.Size(326, 37);
this.lblTituloDB.TabIndex = 13; this.lblTituloDB.TabIndex = 13;
this.lblTituloDB.Text = "lblTituloDB"; this.lblTituloDB.Text = "lblTituloDB";
this.lblTituloDB.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblTituloDB.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -187,7 +188,7 @@
// btnDocGen // btnDocGen
// //
this.btnDocGen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnDocGen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnDocGen.Location = new System.Drawing.Point(320, 485); this.btnDocGen.Location = new System.Drawing.Point(311, 485);
this.btnDocGen.Name = "btnDocGen"; this.btnDocGen.Name = "btnDocGen";
this.btnDocGen.Size = new System.Drawing.Size(75, 23); this.btnDocGen.Size = new System.Drawing.Size(75, 23);
this.btnDocGen.TabIndex = 14; this.btnDocGen.TabIndex = 14;
@@ -243,7 +244,7 @@
this.splitContainer1.Panel2.Controls.Add(this.btnProcs); this.splitContainer1.Panel2.Controls.Add(this.btnProcs);
this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos); this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos);
this.splitContainer1.Size = new System.Drawing.Size(806, 511); this.splitContainer1.Size = new System.Drawing.Size(806, 511);
this.splitContainer1.SplitterDistance = 323; this.splitContainer1.SplitterDistance = 332;
this.splitContainer1.TabIndex = 17; this.splitContainer1.TabIndex = 17;
// //
// lsvTablas // lsvTablas
@@ -260,7 +261,7 @@
this.lsvTablas.FullRowSelect = true; this.lsvTablas.FullRowSelect = true;
this.lsvTablas.Location = new System.Drawing.Point(3, 40); this.lsvTablas.Location = new System.Drawing.Point(3, 40);
this.lsvTablas.Name = "lsvTablas"; this.lsvTablas.Name = "lsvTablas";
this.lsvTablas.Size = new System.Drawing.Size(317, 468); this.lsvTablas.Size = new System.Drawing.Size(326, 468);
this.lsvTablas.Sorting = System.Windows.Forms.SortOrder.Ascending; this.lsvTablas.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.lsvTablas.TabIndex = 4; this.lsvTablas.TabIndex = 4;
this.lsvTablas.UseCompatibleStateImageBehavior = false; this.lsvTablas.UseCompatibleStateImageBehavior = false;
@@ -296,7 +297,7 @@
this.lsvColumnas.FullRowSelect = true; this.lsvColumnas.FullRowSelect = true;
this.lsvColumnas.Location = new System.Drawing.Point(3, 40); this.lsvColumnas.Location = new System.Drawing.Point(3, 40);
this.lsvColumnas.Name = "lsvColumnas"; this.lsvColumnas.Name = "lsvColumnas";
this.lsvColumnas.Size = new System.Drawing.Size(473, 439); this.lsvColumnas.Size = new System.Drawing.Size(464, 439);
this.lsvColumnas.TabIndex = 6; this.lsvColumnas.TabIndex = 6;
this.lsvColumnas.UseCompatibleStateImageBehavior = false; this.lsvColumnas.UseCompatibleStateImageBehavior = false;
this.lsvColumnas.View = System.Windows.Forms.View.Details; this.lsvColumnas.View = System.Windows.Forms.View.Details;

View File

@@ -232,8 +232,7 @@ namespace ServerExplorer.UI
// Crear y mostrar el formulario de los datos. // Crear y mostrar el formulario de los datos.
FrmDatos form = new FrmDatos(dt, nombreTabla); FrmDatos form = new FrmDatos(dt, nombreTabla);
form.MdiParent = this.MdiParent; FrmPrincipal.AddForm(form);
form.Show();
} }
@@ -254,21 +253,18 @@ namespace ServerExplorer.UI
// Crear y mostrar el formulario de los datos. // Crear y mostrar el formulario de los datos.
frmDatos form = new frmDatos(dt, "Procedimientos"); frmDatos form = new frmDatos(dt, "Procedimientos");
form.MdiParent = this.MdiParent; FrmPrincipal.AddForm(form);*/
form.Show();*/
// Crear y mostrar el formulario de los procedimientos. // Crear y mostrar el formulario de los procedimientos.
FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString); FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString);
form.MdiParent = this.MdiParent; FrmPrincipal.AddForm(form);
form.Show();
} }
private void btnExec_Click(object sender, EventArgs e) private void btnExec_Click(object sender, EventArgs e)
{ {
// Crear y mostrar el formulario de exec. // Crear y mostrar el formulario de exec.
FrmExec form = new FrmExec(config.ConnectionString); FrmExec form = new FrmExec(config.ConnectionString);
form.MdiParent = this.MdiParent; FrmPrincipal.AddForm(form);
form.Show();
} }

View File

@@ -34,6 +34,7 @@
this.menuBaseDatos = new System.Windows.Forms.ToolStripMenuItem(); this.menuBaseDatos = new System.Windows.Forms.ToolStripMenuItem();
this.menuConectarA = new System.Windows.Forms.ToolStripMenuItem(); this.menuConectarA = new System.Windows.Forms.ToolStripMenuItem();
this.menuConectarPRUEBAS = new System.Windows.Forms.ToolStripMenuItem(); this.menuConectarPRUEBAS = new System.Windows.Forms.ToolStripMenuItem();
this.flowpnlWindows = new System.Windows.Forms.FlowLayoutPanel();
this.menuPrincipal.SuspendLayout(); this.menuPrincipal.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -86,16 +87,29 @@
this.menuConectarPRUEBAS.Text = "Conectar a PRUEBAS"; this.menuConectarPRUEBAS.Text = "Conectar a PRUEBAS";
this.menuConectarPRUEBAS.Click += new System.EventHandler(this.menuConectarPRUEBAS_Click); this.menuConectarPRUEBAS.Click += new System.EventHandler(this.menuConectarPRUEBAS_Click);
// //
// frmPrincipal // flowpnlWindows
//
this.flowpnlWindows.AutoSize = true;
this.flowpnlWindows.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.flowpnlWindows.Dock = System.Windows.Forms.DockStyle.Top;
this.flowpnlWindows.Location = new System.Drawing.Point(0, 24);
this.flowpnlWindows.Name = "flowpnlWindows";
this.flowpnlWindows.Size = new System.Drawing.Size(800, 0);
this.flowpnlWindows.TabIndex = 6;
//
// FrmPrincipal
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 601); this.ClientSize = new System.Drawing.Size(800, 601);
this.Controls.Add(this.flowpnlWindows);
this.Controls.Add(this.menuPrincipal); this.Controls.Add(this.menuPrincipal);
this.IsMdiContainer = true; this.IsMdiContainer = true;
this.MainMenuStrip = this.menuPrincipal; this.MainMenuStrip = this.menuPrincipal;
this.Name = "frmPrincipal"; this.Name = "FrmPrincipal";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Explorador de Servidores"; this.Text = "Explorador de Servidores";
this.MdiChildActivate += new System.EventHandler(this.FrmPrincipal_MdiChildActivate);
this.menuPrincipal.ResumeLayout(false); this.menuPrincipal.ResumeLayout(false);
this.menuPrincipal.PerformLayout(); this.menuPrincipal.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
@@ -111,5 +125,6 @@
private System.Windows.Forms.ToolStripMenuItem menuBaseDatos; private System.Windows.Forms.ToolStripMenuItem menuBaseDatos;
private System.Windows.Forms.ToolStripMenuItem menuConectarA; private System.Windows.Forms.ToolStripMenuItem menuConectarA;
private System.Windows.Forms.ToolStripMenuItem menuConectarPRUEBAS; private System.Windows.Forms.ToolStripMenuItem menuConectarPRUEBAS;
private System.Windows.Forms.FlowLayoutPanel flowpnlWindows;
} }
} }

View File

@@ -7,33 +7,100 @@ using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using ServerExplorer.Code; using ServerExplorer.Code;
using ServerExplorer.Controls;
namespace ServerExplorer.UI namespace ServerExplorer.UI
{ {
public partial class FrmPrincipal : Form public partial class FrmPrincipal : Form
{ {
#region Declarations
private static FrmPrincipal currentInstance;
#endregion
#region Creator
public FrmPrincipal() public FrmPrincipal()
{ {
currentInstance = this;
InitializeComponent(); InitializeComponent();
} }
#endregion
#region WindowList
private List<Form> listChilds = new List<Form>();
public static void AddForm(Form frm)
{
frm.MdiParent = currentInstance;
frm.WindowState = FormWindowState.Maximized;
frm.Show();
currentInstance.listChilds.Add(frm);
frm.FormClosed += currentInstance.FrmPrincipal_OnChildClose;
currentInstance.RefreshWindowButtons();
}
protected void FrmPrincipal_OnChildClose(object sender, FormClosedEventArgs e)
{
listChilds.Remove((Form)sender);
RefreshWindowButtons();
}
private void FrmPrincipal_MdiChildActivate(object sender, EventArgs e)
{
RefreshWindowButtons();
}
private void RefreshWindowButtons()
{
int childCount = listChilds.Count;
int delta = childCount - flowpnlWindows.Controls.Count;
if (delta < 0)
{
int dest = flowpnlWindows.Controls.Count + delta;
for (int i = flowpnlWindows.Controls.Count - 1; i >= dest; i--)
{
flowpnlWindows.Controls.RemoveAt(i);
}
}
else if (delta > 0)
{
for (int i = 0; i < delta; i++)
{
flowpnlWindows.Controls.Add(new WindowButton());
}
}
for (int i = 0; i < childCount; i++)
{
WindowButton btn = (WindowButton)flowpnlWindows.Controls[i];
Form frm = listChilds[i];
btn.Text = frm.Text;
btn.Window = frm;
btn.Active = (frm == ActiveMdiChild);
}
}
#endregion
#region Menus
private void menuConectarPRUEBAS_Click(object sender, EventArgs e) private void menuConectarPRUEBAS_Click(object sender, EventArgs e)
{ {
// Crear ventana de la base de datos de pruebas // Crear ventana de la base de datos de pruebas
FrmBaseDatos frm = new FrmBaseDatos("Data Source=SSSRV3;Initial Catalog=PRUEBAS;User ID=sa;Password=SLsssrv3"); FrmBaseDatos frm = new FrmBaseDatos("Data Source=SSSRV3;Initial Catalog=PRUEBAS;User ID=sa;Password=SLsssrv3");
//frmBaseDatos frm = new frmBaseDatos("Data Source=DANTE;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True"); //frmBaseDatos frm = new frmBaseDatos("Data Source=DANTE;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
//frmBaseDatos frm = new frmBaseDatos("Data Source=OSKURITO;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True"); //frmBaseDatos frm = new frmBaseDatos("Data Source=OSKURITO;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
frm.MdiParent = this; FrmPrincipal.AddForm(frm);
frm.WindowState = FormWindowState.Maximized;
frm.Show();
} }
private void menuBuscarServidor_Click(object sender, EventArgs e) private void menuBuscarServidor_Click(object sender, EventArgs e)
{ {
// Mostrar ventana de buscador de servidores // Mostrar ventana de buscador de servidores
FrmServidores frm = new FrmServidores(); FrmServidores frm = new FrmServidores();
frm.MdiParent = this; FrmPrincipal.AddForm(frm);
frm.Show();
} }
private void menuConectarA_Click(object sender, EventArgs e) private void menuConectarA_Click(object sender, EventArgs e)
@@ -46,10 +113,10 @@ namespace ServerExplorer.UI
// Crear y mostrar ventana // Crear y mostrar ventana
FrmBaseDatos frm = new FrmBaseDatos(config); FrmBaseDatos frm = new FrmBaseDatos(config);
frm.MdiParent = this; FrmPrincipal.AddForm(frm);
frm.WindowState = FormWindowState.Maximized;
frm.Show();
} }
} }
#endregion
} }
} }

View File

@@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuPrincipal.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="menuPrincipal.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>14, 6</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>32</value>
</metadata> </metadata>
</root> </root>

View File

@@ -127,8 +127,7 @@ namespace ServerExplorer.UI
// Llamar a la venta de la base de datos // Llamar a la venta de la base de datos
FrmBaseDatos frm = new FrmBaseDatos(constructor.ConnectionString); FrmBaseDatos frm = new FrmBaseDatos(constructor.ConnectionString);
frm.MdiParent = this.MdiParent; FrmPrincipal.AddForm(frm);
frm.Show();
} }
} }
} }