Hi!
I would ask everybody who has wrote a C# program and it is quite small in size, to post the program in this thread. I just want to see how the C# program looks like.
THANKS! :)
Printable View
Hi!
I would ask everybody who has wrote a C# program and it is quite small in size, to post the program in this thread. I just want to see how the C# program looks like.
THANKS! :)
This is a very simple mail sending program for windows. POP has not been implemented yet, so some branches might not do anything useful ;)PHP Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace SAEC
{
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RadioButton optName;
private System.Windows.Forms.RadioButton optIPAddress;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.RadioButton optSMTP;
private System.Windows.Forms.RadioButton optPOP3;
private System.Windows.Forms.TextBox txtServerName;
private System.Windows.Forms.TextBox txtFrom;
private System.Windows.Forms.TextBox txtTo;
private System.Windows.Forms.TextBox txtSubject;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtMessage;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtLog;
private System.ComponentModel.Container components = null;
public frmMain()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 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.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtServerName = new System.Windows.Forms.TextBox();
this.optIPAddress = new System.Windows.Forms.RadioButton();
this.optName = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtMessage = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtSubject = new System.Windows.Forms.TextBox();
this.txtTo = new System.Windows.Forms.TextBox();
this.txtFrom = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.txtLog = new System.Windows.Forms.TextBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.optPOP3 = new System.Windows.Forms.RadioButton();
this.optSMTP = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(384, 536);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Send";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtServerName,
this.optIPAddress,
this.optName});
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(320, 96);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server Data";
//
// txtServerName
//
this.txtServerName.Location = new System.Drawing.Point(104, 24);
this.txtServerName.Name = "txtServerName";
this.txtServerName.Size = new System.Drawing.Size(200, 22);
this.txtServerName.TabIndex = 2;
this.txtServerName.Text = "";
//
// optIPAddress
//
this.optIPAddress.Enabled = false;
this.optIPAddress.Location = new System.Drawing.Point(16, 56);
this.optIPAddress.Name = "optIPAddress";
this.optIPAddress.Size = new System.Drawing.Size(80, 24);
this.optIPAddress.TabIndex = 1;
this.optIPAddress.Text = "IP-Address";
//
// optName
//
this.optName.Checked = true;
this.optName.Location = new System.Drawing.Point(16, 24);
this.optName.Name = "optName";
this.optName.Size = new System.Drawing.Size(72, 24);
this.optName.TabIndex = 0;
this.optName.TabStop = true;
this.optName.Text = "Name";
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtMessage,
this.label4,
this.txtSubject,
this.txtTo,
this.txtFrom,
this.label3,
this.label2,
this.label1});
this.groupBox2.Location = new System.Drawing.Point(8, 128);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(464, 296);
this.groupBox2.TabIndex = 6;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "EMail Data";
//
// txtMessage
//
this.txtMessage.Location = new System.Drawing.Point(128, 128);
this.txtMessage.Multiline = true;
this.txtMessage.Name = "txtMessage";
this.txtMessage.Size = new System.Drawing.Size(312, 152);
this.txtMessage.TabIndex = 12;
this.txtMessage.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 128);
this.label4.Name = "label4";
this.label4.TabIndex = 11;
this.label4.Text = "Message:";
//
// txtSubject
//
this.txtSubject.Location = new System.Drawing.Point(128, 88);
this.txtSubject.Name = "txtSubject";
this.txtSubject.Size = new System.Drawing.Size(312, 22);
this.txtSubject.TabIndex = 10;
this.txtSubject.Text = "";
//
// txtTo
//
this.txtTo.Location = new System.Drawing.Point(128, 56);
this.txtTo.Name = "txtTo";
this.txtTo.Size = new System.Drawing.Size(312, 22);
this.txtTo.TabIndex = 9;
this.txtTo.Text = "";
//
// txtFrom
//
this.txtFrom.Location = new System.Drawing.Point(128, 24);
this.txtFrom.Name = "txtFrom";
this.txtFrom.Size = new System.Drawing.Size(312, 22);
this.txtFrom.TabIndex = 8;
this.txtFrom.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.TabIndex = 7;
this.label3.Text = "Subject:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 6;
this.label2.Text = "To:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 5;
this.label1.Text = "From:";
//
// groupBox3
//
this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label5,
this.txtLog});
this.groupBox3.Location = new System.Drawing.Point(8, 440);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(464, 88);
this.groupBox3.TabIndex = 7;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Log Data";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 32);
this.label5.Name = "label5";
this.label5.TabIndex = 1;
this.label5.Text = "Communication:";
//
// txtLog
//
this.txtLog.AcceptsReturn = true;
this.txtLog.Location = new System.Drawing.Point(128, 24);
this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog";
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtLog.Size = new System.Drawing.Size(312, 48);
this.txtLog.TabIndex = 0;
this.txtLog.Text = "";
//
// groupBox4
//
this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
this.optPOP3,
this.optSMTP});
this.groupBox4.Location = new System.Drawing.Point(344, 8);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(128, 96);
this.groupBox4.TabIndex = 8;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Protocol Data";
//
// optPOP3
//
this.optPOP3.Enabled = false;
this.optPOP3.Location = new System.Drawing.Point(16, 56);
this.optPOP3.Name = "optPOP3";
this.optPOP3.TabIndex = 1;
this.optPOP3.Text = "POP3 Server";
//
// optSMTP
//
this.optSMTP.Checked = true;
this.optSMTP.Location = new System.Drawing.Point(16, 24);
this.optSMTP.Name = "optSMTP";
this.optSMTP.TabIndex = 0;
this.optSMTP.TabStop = true;
this.optSMTP.Text = "SMTP Server";
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(488, 573);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox4,
this.groupBox3,
this.groupBox2,
this.groupBox1,
this.button1});
this.Font = new System.Drawing.Font("Arial Unicode MS", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmMain";
this.Opacity = 0.89999997615814209;
this.Text = "Ghost Mailer";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void SendMailSMTP()
{
// create server SMTP with port 25
TcpClient SmtpServ;
string Data;
byte[] szData;
string CRLF = "\r\n";
if( optIPAddress.Checked )
{
SmtpServ = new TcpClient();// IP .Text,25);
}
else
{
SmtpServ = new TcpClient( txtServerName.Text, 25 );
}
try
{
// initialization
NetworkStream NetStrm = SmtpServ.GetStream();
StreamReader RdStrm= new StreamReader(SmtpServ.GetStream());
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// say hello to server and send response into log report
Data = "HELO " + txtServerName.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send sender data
Data = "MAIL FROM: " + "<" + txtFrom.Text + ">" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send receiver data
Data = "RCPT TO: " + "<" + txtTo.Text + ">" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send DATA
Data = "DATA " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send content data
Data = "SUBJECT: " + txtSubject.Text + CRLF + txtMessage.Text + CRLF + "." + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// quit from server SMTP
Data = "QUIT " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// close connection
NetStrm.Close();
RdStrm.Close();
txtLog.Text += "Close connection";
txtLog.Text +="Send mail successly..";
}
catch(InvalidOperationException err)
{
txtLog.Text += "Error: "+ err.ToString();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
button1.Enabled = false;
txtLog.Text = "";
if( optSMTP.Checked )
{
SendMailSMTP();
}
else
{
//POP3
}
button1.Enabled = true;
// back to normal cursor
Cursor.Current = cr;
}
}
}
Here is a small application I made using the Google web service. You can search for something and it will search the Google database and return the number of results. I'm going to have it bring up your web browser and display the results soon.
http://www.dev-lounge.com:8080/downl...archEngine.zip
This was my first C# application. It is also a web service that takes two numbers and sends them to my server. The operation is performed and the value is returned back to the GUI. I'm not sure if I still have the service running so let me know if it doesn't work.
http://www.dev-lounge.com:8080/downloads/WBGUI.zip
My latest application. I can't post any code or exes on this because I did it for work but I'll explain it. I had finished working on an application written in Java just a week or so ago. In the application I had an XML file that served as a bunch of strings used throughout my application. So if anyone wanted to make any changes they would open the XML file and make them (SMTPHost, Email Subjects, about 45 other strings). Of course this leaves room for errors. Someone not thinking could erase an element tag or something and screw up the whole application. So I decided to make an admin tool for modifying the XML file. It is a Windows Form that has a label and a textbox for each element in the XML file. Also it has tabs to separate each group. The user starts the application (the admin tool) and selects parse from the menu. The application parses my XML document and fills in the textboxes with the element data from the file. They can make changes to the document and save it. The application will then write the XML document back with the new values. The Java application parses the XML every time it starts so if the XML has changed, it takes effect the next time the Java app starts. Pretty cool, huh? ;)
Hm... this programs are cool, but they are very slow. What's the point of the C# language?
How do you define slow ? The first one runs like a charm on my notebook. The point of C# is directly accessing the .NET Framework for easy to build but powerful GUI applications.
They're web services. Information is going across the Internet. When you factor in my cable modem and whatever kind of connection you are on, it is going to be slow.Quote:
Originally posted by GaPe
Hm... this programs are cool, but they are very slow. What's the point of the C# language?
Yeah, the Google one is fast because the web service is being hosted at Google's servers. The second one is slow because it is hosted at my house. ;)Quote:
Originally posted by nvoigt
How do you define slow ? The first one runs like a charm on my notebook. The point of C# is directly accessing the .NET Framework for easy to build but powerful GUI applications.