Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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' };
{
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;
}
}
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--;
}
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);
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;
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)
{
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
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
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 =
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 =
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)
{
}
}
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;
ancho1;
ancho2;
ancho3;
altura;
nivel;//es el nivel querido
antniv = 0;
d=70;
}
}
//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;