public class TestParaPrism : TestParallelogram { private int elevation; public TestParaPrism(int left, int top, int basewidth, int baseheight, int offset, bool ishorizontal, int tall) { if (ishorizontal) { // The top and bottom sides of the parallelogram are flat, left and right sides are sloped if (offset > 0) { // Upper left corner to the right of lower left corner. vertices = new Point[] {new Point(left+offset, top), new Point(left+basewidth+offset, top), new Point(left+basewidth, top+baseheight), new Point(left, top+baseheight)}; // Make the vertices. } else { // Upper left corner farther left than lower left corner. vertices = new Point[] {new Point(left, top), new Point(left+basewidth, top), new Point(left-offset+basewidth, top+baseheight), new Point(left-offset, top+baseheight)}; } // End of offset's if block. } else { // The left and right sides of the parallelogram are flat, top and bottom sides are sloped. if (offset > 0) { // Upper left corner is below the upper right corner. vertices = new Point[] {new Point(left, top+offset), new Point(left+basewidth, top), new Point(left+basewidth,top+baseheight), new Point(left, top+baseheight+offset)}; } else { // Upper left corner is above the upper right corner. vertices = new Point[] {new Point(left, top), new Point(left+basewidth, top-offset), new Point(left+basewidth,top+baseheight-offset), new Point(left, top+baseheight)}; } // End of offset's if block. } // End of horizontal check if block. elevation = tall; } // End of TestParaPrism constructor. public int Volume() { return base.Area() * elevation; } // End of volume function. } |
private void btn14_Click(object sender, EventArgs e) { TestParaPrism woodbeam = new TestParaPrism(0, 0, 50, 50, 10, true, 20); MessageBox.Show(woodbeam.Area().ToString()); // Underlying parallelogram's area is 2500. MessageBox.Show(woodbeam.Volume().ToString()); // Volume of prism is 50000. woodbeam = null; //Protip: Annul object references. } // End of btn 14's click procedure. |
virtual public void Inflate(int addwidth, int addheight) { vertices[1].Offset(addwidth, 0); // Offset is a member of the Point structure which basically moves a point. vertices[2].Offset(addwidth, addheight); vertices[3].Offset(0, addheight); } // End of inflate subroutine. |
public override void Inflate(int addwidth, int addheight) { base.Inflate(addwidth, addheight); // Very nice. elevation += addheight; // Let's also change the elevation. } // End of Inflate override |
public void Inflate(int addwidth, int addheight) { vertices[1].Offset(addwidth, 0); // Offset is a member of the Point structure which basically moves a point. vertices[2].Offset(addwidth, addheight); vertices[3].Offset(0, addheight); } // End of inflate subroutine. |
new public void Inflate(int addwidth, int addheight) { base.Inflate(addwidth, addheight); // Very nice. elevation += addheight; // Let's also change the elevation. } // End of the new Inflate subroutine |
public void Inflate(int addwidth, int addheight, int addelevation) { base.Inflate(addwidth, addheight); // Very nice. elevation += addelevation; // Let's also change the elevation. } // End of Inflate subroutine. |
private void btn15_Click(object sender, EventArgs e) { Button btn16 = new Button(); btn16.Location = new Point(181, 362); btn16.Visible = true; btn16.Click += new EventHandler(randomsub); this.Controls.Add(btn16); } // End of btn 15's click procedure. private void randomsub(object sender, EventArgs e) { MessageBox.Show("Run-time event handler successful."); } // End of randomsub |
public delegate void InflationEventHandler(object sender, EventArgs e, int test); // Allows the class to call a subroutine that accepts an object and an EventArgs. public event InflationEventHandler Inflated; // Allows the class to raise the objname_Inflated event. |
public void Inflate(int addwidth, int addheight, int addelevation) { base.Inflate(addwidth, addheight); // Very nice. elevation += addelevation; // Let's also change the elevation. Inflated(this, null, 159); // Raises the Inflated event. } // End of Inflate subroutine. |
private void woodbeam_Inflated(object sender, EventArgs e, int randomnumber) { MessageBox.Show(randomnumber.ToString()); } // End of woodbeam's inflated procedure. |
private void btn14_Click(object sender, EventArgs e) { TestParaPrism woodbeam = new TestParaPrism(0, 0, 50, 50, 10, true, 20); woodbeam.Inflated += new TestParaPrism.InflationEventHandler(woodbeam_Inflated); // When woodbeam is inflated, the woodbeam_Inflated event procedure will run, using information collected from the InflationEventHandler. woodbeam.Inflate(10, 10, 15); MessageBox.Show(woodbeam.Area().ToString()); // Underlying parallelogram's area is 2500. MessageBox.Show(woodbeam.Volume().ToString()); // Volume of prism is 50000. woodbeam = null; //Protip: Annul object references. }// End of btn 14's click procedure. |