Bart

Bart

  • NA
  • 1
  • 0

Problem with custom control c#

Jul 25 2006 5:41 AM
Hi, i'm new of this forum.
On my project i've create this class:

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

using torreEventi.Tag;

namespace torreEventi.PannelloControllo

{

/// <summary>

/// Summary description for GestioneEvento.

/// </summary>

public class GestioneEvento : System.Windows.Forms.UserControl

{

private torreEventi.Tag.textData txtData;

private System.Windows.Forms.ErrorProvider errGestioneEvento;

private System.Windows.Forms.GroupBox grpEvento;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label lblData;

private System.Windows.Forms.Panel pnlEvento;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public GestioneEvento()

{

// This call is required by the Windows.Forms Form Designer.

InitializeComponent();

// TODO: Add any initialization after the InitializeComponent call

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Component Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.txtData = new torreEventi.Tag.textData();

this.errGestioneEvento = new System.Windows.Forms.ErrorProvider();

this.grpEvento = new System.Windows.Forms.GroupBox();

this.label2 = new System.Windows.Forms.Label();

this.lblData = new System.Windows.Forms.Label();

this.pnlEvento = new System.Windows.Forms.Panel();

this.grpEvento.SuspendLayout();

this.pnlEvento.SuspendLayout();

this.SuspendLayout();

//

// txtData

//

this.txtData.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

this.txtData.Location = new System.Drawing.Point(130, 37);

this.txtData.Name = "txtData";

this.txtData.TabIndex = 1;

this.txtData.Text = "";

//

// errGestioneEvento

//

this.errGestioneEvento.ContainerControl = this;

//

// grpEvento

//

this.grpEvento.Controls.Add(this.label2);

this.grpEvento.Controls.Add(this.lblData);

this.grpEvento.Cursor = System.Windows.Forms.Cursors.Arrow;

this.grpEvento.Dock = System.Windows.Forms.DockStyle.Fill;

this.grpEvento.FlatStyle = System.Windows.Forms.FlatStyle.System;

this.grpEvento.Location = new System.Drawing.Point(0, 0);

this.grpEvento.Name = "grpEvento";

this.grpEvento.Size = new System.Drawing.Size(710, 240);

this.grpEvento.TabIndex = 4;

this.grpEvento.TabStop = false;

this.grpEvento.Text = " Gestione Evento ";

//

// label2

//

this.label2.Cursor = System.Windows.Forms.Cursors.Default;

this.label2.Location = new System.Drawing.Point(16, 80);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(80, 15);

this.label2.TabIndex = 1;

this.label2.Text = "Descrizione :";

//

// lblData

//

this.lblData.Cursor = System.Windows.Forms.Cursors.Default;

this.lblData.Location = new System.Drawing.Point(16, 37);

this.lblData.Name = "lblData";

this.lblData.Size = new System.Drawing.Size(112, 15);

this.lblData.TabIndex = 0;

this.lblData.Text = "Data (gg/mm/yyyy) : ";

//

// pnlEvento

//

this.pnlEvento.BackColor = System.Drawing.SystemColors.Control;

this.pnlEvento.Controls.Add(this.grpEvento);

this.pnlEvento.Cursor = System.Windows.Forms.Cursors.Hand;

this.pnlEvento.Dock = System.Windows.Forms.DockStyle.Fill;

this.pnlEvento.Location = new System.Drawing.Point(0, 0);

this.pnlEvento.Name = "pnlEvento";

this.pnlEvento.Size = new System.Drawing.Size(710, 240);

this.pnlEvento.TabIndex = 3;

//

// GestioneEvento

//

this.Controls.Add(this.pnlEvento);

this.Name = "GestioneEvento";

this.Size = new System.Drawing.Size(710, 240);

this.grpEvento.ResumeLayout(false);

this.pnlEvento.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

public Boolean validaGestione1()

{

return true;

}

}

}


and this user control(tag):

using System;

using System.Data;

using System.Collections;

using System.Windows.Forms;

namespace torreEventi.Tag

{

/// <summary>

/// Summary description for textData.

/// </summary>

public class textData: System.Windows.Forms.TextBox

{

private System.Windows.Forms.ErrorProvider errtextData;

#region costruttore

public textData()

{

errtextData = new ErrorProvider();

calendario = new ArrayList();

for(int i = 1;i<=12; i++)

{

MeseItem meseItem = new MeseItem(i);

calendario.Add(meseItem);

}

}

#endregion

#region Proprietà

private ArrayList calendario;

public ArrayList Calendario

{

get{return calendario;}

}

private Boolean dataCorretta;

public Boolean DataCorretta

{

get{ return dataCorretta;}

}

#endregion

protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)

{

base.OnKeyPress (e);

//controllo per caratteri non numerici

if ((((Keys)e.KeyChar) < Keys.D0 || ((Keys)e.KeyChar) > Keys.D9) && (((Keys)e.KeyChar) != Keys.Back && ((Keys)e.KeyChar) != Keys.Tab && ((Keys)e.KeyChar) != Keys.Enter && e.KeyChar != 47 ))

{

e.Handled = true;//annulo la digitazione effettuata

}

}

protected override void OnLostFocus(EventArgs e)

{

base.OnLostFocus (e);

string dtT = string.Empty;

if (this.Text.Length < 10)

{

try

{

dtT = this.Text.Substring(0,2) + "/" + this.Text.Substring(2,2) + "/" + this.Text.Substring(4,4);

}

catch

{

dtT = this.Text;

}

}

else

{

dtT = this.Text;

}

dataCorretta = checkData(dtT);

this.Text = dtT;

}

protected override void OnGotFocus(EventArgs e)

{

base.OnGotFocus (e);

this.errtextData.Dispose();

}

/// <summary>

/// Controllo formale sulla validità della data

/// </summary>

/// <param name="dt"></param>

/// <returns></returns>

public Boolean checkData(string dt)

{

if (dt.ToString().Length == 10)

{

MeseItem meseI;

string[] sArray = dt.Split(new char[]{'/'});

//controllo che il mese esistente

if ((int.Parse(sArray[1])) < 1 || (int.Parse(sArray[1])) > 12)

{

this.errtextData.SetError(this,"Mese " + (int.Parse(sArray[1])) + " errato.");

return false;

}

else

{

//recupero il numero dei giorni previsto per il mese indicato

meseI = (MeseItem)Calendario[int.Parse(sArray[1]) - 1];

if (int.Parse(sArray[0]) < meseI.Giorni || int.Parse(sArray[0]) > meseI.Giorni)

{

this.errtextData.SetError(this,"Il numero dei giorni indicato non rientra nel range previsto.");

return false;

}

}

//tutti i controlli sono stati superati

return true;

}

else

{

this.errtextData.SetError(this,"Data formalmente errata.");

return false;

}

}

}

public class MeseItem

{

#region Costruttori

public MeseItem(int mm)

{

int yy = DateTime.Now.Year;

switch (mm)

{

case 1:

mese = "gennaio";

giorni = 31;

break;

case 2:

mese = "febbraio";

double result = yy /4;

if (result != 0)

{

giorni = 29;

}

giorni = 28;

break;

case 3:

mese = "marzo";

giorni = 31;

break;

case 4:

mese = "aprile";

giorni = 30;

break;

case 5:

mese = "maggio";

giorni = 31;

break;

case 6:

mese = "giugno";

giorni = 30;

break;

case 7:

mese = "luglio";

giorni = 31;

break;

case 8:

mese = "agosto";

giorni = 31;

break;

case 9:

mese = "settembre";

giorni = 30;

break;

case 10:

mese = "ottobre";

giorni = 31;

break;

case 11:

mese = "novembre";

giorni = 30;

break;

case 12:

mese = "dicembre";

giorni = 31;

break;

}

}

#endregion

#region Proprietà

private string mese;

public string Mese

{

get {return mese;}

}

private int giorni;

public int Giorni

{

get {return giorni;}

}

#endregion

}

}

the problem is that when i see the rendering of my user control, this is not visible.
If i run my application the problem is the same, my user control is not visible.



Can you help me?