using System;
using System.Net;
using System.Web.Mail;
public class MailTest
{
public static void Main()
{
string from = "from@from.net";
string to = "to@to.net";
string subject = "This is a test mail message";
string body = "Hi .";
SmtpMail.SmtpServer = "192.168.1.150";
SmtpMail.Send(from, to, subject, body);
}
}
Sunday, 13 March 2011
Simple Email csharp program
Code of Mouse button Event
using System;
using System.Windows.Forms;
using System.Drawing;
public class MainWindow : Form {
public MainWindow() {
Height = 300;
Width = 500;
this.MouseMove += new MouseEventHandler(MainForm_MouseMove);
this.MouseUp += new MouseEventHandler(MainForm_MouseUp);
this.KeyUp += new KeyEventHandler(MainForm_KeyUp);
}
protected void MainForm_MouseMove(object sender, MouseEventArgs e) {
this.Text = string.Format("Current Pos: ({0}, {1})", e.X, e.Y);
}
protected void MainForm_MouseUp(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left)
MessageBox.Show("Left click!");
if (e.Button == MouseButtons.Right)
MessageBox.Show("Right click!");
if (e.Button == MouseButtons.Middle)
MessageBox.Show("Middle click!");
}
protected void MainForm_KeyUp(object sender, KeyEventArgs e) {
MessageBox.Show(e.KeyCode.ToString(), "Key Pressed!");
}
public static void Main(string[] args) {
Application.Run(new MainWindow());
}
}
Saturday, 12 March 2011
Data Grid with Fill
using System;
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class Form1 : System.Windows.Forms.Form {
internal System.Windows.Forms.DataGrid DataGrid1;
internal System.Windows.Forms.Button btnRunQuery;
private System.Windows.Forms.Button btnRunQuery2;
public Form1() {
this.DataGrid1 = new System.Windows.Forms.DataGrid();
this.btnRunQuery = new System.Windows.Forms.Button();
this.btnRunQuery2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.DataGrid1)).BeginInit();
this.SuspendLayout();
this.DataGrid1.DataMember = "";
this.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.DataGrid1.Location = new System.Drawing.Point(8, 8);
this.DataGrid1.Size = new System.Drawing.Size(280, 200);
this.btnRunQuery.Location = new System.Drawing.Point(8, 224);
this.btnRunQuery.Size = new System.Drawing.Size(80, 24);
this.btnRunQuery.Text = "Run Query 1";
this.btnRunQuery.Click += new System.EventHandler(this.btnRunQuery_Click);
this.btnRunQuery2.Location = new System.Drawing.Point(104, 224);
this.btnRunQuery2.Size = new System.Drawing.Size(80, 24);
this.btnRunQuery2.Text = "Run Query 2";
this.btnRunQuery2.Click += new System.EventHandler(this.btnRunQuery2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnRunQuery2,
this.DataGrid1,
this.btnRunQuery});
((System.ComponentModel.ISupportInitialize)(this.DataGrid1)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void btnRunQuery_Click(object sender, System.EventArgs e) {
try {
SqlConnection cn = new SqlConnection("data source=.;database=biblio;uid=admin;pwd=pw");
SqlDataAdapter da = new SqlDataAdapter("Select top 50 Author, Year_born from Authors Where Year_born is not null", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Authors");
DataGrid1.DataSource = ds.Tables["Authors"];
} catch (SqlException ex) {
Debug.WriteLine(ex.ToString());
}
}
private void btnRunQuery2_Click(object sender, System.EventArgs e) {
try {
SqlConnection cn = new SqlConnection("data source=.;database=biblio;uid=admin;pwd=pw");
SqlDataAdapter da = new SqlDataAdapter("Select Title, Price from Titles where Title like 'Hit%'", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Titles and Price");
DataGrid1.DataSource = ds.Tables["Titles and Price"];
} catch (SqlException ex) {
Debug.WriteLine(ex.ToString());
}
}
}
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class Form1 : System.Windows.Forms.Form {
internal System.Windows.Forms.DataGrid DataGrid1;
internal System.Windows.Forms.Button btnRunQuery;
private System.Windows.Forms.Button btnRunQuery2;
public Form1() {
this.DataGrid1 = new System.Windows.Forms.DataGrid();
this.btnRunQuery = new System.Windows.Forms.Button();
this.btnRunQuery2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.DataGrid1)).BeginInit();
this.SuspendLayout();
this.DataGrid1.DataMember = "";
this.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.DataGrid1.Location = new System.Drawing.Point(8, 8);
this.DataGrid1.Size = new System.Drawing.Size(280, 200);
this.btnRunQuery.Location = new System.Drawing.Point(8, 224);
this.btnRunQuery.Size = new System.Drawing.Size(80, 24);
this.btnRunQuery.Text = "Run Query 1";
this.btnRunQuery.Click += new System.EventHandler(this.btnRunQuery_Click);
this.btnRunQuery2.Location = new System.Drawing.Point(104, 224);
this.btnRunQuery2.Size = new System.Drawing.Size(80, 24);
this.btnRunQuery2.Text = "Run Query 2";
this.btnRunQuery2.Click += new System.EventHandler(this.btnRunQuery2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnRunQuery2,
this.DataGrid1,
this.btnRunQuery});
((System.ComponentModel.ISupportInitialize)(this.DataGrid1)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void btnRunQuery_Click(object sender, System.EventArgs e) {
try {
SqlConnection cn = new SqlConnection("data source=.;database=biblio;uid=admin;pwd=pw");
SqlDataAdapter da = new SqlDataAdapter("Select top 50 Author, Year_born from Authors Where Year_born is not null", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Authors");
DataGrid1.DataSource = ds.Tables["Authors"];
} catch (SqlException ex) {
Debug.WriteLine(ex.ToString());
}
}
private void btnRunQuery2_Click(object sender, System.EventArgs e) {
try {
SqlConnection cn = new SqlConnection("data source=.;database=biblio;uid=admin;pwd=pw");
SqlDataAdapter da = new SqlDataAdapter("Select Title, Price from Titles where Title like 'Hit%'", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Titles and Price");
DataGrid1.DataSource = ds.Tables["Titles and Price"];
} catch (SqlException ex) {
Debug.WriteLine(ex.ToString());
}
}
}
hello world in csharp
using System; public class Hello2 { public static void Main() { Console.WriteLine("Hello, World!"); } }
Subscribe to:
Posts (Atom)