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);
}