help... boxing.. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help... boxing..

saridemirsaridemir Posts: 6Member
hi,
I have a problem about boxing..
((TextBox) textbox1).text;
"TextBox": how can I use variable instead of static expresion...
thanks...

Comments

  • dingseadingsea Posts: 6Member
  • BrutesBrutes Posts: 162Member
    Hi

    I am not sure why u want to do this or what it is you trying to do.
    Please be more clear.
  • saridemirsaridemir Posts: 6Member
    I try to make a standart form which takes parameters via ArrayList or an XML file.. I am currently use getType and a case statements like case typeof(TextBox) ....
    case typeof(richTextBox)....
    like this.. but this is not very good technique actualy I need templates (like c++) however in c# I dont know how the templates works... so I need to use this trick...

  • BrutesBrutes Posts: 162Member
    I think you need to send me the code.
    I am still not sure what you doing.

    Brian.
  • saridemirsaridemir Posts: 6Member
    I send the CLsFrmFill.cs file below.... the problem is when I try to support new type (Look at the if statements in the setup function ..) I open the code and add new if statement... (but my previous c++ experience I can do it using templates... so I suspect that my current strategy may be wrong...) how can I do better way...






    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;

    namespace Veresiye_1._6
    {
    ///
    /// Summary description for ClsFrmFill.
    ///
    public class ClsFrmFill : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label lblTitle;
    private ClsHashList sqlField;
    private ClsHashList fieldRow;
    private string sql;
    private int descWidth;
    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.Button btnSave;
    private System.Windows.Forms.Button btnCancel;


    ///
    /// Required designer variable.
    ///
    private System.ComponentModel.Container components = null;

    public ClsFrmFill(string _sql,ClsHashList _sqlField,int _descWidth)
    {
    sql=_sql;
    sqlField=_sqlField;
    descWidth=_descWidth;
    InitializeComponent();

    }
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///
    private void InitializeComponent()
    {
    this.lblTitle = new System.Windows.Forms.Label();
    this.groupBox = new System.Windows.Forms.GroupBox();
    this.btnSave = new System.Windows.Forms.Button();
    this.btnCancel = new System.Windows.Forms.Button();
    this.SuspendLayout();
    //
    // lblTitle
    //
    this.lblTitle.Location = new System.Drawing.Point(0, 0);
    this.lblTitle.Name = "lblTitle";
    this.lblTitle.Size = new System.Drawing.Size(448, 40);
    this.lblTitle.TabIndex = 0;
    //
    // groupBox
    //
    this.groupBox.Location = new System.Drawing.Point(16, 56);
    this.groupBox.Name = "groupBox";
    this.groupBox.Size = new System.Drawing.Size(416, 336);
    this.groupBox.TabIndex = 1;
    this.groupBox.TabStop = false;
    this.SetUp();
    //
    // ClsFrmFill
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(448,this.btnSave.Location.Y+80);
    this.Controls.Add(this.groupBox);
    this.Controls.Add(this.lblTitle);
    this.Name = "ClsFrmFill";
    this.Text = "ClsFrmFill";
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
    this.btnCancel.Click +=new EventHandler(btnCancel_Click);

    this.ResumeLayout(false);

    }
    #endregion
    #region Setup
    public void SetUp()
    {
    this.SuspendLayout();
    this.fieldRow = new ClsHashList();
    int total=20;
    const int space=5;
    for(int i=1;i<this.sqlField.Count;i++)
    {
    /******************************************************************************/
    ClsFieldRow tmp= new ClsFieldRow(this.descWidth);
    tmp.Location = new System.Drawing.Point(this.groupBox.Location.X+10,this.groupBox.Location.Y+total+10);
    tmp.IsRequire = ((ClsSqlField)this.sqlField[i]).IsRequire;
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(string))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new System.Windows.Forms.TextBox();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(tmp.Size.Width-tmp.DescriptionWidth-40,20);
    tmp.Description.Text = ((ClsSqlField)this.sqlField[i]).Description;

    total+=20+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(System.Windows.Forms.TextBox))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new System.Windows.Forms.TextBox();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(tmp.Size.Width-tmp.DescriptionWidth-40,20);
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(System.Windows.Forms.TextBox);
    total+=20+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(ClsTelephone))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new ClsTelephone();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(80,20);
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(ClsTelephone);
    total+=20+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(ClsTaxID))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new ClsTaxID();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(tmp.Size.Width-tmp.DescriptionWidth-40,20);
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(ClsTaxID);
    total+=20+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(ClsSSKID))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new ClsSSKID();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(tmp.Size.Width-tmp.DescriptionWidth-40,20);
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(ClsSSKID);
    total+=20+space;
    }


    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(ClsComboBox))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,20);
    tmp.Data = new ClsComboBox(((ClsSqlField)this.sqlField[i]).RelatedSql,((ClsSqlField)this.sqlField[i]).RelatedDescription,((ClsSqlField)this.sqlField[i]).RelatedField);
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Description.Text = ((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(ClsComboBox);
    total+=20+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(System.Windows.Forms.MonthCalendar))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,155);
    tmp.Data = new System.Windows.Forms.MonthCalendar();
    tmp.Data.Size = new Size(155,tmp.Size.Height);
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(System.Windows.Forms.MonthCalendar);
    total+=155+space;
    }
    if(((ClsSqlField)this.sqlField[i]).TYPE==typeof(System.Windows.Forms.RichTextBox))
    {
    tmp.Size = new System.Drawing.Size(this.groupBox.Width-20,60);
    tmp.Data = new System.Windows.Forms.RichTextBox();
    tmp.Data.Name = ((ClsSqlField)this.sqlField[i]).SQLField;
    tmp.Data.Size = new Size(tmp.Size.Width-tmp.DescriptionWidth-40,60);
    tmp.Description.Text =((ClsSqlField)this.sqlField[i]).Description;
    tmp.TYPE = typeof(System.Windows.Forms.RichTextBox);
    total+=60+space;
    }
    /******************************************************************************/
    tmp.TabIndex = i;
    this.Controls.Add(tmp);
    fieldRow.Add(tmp.Data.Name,tmp);
    }
    this.groupBox.Size = new Size(this.groupBox.Width,total+20);
    //
    // ButtonSave
    //
    this.btnSave.Location = new System.Drawing.Point(this.groupBox.Location.X+descWidth+10, this.groupBox.Location.Y+this.groupBox.Size.Height+20);
    this.btnSave.Name = "btnSave";
    this.btnSave.Size = new System.Drawing.Size(80,24);
    this.btnSave.TabIndex = 0;
    this.btnSave.Text = "Kaydet";
    this.Controls.Add(btnSave);
    //
    // ButtonCancel
    //
    this.btnCancel.Location = new System.Drawing.Point(this.groupBox.Location.X+descWidth+100, this.groupBox.Location.Y+this.groupBox.Size.Height+20);
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.Size = new System.Drawing.Size(80,24);
    this.btnCancel.TabIndex = 0;
    this.btnCancel.Text = "Vazge";
    this.Controls.Add(btnCancel);
    this.ResumeLayout(false);

    }
    public ClsHashList FieldRow
    {
    get{return this.fieldRow;}set{this.fieldRow=value;}
    }
    #endregion
    protected bool CheckFiled()
    {
    for(int i=0;i<fieldRow.Count;i++)
    {
    if(((ClsFieldRow)fieldRow[i]).IsRequire)
    {
    if((((ClsFieldRow)fieldRow[i])).TYPE!=typeof(System.Windows.Forms.MonthCalendar))
    if(((ClsFieldRow)fieldRow[i]).Data.Text.Trim()=="")
    {
    MessageBox.Show(((ClsFieldRow)fieldRow[i]).Description.Text+" alani Eksik");// bura elden gecicek...
    ((ClsFieldRow)fieldRow[i]).Data.Focus();
    return false;
    }
    }

    }
    return true;
    }
    protected void ClearFiled()
    {
    for(int i=0;i<fieldRow.Count;i++)
    {
    if((((ClsFieldRow)fieldRow[i])).TYPE!=typeof(System.Windows.Forms.MonthCalendar))
    {
    if((((ClsFieldRow)fieldRow[i])).TYPE!=typeof(ClsComboBox))
    {
    ((ClsFieldRow)fieldRow[i]).Data.Text="";
    }
    else
    {
    ((ClsComboBox)((ClsFieldRow)fieldRow[i]).Data).SelectedIndex=-1;
    }
    }
    else
    {
    ((System.Windows.Forms.MonthCalendar)((ClsFieldRow)fieldRow[i]).Data).SetDate(DateTime.Now);
    }
    }
    ((ClsFieldRow)fieldRow[0]).Data.Focus();
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
    ClearFiled();
    }
    protected System.Windows.Forms.Button BtnSave
    {
    get{return this.btnSave;}set{this.btnSave=value;}
    }
    protected System.Windows.Forms.Button BtnCancel
    {
    get{return this.btnCancel;}set{this.btnCancel=value;}
    }
    protected ClsHashList SQLField
    {
    get{return this.sqlField;}set{this.sqlField =value;}
    }



    }
    }

Sign In or Register to comment.