Pages

C SHARP & V.B - How to Pass values to another Form

How to Pass values to another Form

Ok. Lets say you have 2 Forms. Form1 and Form2.

In Visual Basic 6 this is simple codes with 1 line only: Form2.text1.text = Form1.text1.text
Thats so Simple.
But in C# not 1 line code. I have 2 ways to get a text from Form1/Form2.

FIRST WAY:
1.) Goto Form1 then Double Click it. At the code type this.

public string CaptionText
{get {return textBox1.Text;}
set { textBox1.Text = value; }}
note: the value of your textbox1.text = sayre;
2.) Goto Form2 then Double click it. At the code type this.
// At your command button In Form2
private void button1_Click(object sender, EventArgs e)
{
Form1 sForm1 = new Form1();
textBox1.Text = sForm1.CaptionText;

}

SECOND WAY:

1.) Goto Form2 then Double click it. At the code type this.

public Form2(string sTEXT)
{
InitializeComponent();
textBox1.Text = sTEXT;
}
2.) Goto Form1 then Double click it. At the code type this.
//At your command button in Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 sForm = new Form2(textBox1.Text);
sForm.Show();
}

c sharp - How to Get Date and Time Difference in C SHARP

I have example here on how to get the difference of date and time in C#.
Step: 1
Create a timer then set the interval to 10 and enabled to true.
Step: 2
Create 3 Label. Label1,Label2,Label3.
Step: 3
Create 2 Datepicker. Name it dtfrom and dtto.
Step: 4
Create a Button1
Then Copy this Code at your form:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{label1.Text = dtfrom.Value.ToString();}
private void timer1_Tick(object sender, EventArgs e)
{label2.Text = string.Format("{0:G}", DateTime.Now);}
private void button1_Click(object sender, EventArgs e)
{
TimeSpan ts = new TimeSpan();
DateTime dt1,dt2 = new DateTime();
dt1 = dtfrom.Value;
dt2 = Convert.ToDateTime(label2.Text);
ts=dt1.Subtract(dt2);
label3.Text = ts.ToString(); //Answer
}

Share/Bookmark


                                                  WITH MY BEST: MOHAMED BASHA

C SHARP-Showing newest posts with label Progress Bar


In this code show you on how to use the progress bar with Insert command.

First Step:
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "your connectionstring";
conn.Open();
int i;
int x = 1000; //insert 1000 rows
Bar.Maximum = x; //Bar ( Your progressbar)
for (i = 0; i < x; i++)
{
string sQL = "Insert Into table1" & _ "(empid,dates,username) values ('COLLADO','11/4/1982','Sayre')";
OleDbCommand cmd = new OleDbCommand(sQL, conn);
cmd.ExecuteNonQuery();
Bar.Value = Bar.Value + 1;
pr = Bar.Value;
pr1 = pr / x;
pr2 = pr1 * 100;
lblpercent.Text = pr2.ToString(); //show the percent in label
Application.DoEvents();
}
//Get the total row in the table
string sQL1 = "select * from table1";
OleDbCommand cmd1 = new OleDbCommand(sQL1, conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
da.Fill(ds);
string ss = ds.Tables[0].Rows.Count.ToString();

                    WITM MY BEST: MOHAMED BASHA

sortable table


Directions: Simply download "sortabletable.zip",
 and refer to the html page inside.

Insert the following code in the HEAD section of your page:

<script type="text/javascript" src="sortable.js"></script>


Then, for the table you wish the sort, insert a "class" and "id" attribute inside its <table> tag:


java - image clock

Step 1: Insert the below into the <HEAD> section of your page
Step 2: Then, to display the clock, call this function where you wish the clock to be shown:
Step 3: But wait, don't forget the images! Download the image pack below and upload the images inside to
the same directory as your webpage:
 

Link With in

Related Posts Plugin for WordPress, Blogger...