This little example shows how to create objects without the use of the Design view, how to position the items, how to use the items, using objective programming and making use of returned results.

Hope it helps a few on the way.


PHP Code: 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 
WindowsFormsApplication9
{
    public 
partial class Form1 Form
    
{
        public 
Form1()
        {
            
InitializeComponent();
        }

        private 
void Form1_Load(object senderEventArgs e)
        {
            
this.Size = new Size(170200);
            
DrawObjects();
        }

        private 
void DrawObjects()
        {
            
// draw some controls
            
TextBox uname = new TextBox();
            
uname.Name "uname_tb";
            
uname.Location = new Point(2020);
            
uname.Size = new Size(10023);
            
this.Controls.Add(uname);

            
TextBox pword = new TextBox();
            
pword.Name "pwd_tb";
            
pword.Location = new Point(2053);
            
pword.Size = new Size(10023);
            
this.Controls.Add(pword);

            
Button button1 = new Button();
            
button1.Location = new Point(2086);
            
button1.Size = new Size(10023);
            
button1.Click += new EventHandler(button_click);
            
button1.Text "Login";
            
this.Controls.Add(button1);

            
Label myLabel = new Label();
            
myLabel.Name "statusLabel";
            
myLabel.Location = new Point(20119);
            
myLabel.Text "Ready.";
            
this.Controls.Add(myLabel);
        }

        private 
void button_click(object senderEventArgs e)
        { 
            
// create some controls so we can access them.
            
TextBox uname = new TextBox();
            
TextBox pwd = new TextBox();
            
Label status = new Label();

            
// for each control in this forms controls
            
foreach (Control control in this.Controls)
            {
                if (
control is TextBox)
                {
                    if (
control.Name == "uname_tb")
                        
uname = (TextBox)control;
                if (
control.Name == "pwd_tb")
                        
pwd = (TextBox)control;
                }

                if (
control is Label)
                {
                if (
control.Name == "statusLabel")
                        
status = (Label)control;
                }
            }

            
// get the value of the boolean object "checkLogin"
            // with these details, and store the returned output
            // in a boolean form.
            
Boolean output checkLogin(uname.Textpwd.Text);

            
// if the result of "checkLogin"....
            
if (!output)
                
status.Text "false";
            else
                
status.Text "true";
        }

        private 
bool checkLogin(string usernamestring password)
        {
            
// if the username and password are correct.
            
if (username == "jayfella" && password == "letmein")
                return 
true;

            else return 
false;

        }
            

    }

jayfella Reviewed by jayfella on . [c#] simple login box with logic This little example shows how to create objects without the use of the Design view, how to position the items, how to use the items, using objective programming and making use of returned results. Hope it helps a few on the way. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; Rating: 5