Wiki Home

Small Demo Package Comparison


Namespace: Wiki
A takeoff from Small Demo Packages
Given the following code in VFP, what does the equivalent micro package look like in VB, C#, C++, Delphi, and so on?

VFP Example
C#.NET Example
VB.NET Example
VB (6.0) Example
C++ Example
Delphi Example

VFP Example
*-- VFP 3,5,6,7 example of a small demo package.
PUBLIC x
x= CREATEOBJECT("MyForm")
x.Show()

DEFINE CLASS MyForm AS Form
  Caption= "Color me!"
  ADD OBJECT btn1 AS MyButton 

  FUNCTION Destroy
  RELEASE x

  FUNCTION ChangeColor()
  This.BackColor=RAND()*255^3
ENDDEFINE

DEFINE CLASS MyButton AS CommandButton
 Caption = "Push Me"
 Top= 20
 Left= 20  
 Height= 25  

 FUNCTION CLICK
 This.ChangeColor() 
 
 FUNCTION ChangeColor
 This.Parent.ChangeColor()
ENDDEFINE
Back To Top
C#.NET Example
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace SmallDemoPackage {
  public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.Button button1;		
    public Form1() {
      InitializeComponent();
    }
    private void InitializeComponent() {
      this.button1 = new System.Windows.Forms.Button();
      this.SuspendLayout();
      this.button1.Location = new System.Drawing.Point(96, 72);
      this.button1.Name = "button1";
      this.button1.TabIndex = 0;
      this.button1.Text = "Push Me!";
      this.button1.Click += new System.EventHandler(this.button1_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.button1});
      this.Name = "Form1";
      this.Text = "Color Me!";
      this.ResumeLayout(false);
    }		
    [STAThread]
    static void Main() {
      Application.Run(new Form1());
    }
    private void button1_Click(object sender, System.EventArgs e){
      changeColor();
    }
    private void changeColor() {
      Random m_random = new Random();
      this.BackColor = System.Drawing.Color.FromArgb(m_random.Next(0,255),m_random.Next(0,255),m_random.Next(0,255));
    }
  }
}
Back To Top
VB.NET example of form that changes background color randomly when the user clicks a button

Back To Top
VB (6.0) example of form that changes background color randomly when the user clicks a button

Back To Top
C++ example of form that changes background color randomly when the user clicks a button

Back To Top----
Delphi example of form that changes background color randomly when the user clicks a button

Back To Top
Contributors: Nancy Folsom Steven Black
Category Developer Productivity
( Topic last updated: 2002.02.08 12:18:23 PM )