Ejercicios RESUETOS C#

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 9

private void acercaDeToolStripMenuItem_Click(object sender, EventArgs e)

{
MessageBox.Show("Este es un ejemplo\ndel uso de menus", "Acerca de",
MessageBoxButtons.OK, MessageBoxIcon.Information);}

private void salirToolStripMenuItem_Click(object sender, EventArgs e)


{ Application.Exit()}
private void borrarColor()
{rojoToolStripMenuItem.Checked = false;
azulToolStripMenuItem.Checked = false;
verdeToolStripMenuItem.Checked = false;
negroToolStripMenuItem.Checked = false; }
private void negroToolStripMenuItem_Click(object sender, EventArgs e){
borrarColor();
Mostrarlabel.ForeColor = Color.Black;
negroToolStripMenuItem.Checked = true;}
private void rojoToolStripMenuItem_Click(object sender, EventArgs e{borrarColor();
Mostrarlabel.ForeColor = Color.Red;
rojoToolStripMenuItem.Checked = true; }
private void azulToolStripMenuItem_Click(object sender, EventArgs e{borrarColor();
Mostrarlabel.ForeColor = Color.Blue;
azulToolStripMenuItem.Checked = true;} private void verdeToolStripMenuItem_Click(object
sender, EventArgs e){
borrarColor();
Mostrarlabel.ForeColor = Color.Green;
verdeToolStripMenuItem.Checked = true}

private void borrarFuente()


{ timesNewRomanToolStripMenuItem.Checked = false;
comicSanToolStripMenuItem.Checked = false;
courierToolStripMenuItem.Checked = false;
}
private void timesNewRomanToolStripMenuItem_Click(object sender, EventArgs e)
{borrarFuente();
timesNewRomanToolStripMenuItem.Checked = true;
Mostrarlabel.Font = new Font("Times new roman", 14, Mostrarlabel.Font.Style);
}

private void courierToolStripMenuItem_Click(object sender, EventArgs e)


{ borrarFuente();
courierToolStripMenuItem.Checked = true;
Mostrarlabel.Font = new Font("Courier", 14, Mostrarlabel.Font.Style);
}

private void comicSanToolStripMenuItem_Click(object sender, EventArgs e)


{ borrarFuente();
comicSanToolStripMenuItem.Checked = true;
Mostrarlabel.Font = new Font("Comic Sans", 14, Mostrarlabel.Font.Style);
}

private void negritaToolStripMenuItem_Click(object sender, EventArgs e)


{negritaToolStripMenuItem.Checked = !negritaToolStripMenuItem.Checked;
Mostrarlabel.Font = new Font(Mostrarlabel.Font.FontFamily, 14, Mostrarlabel.Font.Style
^ FontStyle.Bold);
}

private void cursivaToolStripMenuItem_Click(object sender, EventArgs e)


{
cursivaToolStripMenuItem.Checked = !cursivaToolStripMenuItem.Checked;
Mostrarlabel.Font = new Font(Mostrarlabel.Font.FontFamily, 14, Mostrarlabel.Font.Style
^ FontStyle.Italic);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Fich
{public class MostrarListaTinos {public static void CrearFichero(String fichero){
BinaryWriter bw = null;
char resp;
try{bw = new BinaryWriter(new FileStream(fichero, FileMode.Create, FileAccess.Write));
String nombre, direccion;
long telefono = 0; do {
Console.Write("Nombre:"); nombre = Console.ReadLine();
Console.Write("direccion:"); direccion = Console.ReadLine();
Console.Write("telefono:"); telefono = long.Parse(Console.ReadLine());
bw.Write(nombre);
bw.Write(direccion);
bw.Write(telefono);
Console.Write("¿Desea escribir otro registro? (s/n)");
resp = (char)Console.Read();
Console.ReadLine(); } while(resp == 's');}finally
{ if (bw != null) bw.Close(); }public static void MostrarFichero(String fichero){
BinaryReader br = null; try{ if (File.Exists(fichero) {
br = new BinaryReader(new FileStream(fichero, FileMode.Open, FileAccess.Read));string
nombre, direccion; long telefono; do {nombre = br.ReadString();
direccion = br.ReadString();
telefono = br.ReadInt64();Console.WriteLine(nombre);
Console.WriteLine(direccion);
Console.WriteLine(telefono);
Console.WriteLine()} while (true); } else
Console.WriteLine("El fichero no existe"); }
catch (EndOfStreamException) { Console.WriteLine("Fin del listado"); }
finally { if (br != null) br.Close(); }}
public static void Main(string[] args)
{ String nombreFichero = null;
Try{Console.Write("Nombre del fichero:");
nombreFichero = Console.ReadLine(); char resp = 's';
if (File.Exists(nombreFichero)){
Console.Write("El fichero existe. ¿ Desea sobre escribirlo) n(s/n)");
resp = (char)Console.Read();
Console.ReadLine();}
if (resp == 's') { CrearFichero(nombreFichero); }}
catch (IOException e) { Console.WriteLine("Error" + e.Message); }
try{ if (args.Length == 0){Console.Write("Nombre del fichero:");
string fichero = Console.ReadLine();
MostrarFichero(fichero);}
else
{ MostrarFichero(args[0]); }}
catch (IOException e) { Console.WriteLine("Error " + e.Message); }
Console.Write(" press any key "); Console.Read();}}}
namespace Txt
{
class Program
{
static void Main(string[] args)
{
FileStream fs = null;
FileStream fe = null;

char[] cBuffer = new char[81];


byte[] bBuffer = new byte[81];
byte[] buffer = new byte[81];
int nbytes = 0, car;

try {

fs = new FileStream(" Maria.txt", FileMode.Create,


FileAccess.Write);
Console.WriteLine("Escriba el texto que desea almacenar en el
archivo:");
while ((car = Console.Read()) ! = '\r' && nbytes < buffer.Length)
{
buffer[nbytes]= (byte) car;
nbytes++;
}

fs.Write (buffer, 0, nbytes);


}
catch (IOException e)
{Console.WriteLine("Error:" + e.Message);

}
finally{
if (fs!=null) fs.Close();
}
try
{fe= new FileStream("Maria.txt", FileMode.Open, FileAccess.Read);
nbytes= fe.Read(bBuffer,0,81);
Array.Copy(bBuffer, cBuffer, bBuffer.Length);
String str = new String (cBuffer, 0, nbytes);
Console.WriteLine(str);
}
catch (IOException e){
Console.WriteLine("Error" + e.Message);
}
finally
{ if (fe! = null ) fe.Close();

}
Console.WriteLine("Press Any Key to finish");
Console.Read(); Console.Read();
namespace TablaMultiplica
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
private void button1_Click(object
sender, EventArgs e)
{
listBox1.Items.Clear();//limpia
los resultados para introducir nuevos
int tabla =
int.Parse(textBox1.Text);//variable del
textbox
int limite =
int.Parse(textBox2.Text);
int resultado;//donde se guarda la
multiplicacion

for (int i = 1; i <= limite;


i++)//ciclo for para generar la tabla
{
resultado = tabla *
i;//multimplicando
listBox1.Items.Add(tabla + "x"
namespace Factorial_form + i + "=" + resultado);//formato de la tabla
{
public partial class Form1
: Form }
{
public Form1()
{

InitializeComponent();
}

private void
Calcularbutton_Click(object
sender, EventArgs e)
{
float cantidad,
resultado=1, i;
cantidad =
float.Parse(textBox1.Text);
for (i = 1; i <=
cantidad; i++)
{
resultado = i*
resultado;

}
label2.Text =
resultado.ToString();

textbox1.Clear();
public Form1() private void
{ Calcular_Click(object sender,
EventArgs e)
InitializeComponent(); {
} int a, b, c, i,
num;
private void
button1_Click(object sender, a = 0;
EventArgs e) b = 1;
{
int b = listBox1.Items.Add(a);
Convert.ToInt32(this.textBox1.
Text); listBox1.Items.Add(b);
int exp = num =
Convert.ToInt32(this.textBox2. Convert.ToInt32(textBox1.Text)
Text); ;
decimal aux = b;
for (int i = 1; i for (i = 3; i <=
<= exp - 1; i++) num; i++)
{ {
aux = aux * b;
c = a + b;

} listBox1.Items.Add(c);
this.label3.Text = a = b;
aux.ToString(); b = c;
}
for (int i = 0; i <=
Convert.ToInt32(textBox1.Text);
private void Form1_Load(object

sum = sum + i;
Calcular_Click(object sender,

int num, sum = 0;

listBox1.Items.Add(sum);
sender, EventArgs e)

private void

num =

}
EventArgs e)
{

}
num; i++)

}
namespace VentaProject
{public partial class Form1 : Form{
public Form1(){
InitializeComponent();}
private void Form1_Load(object sender, EventArgs e){ }
private void label1_Click(object sender, EventArgs e){}
private void agregarVendedoresToolStripMenuItem_Click(object sender,
EventArgs e){
Form2 b = new Form2();
b.Show();}
private void opcionesToolStripMenuItem_Click(object sender, EventArgs e) {}
private void salirToolStripMenuItem_Click(object sender, EventArgs e){
Close();}
private void acercaDeToolStripMenuItem_Click(object sender, EventArgs e){}
private void infoToolStripMenuItem_Click(object sender, EventArgs e){
Form3 c = new Form3();
c.Show(); }
namespace VentaProject
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double total = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
total += Convert.ToDouble(row.Cells["Column4"].Value);
}
textBox1.Text = Convert.ToString(total);
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


{

namespace VentaProject
{
class Vendedor
{
private string nombre;
private string apellido;
private string mes;
private int cantidad;

public Vendedor()
{
nombre = string.Empty;
apellido = string.Empty;
mes = string.Empty;
cantidad = 0;}

public Vendedor(string nom, string ap, string ms, int cant)


{nombre= nom; apellido= ap; mes = ms;cantidad= cant;}
public String Nombre{get{return nombre;}set{nombre=value;}}
public String Apellido
get { return apellido; }
set { apellido = value; } public String Mes{get { return mes; } set { mes = value; } }
public int Cantidad
{
get { return cantidad; }
set { cantidad = value; }

}
}

También podría gustarte