Tuesday, August 5, 2014

Passing a Form to a function C# .Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class Class1
    {


        public static void GetForm(Form frm)
        {
            frm.Text = "Satsara";
        }


        public static void SetLabel(Form frm, string lng)
        {
            string ename = "Name";
            string bname = "Nama";
            string name;
            if (lng == "EN")
            {
                name = ename;
            }
            else
                name = bname;

            Control ctn = frm.Controls["lblName"];
            ctn.Text = name;
        }

    }
}

calling the method

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Class1.GetForm(this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1.SetLabel(this, "EN");
        }

        private void button2_Click(object sender, EventArgs e)
        {

            Class1.SetLabel(this, "BA");
        }
    }

No comments:

Post a Comment

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...