0% found this document useful (0 votes)
32 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

This document defines a class called Form1 that inherits from the Form class. Form1 contains methods to generate random numbers and store them in a double array, display the array data in a datagrid, calculate the sum and average of the array, and exit the application. It initializes graphics objects and draws lines to create a grid pattern on a form. Buttons trigger methods to insert new random data, display it, and calculate statistics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

This document defines a class called Form1 that inherits from the Form class. Form1 contains methods to generate random numbers and store them in a double array, display the array data in a datagrid, calculate the sum and average of the array, and exit the application. It initializes graphics objects and draws lines to create a grid pattern on a form. Buttons trigger methods to insert new random data, display it, and calculate statistics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 Arreglos02
{
public partial class Form1 : Form
{
public Form1()// constructor
{
InitializeComponent();
///inicializar componentes
g = this.CreateGraphics();
this.Paint += new PaintEventHandler(Plano);
}

public System.Drawing.Graphics g;
int i = 0, NvoEle,j=0;
double Ele;
double[] Arreglo = new double[100]; //Declarar arreglo de 10 posiciones
Boolean encontrado = false, eliminado = false, modificado = false;

void Plano(object sender, PaintEventArgs e)


{
g.DrawLine(Pens.Blue, 50, 500, 500, 500);
g.DrawLine(Pens.Blue, 50, 50, 50, 500);

for (int m = 50; m < 500; m += 10)


{
g.DrawLine(Pens.Blue, m, 495, m, 505);//lineas de separacion
horizontal
g.DrawLine(Pens.Blue, 45,m,55,m);//lineas de separacion vertical
}
}
Random r = new Random();

public void ObtenerDato()


{
for (int j = 0; j < 100; j++)
{
Ele = Math.Round(r.NextDouble(), 3);
Arreglo[j] = Ele;
}
}

DataTable dt = new DataTable();//crear objeto (tabla)


public void MostrarDatos()
{
dt.Columns.Add("Voltaje");
for (int j = 0; j < 100; j++)
{
DataRow row = dt.NewRow(); //agregar renglon o fila a la tabla
row["Voltaje"] = Arreglo[j];//Enviar el dato del arreglo a la columna de
voltaje
dt.Rows.Add(row); //agregar el registro a la tabla
dtgDatos.DataSource = dt;// enviartabla al datagridView
dtgDatos.Update(); //actualiza datagridView
}
}

private void btnSalir_Click(object sender, EventArgs e)


{
Application.Exit();//salir de la aplicacion

private void btnInsertar_Click(object sender, EventArgs e)


{
ObtenerDato();
MostrarDatos();

public void suma()


{
double sum = 0;
for (int k = 0; k < 100; k++)
{
sum = sum + Arreglo[k];
}
txtSuma.Text = Convert.ToString(sum);
}

public void Promedio()


{
double sum = 0;
double prom = 0;
for (int k = 0; k < 100; k++)
{
sum = sum + Arreglo[k];
}
prom = sum / 100;
txtProm.Text = Convert.ToString(prom);
}

You might also like