Foros del Web » Programación para mayores de 30 ;) » .NET »

Tamaño de imagenes en nodo de un tree view

Estas en el tema de Tamaño de imagenes en nodo de un tree view en el foro de .NET en Foros del Web. Saludos a todos. la pregunta es la siguiente... estoy usando un treeview en c# con imaganes. he utilizado un imagenList y la propiedad del treeview ...
  #1 (permalink)  
Antiguo 02/03/2009, 11:19
Avatar de joselowolf  
Fecha de Ingreso: octubre-2008
Mensajes: 22
Antigüedad: 15 años, 6 meses
Puntos: 1
Tamaño de imagenes en nodo de un tree view

Saludos a todos.
la pregunta es la siguiente...

estoy usando un treeview en c# con imaganes. he utilizado un imagenList y la propiedad del treeview stateimagelist.

cuando uso esta propiedad las imagenes se me redimenciona a un 16x16 y los iconos que uso son de 32x32. se ven muy pequeñas.

encambio cuando uso la propiedad imagelist: las imagenes son de tamaño correcto pero se me agregan a todos los nodos por lo menos una imagen por defecto.

en mi programa no todos los nodos deben tener imagen.

que debo hacer, gracias

Última edición por joselowolf; 02/03/2009 a las 11:25 Razón: no especifique en que lenguaje
  #2 (permalink)  
Antiguo 03/03/2009, 15:25
Avatar de joselowolf  
Fecha de Ingreso: octubre-2008
Mensajes: 22
Antigüedad: 15 años, 6 meses
Puntos: 1
De acuerdo Respuesta: Tamaño de imagenes en nodo de un tree view

Bueno me voy a responder para quien le interese...
paso 1.- Crear un control heredado de un treeView
paso 2. set la propiedad ItemHeight a la altura de la imagenes
paso 3.- escribir el siguiente codigo
private Rectangle CalcularBoundsNodo(TreeNode Nodo)
{
Rectangle rec = Nodo.Bounds;
Graphics g = this.CreateGraphics();
int TextWidth = (int)g.MeasureString(Nodo.Text, Nodo.NodeFont).Width + 26 - rec.Size.Width;
Point loc = rec.Location;
rec.Inflate(TextWidth, 0);
rec.Offset(loc.X - rec.X, 0);
g.Dispose();

return rec;

}
private GraphicsPath PathBackcolorGrupos(Rectangle Rec)
{

GraphicsPath gp = new GraphicsPath();
Rectangle r = new Rectangle(2, Rec.Y + 3, this.Width - 25, Rec.Height - 10);

int radius = 10;

gp.AddArc(r.Left, r.Top, radius, radius, 180, 90);
gp.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
gp.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90);
gp.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90);
gp.CloseFigure();

return gp;

}
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{



// e.DrawDefault = true;
Rectangle Rec = CalcularBoundsNodo(e.Node);

if ((e.State & TreeNodeStates.Selected) != 0)
{

// e.Graphics.FillRectangle(Brushes.Brown, Rec);

// // Color Color1 = Color.FromArgb(176, 216, 228);
// //Color Color2 = Color.FromArgb(72, 72, 172);

Color Color1 = Color.White;
Color Color2 = Color.Teal;
LinearGradientBrush brocha = new LinearGradientBrush(Rec, Color1, Color2, LinearGradientMode.Vertical);
// brocha.GammaCorrection = true;
GraphicsPath Objeto = PathBackcolorGrupos(Rec);
e.Graphics.FillPath(brocha, Objeto);

e.Graphics.DrawPath(new Pen(Brushes.Teal), Objeto);



// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = this.Font;

//Dibuja imagen de collapse y expand y sea del grupo principal

if (e.Node.Parent == null)
{
Font fontExpand = new Font("marlett", 10, GraphicsUnit.Point);
Rectangle rectText1 = new Rectangle(new Point(0, Rec.Y + 8), new Size(15, 15));
if (e.Node.IsExpanded)
e.Graphics.DrawString("4", fontExpand, Brushes.Black, rectText1);
else
e.Graphics.DrawString("6", fontExpand, Brushes.Black, rectText1);
fontExpand.Dispose();
}
else
{//dibuja la presencia de la imagen
Rec.Offset(30, 0);
if (e.Node.StateImageIndex != -1)
{

Image Imagen = this.StateImageList.Images[e.Node.StateImageIndex];
Point Posimage = new Point(Rec.X - 30, Rec.Y);
e.Graphics.DrawImage(Imagen, Posimage);
}
}


// Dibuja Texto
Point loc = new Point(Rec.X, Rec.Y + 5);
Rectangle rectText = new Rectangle(loc, Rec.Size);
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, rectText);


}
else
{
// e.DrawDefault = true;

Rectangle RecNodo = new Rectangle(0, Rec.Y, this.Width, Rec.Height);
e.Graphics.FillRectangle(Brushes.White, RecNodo);
//dibuja el backcolor de los grupos
#region dibuja el backcolor de los grupos
//if (e.Node.Parent == null)
//{
// // Color Color1 = Color.FromArgb(176, 216, 228);
// //Color Color2 = Color.FromArgb(72, 72, 172);

// Color Color1 = Color.White;
// Color Color2 = Color.Teal;
// LinearGradientBrush brocha = new LinearGradientBrush(Rec, Color1, Color2,LinearGradientMode.Vertical);
// // brocha.GammaCorrection = true;
// GraphicsPath Objeto = PathBackcolorGrupos(Rec);
// e.Graphics.FillPath(brocha, Objeto);

// e.Graphics.DrawPath(new Pen(Brushes.Teal), Objeto);



//}
#endregion
// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = this.Font;

//Dibuja imagen de collapse y expand y sea del grupo principal
#region para poner el expand y collap con una imagen
//if (e.Node.Parent == null && imageList2.Images.Count != 0)
// if (e.Node.IsExpanded)
// {
// Image Imagen = imageList2.Images[1];
// Point Posimage = new Point(Rec.X - 11, Rec.Y + 8);
// e.Graphics.DrawImage(Imagen, Posimage);

// }
// else
// {
// Image Imagen = imageList2.Images[0];
// Point Posimage = new Point(Rec.X - 11, Rec.Y + 8);
// e.Graphics.DrawImage(Imagen, Posimage);
// }
#endregion
if (e.Node.Parent == null)
{
Font fontExpand = new Font("marlett", 10, GraphicsUnit.Point);
Rectangle rectText1 = new Rectangle(new Point(0, Rec.Y + 8), new Size(15, 15));
if (e.Node.IsExpanded)
e.Graphics.DrawString("4", fontExpand, Brushes.Black, rectText1);
else
e.Graphics.DrawString("6", fontExpand, Brushes.Black, rectText1);
fontExpand.Dispose();
}
else
{
//dibuja la presencia de la imagen
Rec.Offset(30, 0);
if (e.Node.StateImageIndex != -1)
{
Image Imagen = this.StateImageList.Images[e.Node.StateImageIndex];
Point Posimage = new Point(Rec.X - 30, Rec.Y);
e.Graphics.DrawImage(Imagen, Posimage);
}
}

// Dibuja Texto
Point loc = new Point(Rec.X, Rec.Y + 5);
Rectangle rectText = new Rectangle(loc, Rec.Size);
SolidBrush BrochaTexto = new SolidBrush(e.Node.ForeColor);
e.Graphics.DrawString(e.Node.Text, nodeFont, BrochaTexto, rectText);

}
}


nota: el ejemplo esta aplicado a un ejercicio en especifico.
Suerte
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 04:35.