Sei sulla pagina 1di 34

using

using
using
using
using

/*//
class library
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace productobinario
{
public class Operador
{
public int valor(int num1, int num2)
{
return num1+num2;
}
}
}
guardar , ver en bin debug
referncia ad , examinar buscar en carpeta el dll
invocar
using System.Threading.Tasks;
using System.Windows.Forms;
using productobinario;(invocamos)
namespace nuevo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Operador funcion = new Operador();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int suma = funcion.valor(34, 23);
MessageBox.Show(suma.ToString());
}
funciones
public int generacolor(int a, int b, float d, Pen p1)
{
return a+b;
}
char[] letters = { 'A', 'B', 'C' };

string alphabet = new string(letters);


Graphics g1
Pen p5 = new Pen(Color.Blue, 3);
Point[] a = new Point[10];
new Bitmap bmp1;
bmp1 = new Bitmap(pictureBox2.Width, pictureBox2.Height);
a[0] = new Point (valor , pictureBox1.Width);
a[1] = new Point (130 , pictureBox1.Width/2);
g2 = pictureBox2.CreateGraphics();
g2.Clear(Color. Blue);
g2.DrawEllipse(p4, valor, valor * 12, pictureBox1.Width-x, pictureBox2.H
eight-x);
g2.FillEllipse(Brushes.Blue,valor, valor * 12, pictureBox1.Width, pictur
eBox2.Height);
timer1.Enabled = true;
deci = Convert.ToInt32(textBox2.Text);
MessageBox.Show("FIN DEL PROCESO");
textBox4.Text = cont.ToString()
PC2-Puntos-Base de Datos
namespace PC2
{ //9 botones,cargar, aceptar, reiniciar, ingresar,guardar, borrar, eliminar
//2 Data grid , picture box
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Variables Globales:
int codi;//codigo de figura que apunta la tabla 1
int codi2;//codigo de figura a la que apunta la tabla2
int x;//coordenada x a la que apunta la tabla2
int y;//coordenada y a la que apunta la tabla2
string ruta = "";//cadenas de conexion
string cnx = ""; //cadebna de conexin
int cont = 0;//contador del numero de puntos
Graphics g1;//varible para graficar
OleDbConnection cn; //conexin de una BD
int[] puntos;//variable con las coordenadas x e y ingresadas por teclado
Point[] puntosred;//variable puntosred para redibujar la imagen con punt
os obtenidos de la BD
int ESTADO = 0;// indicador de la cantidad de puntos ingresados
Point[] arreglo;// puntos para graficar el poligono a graficar despues d
e ingresar por teclado
int f;// fila que apunta la tabla 1
int f2;//fila que apunta la tabla2
//funcion creada para hacer una consulta, entra la consulta, devuelve un
a tabla DataTable
DataTable tabla(string cmdtext)
{
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmdtext, cn);
da.Fill(dt);
return dt;
}
//conexion Base de datos
private void button5_Click(object sender, EventArgs e)

{
OpenFileDialog op = new OpenFileDialog();
op.Filter = "Access | *accdb";
if (op.ShowDialog() == DialogResult.OK)
{
ruta = op.FileName;
cnx = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + ruta + "; Persist Security Info=False;";
cn = new OleDbConnection(cnx);
button4.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
string sql = "Select * from FIGURAs";
dataGridView1.DataSource = tabla(sql);
sql = "Select * from COORDENADAS";
dataGridView2.DataSource = tabla(sql);
}
else
MessageBox.Show("Debe seleccionar una base de datos");
}
private void button1_Click(object sender, EventArgs e)
{
cont = Convert.ToInt32(textBox1.Text); //inicializa el numero de pun
tos
arreglo = new Point[cont];//crea el vector de puntos
puntos = new int[2*cont];//crea un vector con los puntostipo int par
a insertarlos luego en la BD
// posiciones pares, x posiciones impares y 2*cont para x e y;
button2.Enabled = true;
button1.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
//obtener valores x e y
int x;
int y;
x = Convert.ToInt32(textBox2.Text);
y = Convert.ToInt32(textBox3.Text);
puntos[2 * ESTADO] = x;
puntos[2 * ESTADO + 1] = y;
arreglo[ESTADO] = new Point(x, y);
ESTADO++;
// si termina de insertarse se diibuja el poligono
if(ESTADO==cont)
{
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.Yellow);
g1.DrawPolygon(new Pen(Color.Violet, 3), arreglo);
ESTADO = 0;
button1.Enabled = true;
button2.Enabled = false;
}
}

private void button3_Click(object sender, EventArgs e)


{
//reinicializa los datos.
ESTADO = 0;
}
//funcion para insertar las coordenadas
void Ins_cor(int x,int y,int z)
{
string sq2 = "insert into coordenadas values (@c1,@c2,@c3)";
OleDbCommand cmd2 = new OleDbCommand(sq2, cn);
cn.Open();
cmd2.Parameters.Add("@c1", OleDbType.Integer).Value = x;
cmd2.Parameters.Add("@c2", OleDbType.Integer).Value = y;
cmd2.Parameters.Add("@c3", OleDbType.Integer).Value = z;
cmd2.ExecuteNonQuery();
cn.Close();
}
private void button4_Click(object sender, EventArgs e)
{
// se inserta la fecha de la figura
string sqlInsert =
"insert into figuras (FECHA_HORA) values(now())";
OleDbCommand cmd1 = new OleDbCommand(sqlInsert, cn);
cn.Open();
cmd1.ExecuteNonQuery();
cn.Close();
string sqlID = "Select max(figura) from figuras";
DataTable dt = tabla(sqlID);
int ID = Convert.ToInt32(dt.Rows[0][0]);
// se inserta los puntos a la base de datos
for(int i=0;i<cont;i++)
{
Ins_cor(ID, puntos[2 * i], puntos[2 * i + 1]);
}
//Mostrar base de datos
string sql = "Select * from FIGURAs";
dataGridView1.DataSource = tabla(sql);
sql = "Select * from COORDENADAS";
dataGridView2.DataSource = tabla(sql);
}
private void button6_Click(object sender, EventArgs e)
{
//Borrar toda la base de datos:
string sqlUpdate =
"DELETE FROM figuras";
OleDbCommand cmd1 = new OleDbCommand(sqlUpdate, cn);
cn.Open();
cmd1.ExecuteNonQuery();
cn.Close();
sqlUpdate =
"DELETE FROM coordenadas";
OleDbCommand cmd2 = new OleDbCommand(sqlUpdate, cn);
cn.Open();
cmd2.ExecuteNonQuery();
cn.Close();
//mostrar BD
string sql = "Select * from FIGURAs";
dataGridView1.DataSource = tabla(sql);

sql = "Select * from COORDENADAS";


dataGridView2.DataSource = tabla(sql);
}
private void button7_Click(object sender, EventArgs e)
{
//Eliminar coordenadas de la tabla 2
string sqlUpdate =
"DELETE FROM coordenadas where x=@c1 and y=@c2 and figura=@c3";
OleDbCommand cmd1 = new OleDbCommand(sqlUpdate, cn);
cn.Open();
cmd1.Parameters.Add("@c1", OleDbType.Integer).Value
= x;
cmd1.Parameters.Add("@c2", OleDbType.Integer).Value
= y;
cmd1.Parameters.Add("@c3", OleDbType.Integer).Value
= codi2;
cmd1.ExecuteNonQuery();
cn.Close();
//Mostrar BD
string sql = "Select * from FIGURAs";
dataGridView1.DataSource = tabla(sql);
sql = "Select * from COORDENADAS";
dataGridView2.DataSource = tabla(sql);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEven
tArgs e)
{
//extrae la fila luego extrae el codigo para guardarlo en codi
f = dataGridView1.CurrentCell.RowIndex;
//extrae el codigo que aputna la tabla1
codi = Convert.ToInt32(dataGridView1[0, f].Value.ToString());
}
private void button8_Click(object sender, EventArgs e)
{
//Eliminar la figura de la tabla 1 y luego sus coodernadas de acuerd
o al ID
string sqlUpdate =
"DELETE FROM figuras where figura=@c1";
OleDbCommand cmd1 = new OleDbCommand(sqlUpdate, cn);
cn.Open();
cmd1.Parameters.Add("@c1", OleDbType.Integer).Value
= codi;
cmd1.ExecuteNonQuery();
cn.Close();
sqlUpdate="DELETE FROM coordenadas where figura=@c1";
OleDbCommand cmd2 = new OleDbCommand(sqlUpdate, cn);
cn.Open();
cmd2.Parameters.Add("@c1", OleDbType.Integer).Value
= codi;
cmd2.ExecuteNonQuery();
cn.Close();
string sql = "Select * from FIGURAs";
dataGridView1.DataSource = tabla(sql);
sql = "Select * from COORDENADAS";
dataGridView2.DataSource = tabla(sql);
}

private void dataGridView2_CellClick(object sender, DataGridViewCellEven


tArgs e)
{
f2 = dataGridView2.CurrentCell.RowIndex;
//extraer las coodernadas y ID que apunta la tabla 2
codi2 = Convert.ToInt32(dataGridView2[0, f2].Value.ToString());
x = Convert.ToInt32(dataGridView2[1, f2].Value.ToString());
y = Convert.ToInt32(dataGridView2[2, f2].Value.ToString());
}
private void button9_Click(object sender, EventArgs e)
{
//Redibujar la imagen
// obtener el la cantidad de puntos que existen en la imagen con cod
igo codi*
string sqlID = "SELECT Count(*) AS TotalOrders FROM coordenadas wher
e figura =" + codi;
DataTable dt1 = tabla(sqlID);
int total = Convert.ToInt32(dt1.Rows[0][0]);
//obtener los puntos y guardarlos en la variable global puntosred
sqlID = "SELECT *FROM coordenadas where figura =" + codi;
dt1 = tabla(sqlID);
puntosred = new Point[total];
for(int i=0;i<total;i++)
{
//Extraigo los puntos de la tabla que consulte [x,y] las veces q
ue existan puntos;
//lo guardo en la variable point puntos red para volver a redibu
jar
puntosred[i] = new Point(Convert.ToInt32(dt1.Rows[i][1]), Conver
t.ToInt32(dt1.Rows[i][2]));
}
//graficar
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.Yellow);
g1.DrawPolygon(new Pen(Color.Blue, 2), puntosred);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void dataGridView2_CellContentClick(object sender, DataGridViewC
ellEventArgs e)
{
}
}
}
/// VASO
Graphics g1;
Pen pe1 = new Pen(Color.Red,3);
Point p1, p2, p3, p4;
int D,D1,D2,H;
int ac=1,difmax;
int aux,aux2;
int por,restox;

int c = 0;
int halt = 0;
private void button1_Click(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.Green);
D1=Convert.ToInt32(textBox3.Text);
D2=Convert.ToInt32(textBox4.Text);
D=Convert.ToInt32(textBox2.Text);
H = Convert.ToInt32(textBox1.Text);
p1 = new Point(pictureBox1.Width/3-(D1+D+D2)/2,60);
p2 = new Point(pictureBox1.Width/3+(D1+D+D2)/2,60);
p3 = new Point(pictureBox1.Width/3-D/2,60+H);
p4 = new Point(pictureBox1.Width / 3 + D / 2, 60 + H);
//duferencia entre base mayor y base menor
difmax = p3.X -p1.X;
//puntos iniciales
aux = p3.X;
aux2 = p4.X;
//unir puntos para la figura
g1.DrawLine(pe1,p1,p2);
g1.DrawLine(pe1, p3,p4);
g1.DrawLine(pe1, p1, p3);
g1.DrawLine(pe1, p2, p4);
//porcntaje d ellenado
por = H * Convert.ToInt32(comboBox1.Text) / 100;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
c++;
p3.Y-=ac;
p4.Y-=ac;
halt+=ac;
restox = Convert.ToInt32(halt*difmax/H);
p3.X = aux-restox;
p4.X = aux2 + restox;
g1.DrawLine(pe1, p3, p4);
textBox5.Text = c.ToString();
if (halt >= por)
{
timer1.Enabled = false;
textBox5.Text = "FIN";
}
}
private void Form1_Load(object sender, EventArgs e)
{
for (int j = 0; j <= 100; j+= 5)

comboBox1.Items.Add(j);
}
///PLANETARIO
Graphics g1;
Pen p1 = new Pen(Color.Red, 1);
int posx, posy;
float ang = 0;
int NUM,TEMP;
private void Form1_Load(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
for (int i = 0; i <= 3; i ++)//valores para la lista
comboBox1.Items.Add(i);
g1 = pictureBox1.CreateGraphics();
for (int i = 0; i <= 3; i++)//valores para la lista
comboBox2.Items.Add(i);
c
}
private void button1_Click(object sender, EventArgs e)
{
g1.Clear(Color.White);
timer1.Enabled = true;
NUM = Convert.ToInt32(comboBox1.Text);
TEMP= Convert.ToInt32(comboBox2.Text);
}
private void timer1_Tick(object sender, EventArgs e)
{
posx= Convert.ToInt32( 40*Math.Cos(ang*Math.PI/180));
posy = Convert.ToInt32( 10* Math.Sin(ang * Math.PI / 180));
g1.Clear(Color.SkyBlue);
g1.FillEllipse(Brushes.Yellow, 270, 150, 18, 18);
if (NUM == 1 && TEMP == 1)
{
g1.FillEllipse(Brushes.Orange, 2 * posx + 280, 2 * posy + 150, 1
0, 10);
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
ang--;

190,145, 180, 30, 0, 0);


190, 145, 180, 30, 0, 90);
190, 145, 180, 30, 0, 180);
190, 145, 180, 30, 0, 360);

}
if (NUM == 1 && TEMP == 2)
{
g1.FillEllipse(Brushes.Orange, 3 * posx + 280, 3 * posy + 150, 1
0, 10);
g1.DrawArc(p1, 160, 130, 240, 50, 0, 0);
g1.DrawArc(p1, 160, 130, 240, 50, 0, 90);

g1.DrawArc(p1, 160, 130, 240, 50, 0, 180);


g1.DrawArc(p1, 160, 130, 240, 50, 0, 360);
ang--;
}
if (NUM == 1 && TEMP == 3)
{
g1.FillEllipse(Brushes.Orange, 5 * posx + 280, 5 * posy + 150, 1
0, 10);
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,

105, 115, 390, 90, 0, 0);


105, 115, 390, 90, 0, 90);
105, 115, 390, 90, 0, 180);
105,115, 390, 90, 0, 360);

ang--;
}
if (NUM == 2 && TEMP == 1)
{
g1.FillEllipse(Brushes.Orange, 2 * posx + 280, 2 * posy + 150, 1
0, 10);
g1.FillEllipse(Brushes.Blue, 2 * posx + 280, 2 * posy + 150, 4,
4);
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,

190,
190,
190,
190,

145,
145,
145,
145,

180,
180,
180,
180,

30,
30,
30,
30,

0,
0,
0,
0,

0);
90);
180);
360);

ang--;
}
if (NUM == 2 && TEMP == 2)
{
g1.FillEllipse(Brushes.Orange, 3 * posx + 280, 3 * posy + 150, 1
0, 10);
g1.FillEllipse(Brushes.Blue, 3 * posx + 280, 3 * posy + 150, 4,
4);
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,

160,
160,
160,
160,

130,
130,
130,
130,

240,
240,
240,
240,

50,
50,
50,
50,

0,
0,
0,
0,

0);
90);
180);
360);

ang--;
}
if (NUM == 2 && TEMP == 3)
{
g1.FillEllipse(Brushes.Orange, 5 * posx + 280, 5 * posy + 150, 1
0, 10);
g1.FillEllipse(Brushes.Blue, 5 * posx + 280, 5 * posy + 150,4, 4
);
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
g1.DrawArc(p1,
ang--;
}

105,
105,
105,
105,

115,
115,
115,
115,

390,
390,
390,
390,

90,
90,
90,
90,

0,
0,
0,
0,

0);
90);
180);
360);

}
/////ESPIRAL
Graphics g1;
Pen p1 = new Pen(Color.Green,1);
int xx,yy;
double ANG; //para que inicie arriba
float RADIO, C=1;
int c;
private void Form1_Load(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
for (int i = 100; i <= 500; i+=5)//valores para la lista
comboBox2.Items.Add(i);

}
private void button1_Click(object sender, EventArgs e)
{
g1.Clear(Color.Yellow);
timer1.Enabled = true;
RADIO = Convert.ToInt32(comboBox2.Text);
ANG = Convert.ToInt32(textBox2.Text);
}
private void timer1_Tick(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
double cos = Math.Cos(ANG * (Math.PI / 180));
double sen = Math.Sin(ANG * (Math.PI / 180));
xx = Convert.ToInt32(300 - RADIO * cos);
yy = Convert.ToInt32(50 - RADIO / 2 * sen);
g1.DrawEllipse(p1, xx, yy + C, 5, 5);
g1.FillEllipse(Brushes.Blue, xx, yy + C, 5, 5);
ANG+=5;
RADIO = RADIO - (float)0.3;
C++ ;
c++;
textBox1.Text = c.ToString();
if (c == 500)
{
timer1.Enabled = false;
textBox1.Text = "END";
}

//CUADRADO ROTATORIO
Graphics g1;
Pen p1 = new Pen(Color.Black, 3);
Point[] a = new Point[5];
int ancho;
int x, y, TAM;
double D,ang=0;
private void Form2_Load(object sender, EventArgs e)
{
this.Text = "Cuadrado";
for (int i = 0; i <= 100; i += 5)
comboBox1.Items.Add(i);
}
private void button1_Click_1(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
ancho =Convert.ToInt32(comboBox1.Text);
//formando el cuadrado
TAM = Convert.ToInt32(Math.Sqrt(ancho * ancho + ancho * ancho));
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
g1.Clear(Color.SkyBlue);
D = -45 * (Math.PI / 180);
x = Convert.ToInt32(TAM * (0.5) * Math.Cos(ang * Math.PI / 180 +
D));
y = Convert.ToInt32(TAM * (0.5) * Math.Sin(ang * Math.PI / 180 +
D));
a[0] = new Point(200 + x, 200 + y);
D = -135 * (Math.PI / 180);
x = Convert.ToInt32(TAM * (0.5) * Math.Cos(ang * Math.PI / 180 +
D));
y = Convert.ToInt32(TAM * (0.5) * Math.Sin(ang * Math.PI / 180 +
D));
a[1] = new Point(200 + x, 200 + y);
D = -225 * (Math.PI / 180);
x = Convert.ToInt32(TAM * (0.5) * Math.Cos(ang * Math.PI / 180 +
D));
y = Convert.ToInt32(TAM * (0.5) * Math.Sin(ang * Math.PI / 180 +
D));
a[2] = new Point(200 + x, 200 + y);
D = -315 * (Math.PI / 180);
x = Convert.ToInt32(TAM * (0.5) * Math.Cos(ang * Math.PI / 180 +
D));
y = Convert.ToInt32(TAM * (0.5) * Math.Sin(ang * Math.PI / 180 +
D));
a[3] = new Point(200 + x, 200 + y);
a[4] = a[0]; ;
}
catch
{}

g1.DrawLines(p1, a);
if (checkBox1.Checked == true)
{
ang++;
p1.Color = Color.Blue;
}
else
{
ang--;
p1.Color = Color.Blue;
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
//CADENAS-MATRIZ
// separa letras
char[] letters = { 'A', 'B', 'C' };
string alphabet = new string(letters);
Graphics g1
Pen p5 = new Pen(Color.Blue, 3);
Point[] a = new Point[10];
new Bitmap bmp1;
bmp1 = new Bitmap(pictureBox2.Width, pictureBox2.Height);
a[0] = new Point (valor , pictureBox1.Width);
a[1] = new Point (130 , pictureBox1.Width/2);
g2 = pictureBox2.CreateGraphics();
g2.Clear(Color. Blue);
g2.DrawEllipse(p4, valor, valor * 12, pictureBox1.Width-x, pictureBox2.H
eight-x);
g2.FillEllipse(Brushes.Blue,valor, valor * 12, pictureBox1.Width, pictur
eBox2.Height);
timer1.Enabled = true;
deci = Convert.ToInt32(textBox2.Text);
MessageBox.Show("FIN DEL PROCESO");
textBox4.Text = cont.ToString();
private void button1_Click(object sender, EventArgs e)
{
//int i, cont = 0;
for (int i = 0; i < mensaje1.Length; i++)
{
char car = mensaje1[i];
MessageBox.Show(car.ToString());
}
string mensaje;

private void Form1_Load(object sender, EventArgs e)


{
mensaje = textBox1.Text; //string es letra
}
private void button1_Click(object sender, EventArgs e)
{//boton substring
string valor = mensaje.Substring(7, 3);//columna y # de elemntos
MessageBox.Show(valor);//automatico
}
private void button2_Click(object sender, EventArgs e)
{//boton indexof
int pos = mensaje.IndexOf("A");//el indice
MessageBox.Show(pos.ToString());
}
private void button3_Click(object sender, EventArgs e)
{//EXTRAER CARACTERES
int i,cont=0;
char car = mensaje[40];
MessageBox.Show(car.ToString());
}
private void button4_Click(object sender, EventArgs e)
{//CANTIDAD DE ELEMENTOS
int total = mensaje.Length;
MessageBox.Show(total.ToString());
}
private void button5_Click(object sender, EventArgs e)
{//extraccion con length
int len = mensaje.Length;
int pos = mensaje.IndexOf("s");
string subcad = mensaje.Substring(pos+1, len - pos-1);
MessageBox.Show(subcad);
}
private void button6_Click(object sender, EventArgs e)
{ //convertir a ascci
int i;
for (i = 0; i <= 30; i++)
{
char valor = mensaje[i];
int cod = (int)valor;
comboBox1.Items.Add(cod.ToString());
}
}
private void button7_Click(object sender, EventArgs e)
{ //convertir a char
int i=0;
char valor = (char)i;
for (i = 0; i <= 30; i++)
{

valor = mensaje[i];
comboBox1.Items.Add(valor.ToString());
}
}
private void button8_Click(object sender, EventArgs e)
{//char-ascci combo box
int t = mensaje.Length;
char car1,car2;
int val1,val2;
for (int i = 0; i < t; i++)
{
car1 = mensaje[i];
val1 = (int)car1;
//val2 = val1 + 5;
//car2 = (char)val2;
//listBox1.Items.Add(car1 + " >> " + val1 + " | "
//+ car2 + " >> " + val2 );
comboBox1.Items.Add(car1 + " = " + val1);
}
}
private void button9_Click(object sender, EventArgs e)
{//vector conteo
int[] arreglo = new int[mensaje.Length];
for (int i = 0; i < mensaje.Length; i++)
{
arreglo[i] = i;
listBox1.Items.Add(arreglo[i]);
}
}
private void button10_Click(object sender, EventArgs e)
{//MATRIZ
int[,] arreglo = new int[3, 3];
for (int i = 0; i < 3; i++)//cada elemto prueba con todos los de aba
jo
for (int j = 0; j < 3; j++)
{
arreglo[i, j] = (i+j);
}
foreach (int p in arreglo)//lo manda directo
listBox1.Items.Add(p);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
//CARACOL
Graphics g1;

double x, y, r,a,b;
double ang;
double DimX;
double DimY;
double i=0;
int c = 0;
Pen pe1 = new Pen(Color.Blue, 10);
Pen pe2 = new Pen(Color.Black,2);
private void button1_Click(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
DimX = pictureBox1.Width;
DimY = pictureBox1.Height;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
i+=10;
c++;
//Bitmap ba = new Bitmap(100,100);
Bitmap bb = new Bitmap(350,350);//tamao del picture
pictureBox1.Image = bb;
g1 = Graphics.FromImage(bb);
a = 0.1;
r = -i*a ;
x = r * Math.Cos(i * Math.PI * 0.0055555) + DimX * 0.5;
y = r * Math.Sin(i * Math.PI * 0.0055555) + DimY * 0.5;
g1.Clear(Color.SkyBlue);
g1.DrawEllipse(pe1, Convert.ToInt32(x), Convert.ToInt32(y),1,1);
for (ang = 0; ang < i; ang = ang + 0.5)
{
a = 0.1;
r = -ang *a;
x = r * Math.Cos(ang * Math.PI * 0.0055555) + DimX * 0.5;
y = r * Math.Sin(ang * Math.PI * 0.0055555) + DimY * 0.5;
g1.DrawEllipse(pe2, Convert.ToInt32(x), Convert.ToInt32(y),
1, 1);
}
textBox1.Text = c.ToString();
if (i>700)
{
timer1.Enabled = false;
textBox1.Text = "OK";
}
//ENCRIPTADO DE LETRAS
using System;
using System.Collections.Generic;

using
using
using
using
using
using
using

System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace codificador_de_color
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics g1;
Bitmap bp1;
Color co;//para colores argb
SolidBrush sc;//rellenar
int r, g, b;
int x, y;
private void Form1_Load(object sender, EventArgs e)
{
//creando el bitmap
bp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g1 = Graphics.FromImage(bp1);
}
private void button1_Click(object sender, EventArgs e)
{
int tam = textBox1.TextLength/3;
int aux=0;
for (int k = 0; k < tam; k++)
{
r = Convert.ToInt32(textBox1.Text[k+aux]);
g = Convert.ToInt32(textBox1.Text[k+1+aux]);
b = Convert.ToInt32(textBox1.Text[k + 2+aux]);
aux = aux + 2;
co = Color.FromArgb(r, g, b);
sc = new SolidBrush(co);
if (x*10 >= pictureBox1.Width )
{
x = 0; y++;
g1.FillEllipse(sc, x * 10, y * 10, 10, 10);
}
else {
g1.FillEllipse(sc, x * 10, y * 10, 10, 10);
}
x++;
pictureBox1.Image = bp1;
}
if ( (textBox1.TextLength % 3) != 0)
{

int caso = textBox1.TextLength % 3;


if (caso == 1)
{ r = Convert.ToInt32(textBox1.Text[textBox1.TextLength - 1]);
g = 0; b = 0;
}
else if (caso == 2)
{
r = Convert.ToInt32(textBox1.Text[textBox1.TextLength - 2]);
g = Convert.ToInt32(textBox1.Text[textBox1.TextLength - 1]);
b = 0;
}
if (x * 10 >= pictureBox1.Width)
{
x = 0; y++;
g1.FillEllipse(sc, x * 10, y * 10, 10, 10);
}
else
{
g1.FillEllipse(sc, x * 10, y * 10, 10, 10);
}
}
}
private void button2_Click(object sender, EventArgs e)
{ //borrar todo
x = 0;
y = 0;
g1.Clear(Color.White);
r = 0;
g = 0;
b = 0;
pictureBox1.Image = bp1;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
//CARGAR DIBUJO BMP-FLITAR
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace S3_C2_stefy_Ejercicios_PC1
{
public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}
Graphics g1,g2;
string [] colores = new string[10];
Bitmap bmp1 = new Bitmap(200,200);
Bitmap bmp2 = new Bitmap(200,200);
int cont = 0;
int n;
string valorSelecccinado;
Color cp;//color de cada pixel a escanear

, cm color del pixel a compa

rar
string sc;
private void Form1_Load(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
g2 = pictureBox2.CreateGraphics();
}
private void button3_Click(object sender, EventArgs e)
{
g1.Clear(Color.White);
g2.Clear(Color.White);
OpenFileDialog op = new OpenFileDialog();
op.Filter = "bitmap | *.bmp";
op.ShowDialog();
string ruta = op.FileName;
Bitmap bmp3 = new Bitmap(ruta);
g1 = Graphics.FromImage(bmp1);
g1.DrawImage(bmp3, 0, 0);
g1.DrawImage(bmp3, 200, 200);
pictureBox1.Image = bmp1;

}
int detectar(string color)
{
int r = Array.IndexOf(colores, color);
if (r == -1) //si encuentra un valor igual en la lista devuelve un v
alor mayor que -1
{
colores[cont] = color;
comboBox1.Items.Add(color);
cont++;
}
return (cont);
}

void buscar_colores()
{
Color cp;//color de cada pixel a escanear

, cm color del pixel a c

omparar
string sc;
for (int i = 0; i < 200; i++)
{
for (int j = 0; j < 200; j++)
{
cp = bmp1.GetPixel(i, j);
sc = cp.R + "," + cp.G + "," + cp.B;
n = detectar(sc);
}
}
listBox1.DataSource = colores;
comboBox1.DataSource = colores;
//No usar Data Source sino un FOR para que vuelva a escanear varias
veces !!
}
private void button2_Click(object sender, EventArgs e)
{
buscar_colores();
checkBox1.Enabled = true;

}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//string valorSelecccinado = comboBox1.Items[comboBox1.SelectedIndex
].ToString();//listBox1.Items[listBox1.SelectedIndex].ToString();
valorSelecccinado = comboBox1.Items[comboBox1.SelectedIndex].ToSt
ring();
for (int i =
{
for (int
{
cp =
sc =

0; i < 200; i++)


j = 0; j < 200; j++)
bmp1.GetPixel(i, j);
cp.R + "," + cp.G + "," + cp.B;

if (valorSelecccinado == sc)
bmp2.SetPixel(i, j, cp);
else if (checkBox1.Checked == false)
bmp2.SetPixel(i, j, Color.White);
else { }
}

}
pictureBox2.Image = bmp2;

}
private void button1_Click(object sender, EventArgs e)
{
//pictureBox2.Image.Save("E:\\UPC\\2015_02\\1.-Programacin Avanzada\\
Clases\\Semana 3\\stefy.bmp");
SaveFileDialog op = new SaveFileDialog();
op.Filter = "bitmap | *.bmp";
op.ShowDialog();
string ruta1 = op.FileName;
pictureBox2.Image.Save(ruta1);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
MessageBox.Show("Seleccione el color que desea adicionar");
valorSelecccinado = comboBox1.Items[comboBox1.SelectedIndex].ToS
tring();
for (int i =
for (int
{
cp =
sc =

0; i < 200; i++)


j = 0; j < 200; j++)
bmp1.GetPixel(i, j);
cp.R + "," + cp.G + "," + cp.B;

if (valorSelecccinado == sc)
bmp2.SetPixel(i, j, cp);
else if (checkBox1.Checked == false)
bmp2.SetPixel(i, j, Color.White);
else { }
}
pictureBox2.Image = bmp2;
}

}
}
}

//OTRA FORMA
Bitmap bmp1;
Bitmap bmp2= new Bitmap(300,200);
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnselec_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
OpenFileDialog op = new OpenFileDialog();
op.Filter = "bitmap | *.bmp";
op.ShowDialog();
string ruta = op.FileName;
bmp1 = new Bitmap(ruta);
pictureBox1.Image = bmp1;
}
Color[] BD = new Color[300];
private void btnscan_Click(object sender, EventArgs e)
{
Color c1;
Color c2;
int flag;
int cont = 0;
for(int i=0;i<300;i++)
{
for(int j=0;j<200;j++)
{
c1=bmp1.GetPixel(i, j);
if (i == 0 && j == 0)
{
comboBox1.Items.Add(c1.ToString());
BD[cont]= c1;
cont++ ;
}
else
{
flag = 0;
for (int m = 0; m < cont;m++)
{
if (BD[m]==c1)
{
flag = 1;
}
}
if(flag==0)
{
comboBox1.Items.Add(c1.ToString());
BD[cont] = c1;
cont++;
}
}
}

}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Color c3;
int pos = comboBox1.SelectedIndex;
if (checkBox1.Checked == false)
{
for (int i = 0; i < 300; i++)
{
for (int j = 0; j < 200; j++)
{
bmp2.SetPixel(i, j, Color.White);
}
}
for (int i = 0; i < 300; i++)
{
for (int j = 0; j < 200; j++)
{
c3 = bmp1.GetPixel(i, j);
if (c3 == BD[pos])
{
bmp2.SetPixel(i, j, c3);
}
}
pictureBox2.Image = bmp2;
}
}

else
{
for (int i = 0; i < 300; i++)
{
for (int j = 0; j < 200; j++)
{
c3 = bmp1.GetPixel(i, j);
if (c3 == BD[pos])
{
bmp2.SetPixel(i, j, c3);
}
}
pictureBox2.Image = bmp2;
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void btnsave_Click(object sender, EventArgs e)
{

SaveFileDialog op = new SaveFileDialog();


op.Filter = "bitmap | *.bmp";
op.ShowDialog();
string ruta1 = op.FileName;
pictureBox2.Image.Save(ruta1);
}
}
}
//CLASE PIXEL
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ManejoGraficos
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics g1,g2;
Bitmap bmp1 = new Bitmap(100, 100);
Bitmap bmp2 = new Bitmap(20, 20);
private void button1_Click(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.Yellow);
g1.DrawArc(new Pen(Color.Blue, 2), 10, 10, 130, 130, 90, 45);
g1.DrawArc(new Pen(Color.Red, 2), 10, 10, 130, 130, 270, 45);
g1.DrawArc(new Pen(Color.Green, 2), 10, 10, 130, 130, 0, 45);
}
private void button2_Click(object sender, EventArgs e)
{
// Bitmap bmp1 = new Bitmap(100, 100);
for (int i = 0; i < 100; i++)
{
bmp1.SetPixel(i, 49,Color.Blue);
}
pictureBox1.Image = bmp1;
}
private void button3_Click(object sender, EventArgs e)
{ //crear bitmap
// Bitmap bmp1 = new Bitmap(100, 100);
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
bmp1.SetPixel(i, j, Color.Red);

}
}
pictureBox1.Image = bmp1;
}
private void button4_Click(object sender, EventArgs e)
{
Color c1 = bmp1.GetPixel(0, 49);
// MessageBox.Show(c1.ToString());
int r = c1.R;
int g = c1.G;
int b = c1.B;
textBox1.Text = "R: " + r;
textBox2.Text = "G: " + g;
textBox3.Text = "B: " + b;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{//mover raton con coordenadas RGB
try
{
this.Text = "X: " + e.X + " Y:" + e.Y;
Color c1 = bmp1.GetPixel(e.X, e.Y);
int r = c1.R;
int g = c1.G;
int b = c1.B;
textBox1.Text = "R: " + r;
textBox2.Text = "G: " + g;
textBox3.Text = "B: " + b;
}
catch (Exception ex)
{
this.Text = ex.Message;
}
}
private void button5_Click(object sender, EventArgs e)
{//metodos graficos en bitmap
//g1 = pictureBox1.CreateGraphics();
g1 = Graphics.FromImage(bmp1);
g1.Clear(Color.Red);
g1.DrawEllipse(new Pen(Color.Blue, 2), 0, 0, 100, 100);
pictureBox1.Image = bmp1;
}
private void button6_Click(object sender, EventArgs e)
{//ejemplo2
g1 = Graphics.FromImage(bmp2); //bmp2
g1.Clear(Color.Red);
g1.DrawEllipse(new Pen(Color.Blue, 2), 0, 0, 20, 20);
g2 = Graphics.FromImage(bmp1); //bmp1
g2.DrawImage(bmp2, 0, 0);
g2.DrawImage(bmp2, 30, 30);
g2.DrawImage(bmp2, 60, 60);

pictureBox1.Image = bmp1;
}
private void button7_Click(object sender, EventArgs e)
{ //cargar archivos bmp
OpenFileDialog op = new OpenFileDialog ();
op.Filter = "bitmap | *.bmp";
op.ShowDialog();
string ruta = op.FileName ;
Bitmap bmp3 = new Bitmap(ruta);
g2 = Graphics.FromImage(bmp1); //bmp1
g2.DrawImage(bmp3, 0, 0);
g2.DrawImage(bmp3, 30, 30);
g2.DrawImage(bmp3, 60, 60);
pictureBox1.Image = bmp1;
}
}
}
//CUBO
Graphics
int c =
int x1,
int x3,
int p1,
Pen pe1
private
{

g1;
0;
x2;
x4;
p2, p3, p4;
= new Pen(Color.Green, 3);
void Form1_Load(object sender, EventArgs e)

}
private void button1_Click(object sender, EventArgs e)
{
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.Yellow);
x1 = 80;
x2 = 80;
x3 = 130;
x4 = 130;
p1 = 50;
p2 = 50;
p3 = 100;
p4 = 100;
timer1.Enabled = true;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)

{
x1++;
x2++;
x3--;
x4--;
p1++;
p2++;
p3--;
p4--;
c++;
if (x1 >= 100 && x2>= 100 && x3 <= 50 && x4 <= 50 && p1 >= 100 && p2
>= 100 && p3 <= 50 && p4 <= 50)
timer1.Enabled = false;
if (c == 80)
{
g1 = pictureBox1.CreateGraphics();
g1.Clear(Color.SkyBlue);
textBox1.Text = "CUBO TERMINADO";
}
//Rutina para achicar le cubo
g1.DrawLine(pe1,
g1.DrawLine(pe1,
g1.DrawLine(pe1,
g1.DrawLine(pe1,

x1,
x1,
x1,
x3,

//Segundo Cuadrado
g1.DrawLine(pe1, p1,
g1.DrawLine(pe1, p1,
g1.DrawLine(pe1, p1,
g1.DrawLine(pe1, p3,
//uniendo lineas
g1.DrawLine(pe1, x1,
g1.DrawLine(pe1, x1,
g1.DrawLine(pe1, x3,
g1.DrawLine(pe1, x3,

x2,
x3,
x2,
x1,

x1,
x3,
x3,
x3,

x4);
x4);
x1);
x4);

p2,
p3,
p2,
p1,

p1,
p3,
p3,
p3,

p3);
p4);
p1);
p4);

x2,
x3,
x3,
x1,

p1,
p1,
p3,
p3,

p2);
p3);
p4);
p1);

textBox1.Text = c.ToString();
//USO DE SPLIT (SEPARAR)
namespace usodeSplit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string cadena = textBox1.Text;
char[] car = new char[2];
car[0] = '(';

car[1] = ')';
string[] datos = cadena.Split(car);
listBox1.DataSource = datos;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

//ENCRIPTADOR

namespace encriptador
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Clear();//limpiamos el textbox2
string tx1 = textBox1.Text; //cojemos nuestra entrada (donde esc
ribimos) en modo cadena
if (comboBox1.SelectedIndex == 0) //si es la primera opcion, en
este caso:encriptar
{
for (int i = 0; i < tx1.Length;i++ )
//foreach (char c in tx1) //aparte del for, guarda letra
por letra de la cadena tx1 en una char "c"
{
int c_int = Convert.ToInt32(tx1[i]); // el cacarter
(la letra) "c" se convierte a numero decimal entero
string binary_string = Convert.ToString(c_int, 2); /
/"el numero entero decimal "c2", en modo binario" se convierte en cadena
binary_string = "1" + binary_string; //agregamos un
bit a binary a la izq.. si pusieramos binary + "1" se colocaria a la derecha
int binary_to_int = Convert.ToInt32(binary_string, 2
); //"la cadena de 9 bits, en modo binario" se convierten en un numero entero de
cimal
string hexValue = Convert.ToString(binary_to_int, 16
);//"este numero entero decimal, en modo hexa" lo convierten a cadena
textBox2.Text = textBox2.Text + hexValue; //todos so
n strings(cadenas); suma de cadenas, es posicionar a la derecha (agregar valores

a la cadena a la derecha)
}
}
else //si es desencriptar; desencriptar toma el valor de 1 en el
combobox, xq es el segundo
{
for (int j = 0; j < tx1.Length ; j = j + 2)
{
string aux2 = tx1.Substring(j, 2); //substrae de tx1 des
de la posicion j, 2 letras (j y j+1) y los guarda en la cadena "aux2"// substrae
2 letras xq esta en hexa (y porq eran 8 bits)
int value0 = Convert.ToInt32(aux2, 16); //"la cadena aux
de 2 letras, en modo hexa" lo convierte a numero entero decimal
string value = Convert.ToString(value0, 2);// "el numero
entero decimal, en modo binario" lo convierte a cadena
string auxb = value.Substring(1, value.Length - 1);// de
de la cadena de 9 bits, Coje los 8 de la derecha (en modo cadena)
int dec = Convert.ToInt32(auxb, 2); //"la cadena de 8 bi
ts, en modo binario", la convierte a numero entero decimal
char charValue = (char)dec; //el numero entero decimal l
o toma como caracter(letra)
textBox2.Text = textBox2.Text +charValue;//de caracter e
n caracter los va agregando
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
//RESORTE CON MASA
namespace Resorte
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics x;
void Espiral(int largofinal, int numeroespiral,int arcanch,int yinit)
{
x = pictureBox1.CreateGraphics();
x.Clear(Color.White);
Pen p = new Pen(Color.Black);
p.Width = 1;
int ancho = pictureBox1.Width;
int alto = pictureBox1.Height;

int arcalt = largofinal / (numeroespiral * 3);


yinit = yinit + arcalt;
for (int i = 0; i < numeroespiral; i++)
{
x.DrawArc(p, ancho / 2 - arcanch / 4, yinit - arcalt / 2, arcanc
h, arcalt, 270, 90);
x.DrawArc(p, ancho / 2 - arcanch+arcanch/4, yinit - arcalt / 2,
arcanch * 2, arcalt * 4, 180, 90);
x.DrawArc(p, ancho / 2 - arcanch / 4, yinit - arcalt / 2, arcanc
h, arcalt, 0, 90);
x.DrawArc(p, ancho / 2 - arcanch + arcanch / 4, yinit - 7 * arca
lt / 2, arcanch * 2, arcalt * 4, 90, 90);
yinit = yinit + arcalt * 3;
}
}
void ImagenInicial()
{
valor = 50;
Espiral(valor, 7, 20, 20);
x.FillRectangle(Brushes.Red, pictureBox1.Width / 2 - 20, valor + 5,
40, 30);
}
private void button1_Click(object sender, EventArgs e)
{
activar = true;
ImagenInicial();
}
int pend = 1;
int valor = 50;
int maxvalor;
bool activar = false;
private void timer1_Tick(object sender, EventArgs e)
{
Espiral(valor, 7, 20, 20);
x = pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Black);
p.Width = 1;
x.FillRectangle(Brushes.Red, pictureBox1.Width / 2 - 20, valor + 5,
40, 30);
valor = valor + 5*pend;
if (valor >= maxvalor) { pend=-1; }
else if (valor <= 50) { pend = 1; }
}
int maxvalor1;
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
maxvalor1 = pictureBox1.PointToClient(Cursor.Position).Y-35;

if (maxvalor1 > 50){maxvalor = maxvalor1;}


else { maxvalor = 51; }
activar = false;
timer1.Enabled = true;
}
int initk=0;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((activar == true))
{
initk = pictureBox1.PointToClient(Cursor.Position).Y;
if ((initk-30)> 50)
{
Espiral(initk - 30, 7, 20, 20);
x = pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Black);
p.Width = 1;
x.FillRectangle(Brushes.Red, pictureBox1.Width / 2 - 20, ini
tk-30, 40, 30);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
ImagenInicial();
timer1.Enabled = false;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
//CISTERNA
namespace Envase
{
public partial class Envase : Form
{
public Envase()
{
InitializeComponent();
}
System.Drawing.Graphics x;
int
int
int
int
int
int
int

ancho1;
ancho2;
ancho3;
altura;
nivel;//es el nivel querido
antniv = 0;
d=70;

private void button1_Click(object sender, EventArgs e)


{
ancho1 = Convert.ToInt32(textBox1.Text);//lo que escribimos en el te
xtbox1, en modo texto, lo convierte a numero entero decimal
ancho2 = Convert.ToInt32(textBox2.Text);
altura = Convert.ToInt32(textBox3.Text);
int porcentaje = Convert.ToInt32(comboBox1.SelectedItem);
nivel = (int)((float)altura * porcentaje / 100);
x = pictureBox1.CreateGraphics();//x toma al picture box
x.Clear(Color.White); //limpia el picturebox1 con fondo blanco
timer1.Interval = 200;//intervalo de tiempo 0.2s 200ms
timer1.Enabled = true; //inicia el timer e inicia la simulacion
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//altura = Convert.ToInt32(textBox3.Text);
//int porcentaje = comboBox1.SelectedIndex;
//nivel = (int)(((float)altura / 100) * (10*(porcentaje+1)));
}
private void timer1_Tick(object sender, EventArgs e)
{
int por = (int)(100 * ((float)antniv / (float)altura));
label5.Text = Convert.ToString(por) + ' ' + '%';//pone en pantalla e
l porcentaje
if (antniv == nivel) //se detiene cuando se haya llegado al nivel p
edido en el combobox "porcentaje"
{
timer1.Enabled = false;
}
else
{
x = pictureBox1.CreateGraphics();
x.Clear(Color.White);
//CONDICION para que anteriornivel alcance a nivel
if (antniv < nivel)
{ antniv = antniv + 1; }
else
{ antniv = antniv - 1; }
//ancho de la superficie superior del agua
ancho3 = (int)((float)ancho1 + (((float)(altura - antniv) / (flo
at)altura) * (float)(ancho2 - ancho1)));
//dibuja al tanque negro
Pen p1 = new Pen(Color.Black);
p1.Width = 1;
x.DrawEllipse(p1,d - (ancho1 / 2), 20, ancho1, 20);
x.DrawEllipse(p1,d - (ancho2 / 2), 20 + altura, ancho2, 20);
x.DrawLine(p1,d - (ancho1 / 2), 30, d - (ancho2 / 2), 30 + altur
a);
x.DrawLine(p1,d + (ancho1 / 2), 30, d + (ancho2 / 2), 30 + altur
a);

//cuerpo del cilindro llenandose - celeste


Pen p = new Pen(Color.Cyan);
p.Width = 1;
Point[] ap = new Point[4];
ap[0] = new Point(d - (ancho3 / 2), 30 + altura - antniv);//sup
izq
ap[1] = new Point(d - (ancho2 / 2), 30 + altura);//inf izq
ap[2] = new Point(d + (ancho2 / 2), 30 + altura);//inf der
ap[3] = new Point(d + (ancho3 / 2), 30 + altura - antniv);//sup
der
x.DrawPolygon(p, ap);
x.FillPolygon(Brushes.Cyan, ap);
//Desplazamiento de la superficie del agua
x.FillEllipse(Brushes.Cyan, d - (ancho2 / 2), 20 + altura, ancho
2, 20);//la base
x.FillEllipse(Brushes.Blue, d - (ancho3 / 2), 20 + altura - antn
iv, ancho3, 20);//superficie superior
}
}
private void Envase_Load(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
//SEPARA NUMEROS
string[] sep;
int a, b, c;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
sep = comboBox1.Text.Split('-');
a =Convert.ToInt32( sep[0]);
b = Convert.ToInt32(sep[1]);
c = Convert.ToInt32(sep[2]);
textBox1.Text = a.ToString();
textBox2.Text = b.ToString();
textBox3.Text = c.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}

}
}
//LANZAMIENTO (BOTN SIMULAR , TXBOX ANGULO)
private void button1_Click(object sender, EventArgs e)
{
angfin = Convert.ToInt32(textBox1.Text);
timer1.Enabled = true; //inicia el timer e inicia la simulacion
}
int angfin;
int xx, yy;
int xd, yd;
int radio=100;
double t=0;
int vx;
int vy;
double ang = 450;//para que empiece arriba
private void timer1_Tick(object sender, EventArgs e)
{
x = pictureBox1.CreateGraphics();
x.Clear(Color.Black);
Pen p = new Pen(Color.Blue);//lapiz
p.Width = 2;//ancho del lapiz
//x.Clear(Color.White);//todo el picturebox blanxo
double co = Math.Cos((float)ang *(float)(Math.PI / 180));
double se = Math.Sin((float)ang * (float)(Math.PI / 180));
xx = Convert.ToInt32(200 - (float)radio * co);
yy = Convert.ToInt32(200 - (float)radio * se);
x.DrawLine(p, 200, 200, xx+1, yy+1);
x.DrawEllipse(p, xx, yy, 16,16);
x.FillEllipse(Brushes.Blue, xx,yy,16,16);
ang = ang - 1;
if (ang == angfin)
{
timer1.Enabled = false;
timer2.Enabled = true;
vy = ((int)((float)radio * co));
vx = -((int)((float)radio * se));
}
}
private void timer2_Tick(object sender, EventArgs e)
{
x = pictureBox1.CreateGraphics();
x.Clear(Color.White);
Pen p = new Pen(Color.Blue);//lapiz
p.Width = 2;//ancho del lapiz
x.Clear(Color.White);//todo el picturebox blanxo
xd = (int)(xx + (float)vx * t);
yd = (int)(yy + (float)vy * t + (float)0.5 * t * t*9.8);
x.DrawEllipse(p, xd, yd, 16, 16);
x.FillEllipse(Brushes.Blue, xd, yd, 16, 16);
//x.DrawLine(p, , , xd, yd );
//t++;
t=t+0.1;

if (xd >= 400)


{ timer2.Enabled = false; }
}
}
}
*/

Potrebbero piacerti anche