Editor de propiedes

17/02/2004 - 15:14 por karel | Informe spam
Como se puede cambiar el editor de una propiedad????
muchas gracias

Preguntas similare

Leer las respuestas

#1 Vladimir Ilich Ulianov Lenin
17/02/2004 - 15:40 | Informe spam
Como se puede cambiar el editor de una propiedad????
muchas gracias
.




Con mucho cuidado.

Y también con clases relacionadas con ComponentModel.
Mira algo así como Designer y cosas parecidas para
implementar un diseñador de propiedades personalizado.
Respuesta Responder a este mensaje
#2 pepe
27/02/2004 - 15:23 | Informe spam
Tienes que hacer una clase que herede de

UITypeEditor (O alguna de sus clases hijas, como
FileNameEditor)

En tu clase, necesitas sobrecargar algunos métodos, entre
ellos EditValue.

Ya que tu clase esté lista, especificar un atributo a la
propiedad que quieres que utilize tu editor.

//Ejemplo del editor de propiedades

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace AngleEditor
{
// This UITypeEditor can be associated with Int32,
Double and Single
// properties to provide a design-mode angle
selection interface.
public class AngleEditor :
System.Drawing.Design.UITypeEditor
{
public AngleEditor()
{
}

// Indicates whether the UITypeEditor provides a
form-based (modal) dialog,
// drop down dialog, or no UI outside of the
properties window.
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand,
Name="FullTrust")]
public override
System.Drawing.Design.UITypeEditorEditStyle GetEditStyle
(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}

// Displays the UI for value selection.
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand,
Name="FullTrust")]
public override object EditValue
(System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider, object value)
{
// Return the value if the value is not of
type Int32, Double and Single.
if( value.GetType() != typeof(double) &&
value.GetType() != typeof(float) && value.GetType() !=
typeof(int) )
return value;

// Uses the IWindowsFormsEditorService to
display a
// drop-down UI in the Properties window.
IWindowsFormsEditorService edSvc =
(IWindowsFormsEditorService)provider.GetService(typeof
(IWindowsFormsEditorService));
if( edSvc != null )
{
// Display an angle selection control and
retrieve the value.
AngleControl angleControl = new
AngleControl((double)value);
edSvc.DropDownControl( angleControl );

// Return the value in the appropraite
data format.
if( value.GetType() == typeof(double) )
return angleControl.angle;
else if( value.GetType() == typeof
(float) )
return (float)angleControl.angle;
else if( value.GetType() == typeof(int) )
return (int)angleControl.angle;
}
return value;
}

// Draws a representation of the property's value.
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand,
Name="FullTrust")]
public override void PaintValue
(System.Drawing.Design.PaintValueEventArgs e)
{
int normalX = (e.Bounds.Width/2);
int normalY = (e.Bounds.Height/2);

// Fill background and ellipse and center
point.
e.Graphics.FillRectangle(new SolidBrush
(Color.DarkBlue), e.Bounds.X, e.Bounds.Y, e.Bounds.Width,
e.Bounds.Height);
e.Graphics.FillEllipse(new SolidBrush
(Color.White), e.Bounds.X+1, e.Bounds.Y+1, e.Bounds.Width-
3, e.Bounds.Height-3);
e.Graphics.FillEllipse(new SolidBrush
(Color.SlateGray), normalX+e.Bounds.X-1,
normalY+e.Bounds.Y-1, 3, 3);

// Draw line along the current angle.
double radians = ((double)e.Value*Math.PI) /
(double)180;
e.Graphics.DrawLine( new Pen(new SolidBrush
(Color.Red), 1), normalX+e.Bounds.X, normalY+e.Bounds.Y,
e.Bounds.X+ ( normalX + (int)( (double)
normalX * Math.Cos( radians ) ) ),
e.Bounds.Y+ ( normalY + (int)( (double)
normalY * Math.Sin( radians ) ) ) );
}

// Indicates whether the UITypeEditor supports
painting a
// representation of a property's value.
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand,
Name="FullTrust")]
public override bool GetPaintValueSupported
(System.ComponentModel.ITypeDescriptorContext context)
{
return true;
}
}


// Ejemplo de su uso

public class AngleTest : UserControl
{
...
private double int_angle;

[BrowsableAttribute(true)]
[EditorAttribute(typeof(AngleEditor), typeof
(System.Drawing.Design.UITypeEditor))]
public double Angle
{
get
{ return int_angle; }
set
{ int_angle = value; }
}


}


Pepe.
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida