Novedades Desafíos Papers y H-Zine Proyectos Foro
foros de discusión

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Ayuda con C# plis, Necesito ayuda para mi trabajo final plis en C#
osrieldei
post Oct 15 2008, 12:52 PM
Post #1


Recién llegado
*


Group: Hackerss Member
Posts: 1
Joined: 14-October 08
Member No.: 6,159



estoy haciedno un jueguito llamado guerra de barcos no se si lo habran visto antes pero tengo un problema quiero hacer un array de labels pero no se como hacerlos osea crear 100 labels pero ponerle una caracteristica como su posion X,Y
Go to the top of the page
 
+Quote Post
marioly
post Oct 15 2008, 01:13 PM
Post #2


Regia
Group Icon


Group: Root Admin
Posts: 2,007
Joined: 14-April 06
From: Mty, Nuevo Leon
Member No.: 38



System.Windows.Forms.Label[] misLabel = new System.Windows.Forms.Label[100];
...

misLabel[0] = new Label();
misLabel[0].Size = new System.Drawing.Size(33, 33);
misLavel[0].Location = new System.Drawing.Point(30, 30);


Recuerda que tienes que inicializar cada elemento y agregarlo a "Controls", saludos


--------------------
Go to the top of the page
 
+Quote Post
mig16
post Oct 15 2008, 02:48 PM
Post #3


Miembro
***


Group: Hackerss Member
Posts: 85
Joined: 22-April 06
From: Mexico, D.F.
Member No.: 208



Pues tambien lo podrias hacer asi, no se si ese array lo vayas a ocupar para otra cosa, la diferencia entre lo mio y lo de marioly es que este es mas flexible ya que en la estructura puedes agregar y quitar variables, pero como te digo, no se como lo vayas a utilizar entonces aki tienes otra opcion...:

namespace:

using System.Collections.Generic;

Codigo:

//CREAS UNA ESTRUCTURA

public struct LabelInfo
{
public string text;
public int x;
public int y;
}

//ESTE CODIGO LO USAS DENTRO DE UN METODO PARA CREAR UNA COLECCION GENERICA

List<LabelInfo> lblInfoCollecion = new List<LabelInfo>();

LabelInfo tmpLbl = new LabelInfo();
tmpLbl.text = " testing";
tmpLbl.x = 100;
tmpLbl.y = 200;

lblInfoCollecion.Add(tmpLbl);

//ASI LO PODRIAS CONSUMIR

foreach(LabelInfo lbl in lblInfoCollecion)
{
string text = tmpLbl.text;
int x = tmpLbl.x;
int y = tmpLbl.y;
}


Saludos.

mig16

This post has been edited by mig16: Oct 15 2008, 02:51 PM


--------------------
VISITA MI BLOG DE C# DONDE ENCONTRARAS ARTICULOS GENERALES DE C#
http://mig16.cep.la
Imagen IPB
Go to the top of the page
 
+Quote Post
WhiteWolf
post Dec 1 2008, 04:47 PM
Post #4


Conociendo el foro
**


Group: Hackerss Member
Posts: 13
Joined: 11-January 07
From: D4rkS1de
Member No.: 1,666



Hi:

Muy buenos codigos, ambos excelentes, solo decir que puede ser tedioso ir label por label del array dandole coordenadas, maximo cuando son 100. Si las coordenadas tienen alguna regla(Ej:que esten a 20u entre ellas) puedes usar un for o while para recorrelo:

//Aplicado al codigo de marioly
int x=0;
int y=0;
for(int w=0; w<misLabel.Lenght; w++)
{
misLabel[w] = new Label();
misLabel[w].Size = new System.Drawing.Size(33, 33);
misLavel[w].Location = new System.Drawing.Point(x, y);
x+=20;
y+=20;
}

El codigo de mig16 depende de que la version de Framework que uses soporte Genericidad. Si usas VS.Net 2005 o superior no tienes problemas .....

wink.gif


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 

- Lo-Fi Version Time is now: 7th January 2009 - 11:36 AM