Thread: Post programs

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Thumbs up Post programs

    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!
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    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 Disposebool disposing )
            {
                if( 
    disposing )
                {
                    if (
    components != null
                    {
                        
    components.Dispose();
                    }
                }
                
    base.Disposedisposing );
            }

            
    #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(384536);
                
    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(88);
                
    this.groupBox1.Name "groupBox1";
                
    this.groupBox1.Size = new System.Drawing.Size(32096);
                
    this.groupBox1.TabIndex 5;
                
    this.groupBox1.TabStop false;
                
    this.groupBox1.Text "Server Data";
                
    // 
                // txtServerName
                // 
                
    this.txtServerName.Location = new System.Drawing.Point(10424);
                
    this.txtServerName.Name "txtServerName";
                
    this.txtServerName.Size = new System.Drawing.Size(20022);
                
    this.txtServerName.TabIndex 2;
                
    this.txtServerName.Text "";
                
    // 
                // optIPAddress
                // 
                
    this.optIPAddress.Enabled false;
                
    this.optIPAddress.Location = new System.Drawing.Point(1656);
                
    this.optIPAddress.Name "optIPAddress";
                
    this.optIPAddress.Size = new System.Drawing.Size(8024);
                
    this.optIPAddress.TabIndex 1;
                
    this.optIPAddress.Text "IP-Address";
                
    // 
                // optName
                // 
                
    this.optName.Checked true;
                
    this.optName.Location = new System.Drawing.Point(1624);
                
    this.optName.Name "optName";
                
    this.optName.Size = new System.Drawing.Size(7224);
                
    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(8128);
                
    this.groupBox2.Name "groupBox2";
                
    this.groupBox2.Size = new System.Drawing.Size(464296);
                
    this.groupBox2.TabIndex 6;
                
    this.groupBox2.TabStop false;
                
    this.groupBox2.Text "EMail Data";
                
    // 
                // txtMessage
                // 
                
    this.txtMessage.Location = new System.Drawing.Point(128128);
                
    this.txtMessage.Multiline true;
                
    this.txtMessage.Name "txtMessage";
                
    this.txtMessage.Size = new System.Drawing.Size(312152);
                
    this.txtMessage.TabIndex 12;
                
    this.txtMessage.Text "";
                
    // 
                // label4
                // 
                
    this.label4.Location = new System.Drawing.Point(16128);
                
    this.label4.Name "label4";
                
    this.label4.TabIndex 11;
                
    this.label4.Text "Message:";
                
    // 
                // txtSubject
                // 
                
    this.txtSubject.Location = new System.Drawing.Point(12888);
                
    this.txtSubject.Name "txtSubject";
                
    this.txtSubject.Size = new System.Drawing.Size(31222);
                
    this.txtSubject.TabIndex 10;
                
    this.txtSubject.Text "";
                
    // 
                // txtTo
                // 
                
    this.txtTo.Location = new System.Drawing.Point(12856);
                
    this.txtTo.Name "txtTo";
                
    this.txtTo.Size = new System.Drawing.Size(31222);
                
    this.txtTo.TabIndex 9;
                
    this.txtTo.Text "";
                
    // 
                // txtFrom
                // 
                
    this.txtFrom.Location = new System.Drawing.Point(12824);
                
    this.txtFrom.Name "txtFrom";
                
    this.txtFrom.Size = new System.Drawing.Size(31222);
                
    this.txtFrom.TabIndex 8;
                
    this.txtFrom.Text "";
                
    // 
                // label3
                // 
                
    this.label3.Location = new System.Drawing.Point(1688);
                
    this.label3.Name "label3";
                
    this.label3.TabIndex 7;
                
    this.label3.Text "Subject:";
                
    // 
                // label2
                // 
                
    this.label2.Location = new System.Drawing.Point(1656);
                
    this.label2.Name "label2";
                
    this.label2.TabIndex 6;
                
    this.label2.Text "To:";
                
    // 
                // label1
                // 
                
    this.label1.Location = new System.Drawing.Point(1624);
                
    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(8440);
                
    this.groupBox3.Name "groupBox3";
                
    this.groupBox3.Size = new System.Drawing.Size(46488);
                
    this.groupBox3.TabIndex 7;
                
    this.groupBox3.TabStop false;
                
    this.groupBox3.Text "Log Data";
                
    // 
                // label5
                // 
                
    this.label5.Location = new System.Drawing.Point(1632);
                
    this.label5.Name "label5";
                
    this.label5.TabIndex 1;
                
    this.label5.Text "Communication:";
                
    // 
                // txtLog
                // 
                
    this.txtLog.AcceptsReturn true;
                
    this.txtLog.Location = new System.Drawing.Point(12824);
                
    this.txtLog.Multiline true;
                
    this.txtLog.Name "txtLog";
                
    this.txtLog.ScrollBars System.Windows.Forms.ScrollBars.Vertical;
                
    this.txtLog.Size = new System.Drawing.Size(31248);
                
    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(3448);
                
    this.groupBox4.Name "groupBox4";
                
    this.groupBox4.Size = new System.Drawing.Size(12896);
                
    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(1656);
                
    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(1624);
                
    this.optSMTP.Name "optSMTP";
                
    this.optSMTP.TabIndex 0;
                
    this.optSMTP.TabStop true;
                
    this.optSMTP.Text "SMTP Server";
                
    // 
                // frmMain
                // 
                
    this.AutoScaleBaseSize = new System.Drawing.Size(515);
                
    this.ClientSize = new System.Drawing.Size(488573);
                
    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.25FSystem.Drawing.FontStyle.RegularSystem.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 TcpClienttxtServerName.Text25 );
                }
                
                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 senderSystem.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;
            }
            
        }

    This is a very simple mail sending program for windows. POP has not been implemented yet, so some branches might not do anything useful
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    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

  4. #4
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    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

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    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?

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Hm... this programs are cool, but they are very slow. What's the point of the C# language?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    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.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by GaPe
    Hm... this programs are cool, but they are very slow. What's the point of the C# language?
    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.

  9. #9
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    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.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. post your network programs here
    By manav in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-27-2008, 01:13 AM
  2. Replies: 0
    Last Post: 07-26-2007, 09:55 AM
  3. programs with the most power
    By code2d in forum Tech Board
    Replies: 4
    Last Post: 01-12-2007, 12:59 PM
  4. Post your C# programs/screenshots!
    By CompiledMonkey in forum C# Programming
    Replies: 3
    Last Post: 03-30-2002, 10:17 AM