Forms-Eigenschaftenfenster: Platzieren einer benutzerdefinierten Eigenschaft in eine SubCategory
- VB.NET
- .NET (FX) 4.5–4.8
Sie verwenden einen veralteten Browser (%browser%) mit Sicherheitsschwachstellen und können nicht alle Funktionen dieser Webseite nutzen.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von VB1963.
-
-
Hm
BorderSize
ist zum Beispiel eine Eigenschaft vonFlatButtonAppearance
nicht vonButton
; vielleicht hat das damit zutun?
Mich erinnert das ein wenig an WPF da macht man ja eine Darstellung aus einer beliebigen Klasse. Und da im Eigenschaftsfenster ja nicht der Button dargestellt ist, sondern dessen Eigenschaften wäre das so gemünzt BorderSize ja eine Darstellung der FlatAppearance und nicht des Buttons. -
-
@VB1963 Sieh Dir mal die Quellen im
IlSpy
an, ob da was verzeichnet ist.Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert! -
Achso, also ist deine
FocusBorderColor
schon eine Eigenschaft vonFlatButtonAppearance
ich dachte, die wäre in deiner Button Klasse
Mit einem Converter krieg ich einen Node im Eigenschaftsfenster erzeugt. Werden die Eigenschaft von Point ausgeschildert (X, Y), weil ich nen PointConverter geklaut habe. Aber ob man da noch Eigenschaften dazu wursteln kann... (Da Test kein Point ist meckert er da natürlich gewaltig, aber ich würde denken wenn man eine Klasse und einen Converter entsprechend bastelt, dann kann man so einen Node frei gestalten)
Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „Haudruferzappeltnoch“ ()
-
FocusedBorderColor
kann nicht Teil vonFlatAppearance
werden, daFlatAppearance
eine Klasse ist, deren Konstruktor versteckt ist, sodass man nicht davon erben kann, um die Klasse zu erweitern.
Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „VaporiZed“, mal wieder aus Grammatikgründen.
Aufgrund spontaner Selbsteintrübung sind all meine Glaskugeln beim Hersteller. Lasst mich daher bitte nicht den Spekulatiusbackmodus wechseln. -
-
Also ich hätte es so nie hingekriegt, aber mit ein bisschen Glück konnte ich es GPT entlocken, das ergibt einen CustomButton mit einer Custom Eigenschaft, die wiederum customizable Eigenschaften in einer SubCategory beinhaltet:
VB.NET-Quellcode
- Public Class CustomFlatAppearance
- <Browsable(True)>
- <Description("Die Farbe des Rahmens.")>
- Public Property BorderColor As Color
- <Browsable(True)>
- <Description("Die Größe des Rahmens.")>
- Public Property BorderSize As Integer
- End Class
- Public Class CustomFlatAppearanceConverter
- Inherits ExpandableObjectConverter
- Public Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
- If destinationType = GetType(CustomFlatAppearance) Then Return True
- Return MyBase.CanConvertTo(context, destinationType)
- End Function
- End Class
- Public Class CustomButton
- Inherits Button
- Private _customFlatAppearance As CustomFlatAppearance = New CustomFlatAppearance()
- <Browsable(True)>
- <Description("Die benutzerdefinierte Darstellung des Buttons.")>
- <TypeConverter(GetType(CustomFlatAppearanceConverter))>
- Public Property CustomFlatAppearance As CustomFlatAppearance
- Get
- Return _customFlatAppearance
- End Get
- Set(value As CustomFlatAppearance)
- _customFlatAppearance = value
- End Set
- End Property
- End Class
-
Haudruferzappeltnoch schrieb:
aber vielleicht kannst du die schlicht austauschen... -
Du könntest dir auch eine eigene
FlatButtonAppearance
Klasse, basierend auf der Originalen Klasse, erstellen.
Beispiel
C#-Quellcode
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Globalization;
- using System.Windows.Forms;
- namespace MyButton
- {
- internal sealed class ApplicableToButtonAttribute : Attribute
- {
- public ApplicableToButtonAttribute()
- {
- }
- }
- internal class FlatButtonAppearanceConverter : ExpandableObjectConverter
- {
- // Don't let the property grid display the full type name in the value cell
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string))
- {
- return "";
- }
- return base.ConvertTo(context, culture, value, destinationType);
- }
- // Don't let the property grid display the CheckedBackColor property for Button controls
- public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
- {
- if (context != null && context.Instance is Button)
- {
- Attribute[] attributes2 = new Attribute[attributes.Length + 1];
- attributes.CopyTo(attributes2, 0);
- attributes2[attributes.Length] = new ApplicableToButtonAttribute();
- attributes = attributes2;
- }
- return TypeDescriptor.GetProperties(value, attributes);
- }
- }
- [TypeConverter(typeof(FlatButtonAppearanceConverter))]
- public class FlatButtonAppearance
- {
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1)]
- public int BorderSize
- {
- get => buttonOwner.FlatAppearance.BorderSize;
- set => buttonOwner.FlatAppearance.BorderSize = value;
- }
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(typeof(Color), "")]
- public Color BorderColor
- {
- get => buttonOwner.FlatAppearance.BorderColor;
- set => buttonOwner.FlatAppearance.BorderColor = value;
- }
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true),EditorBrowsable(EditorBrowsableState.Always),DefaultValue(typeof(Color), "")]
- public Color CheckedBackColor
- {
- get => buttonOwner.FlatAppearance.CheckedBackColor;
- set => buttonOwner.FlatAppearance.CheckedBackColor = value;
- }
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true),EditorBrowsable(EditorBrowsableState.Always),DefaultValue(typeof(Color), "")]
- public Color MouseDownBackColor
- {
- get => buttonOwner.FlatAppearance.MouseDownBackColor;
- set => buttonOwner.FlatAppearance.MouseDownBackColor = value;
- }
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true),EditorBrowsable(EditorBrowsableState.Always),DefaultValue(typeof(Color), "")]
- public Color MouseOverBackColor
- {
- get => buttonOwner.FlatAppearance.MouseOverBackColor;
- set => buttonOwner.FlatAppearance.MouseOverBackColor = value;
- }
- [Browsable(true), ApplicableToButton(), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(typeof(Color), "")]
- public string MyFancyCustomFlatAppearanceProperty
- {
- get => "Change me if you can ;)";
- }
- private readonly Button buttonOwner;
- public FlatButtonAppearance(Button owner) => buttonOwner = owner ?? new Button();
- }
- }
C#-Quellcode
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace MyButton
- {
- public class MyButton : Button
- {
- [Browsable(true), Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- public new FlatButtonAppearance FlatAppearance { get; private set; }
- public MyButton() : base() => FlatAppearance = new FlatButtonAppearance(this);
- }
- }
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Fakiz“ () aus folgendem Grund: Category-Attribute ergänzt
-
-
Tags
-
Ähnliche Themen
-
flexy1994 - - Sonstige Problemstellungen
-
Controls in der Mitte der Forms
TheGameSiders - - Sonstige Problemstellungen -
Hatschi - - Sonstige Problemstellungen
-
5 Benutzer haben hier geschrieben
- VB1963 (5)
- Haudruferzappeltnoch (3)
- VaporiZed (1)
- RodFromGermany (1)
- Fakiz (1)