Hallo liebe Community,
ich habe ein Problem mit meinem UserControl, wo Ihr vielleicht eine Erklärung dafür parat habt.
Mein UserControl besteht im Prinzip aus 2 Labels.
Um diese 2 Labels beschreiben zu können, habe ich 2 Properties vom Typ
Verweis auf
Das UserControl:
Spoiler anzeigen
Und der Designer-Teil:
Spoiler anzeigen
Mein Problem ist nun, dass sich beide Properties, also Title und Description immer wieder zurücksetzen, wenn ich das Projekt neu kompiliere oder starte...
Weiß jemand, warum
ich habe ein Problem mit meinem UserControl, wo Ihr vielleicht eine Erklärung dafür parat habt.
Mein UserControl besteht im Prinzip aus 2 Labels.
Um diese 2 Labels beschreiben zu können, habe ich 2 Properties vom Typ
String
angelegt.Verweis auf
System.Design
erforderlich.Das UserControl:
C#-Quellcode
- [Designer(typeof(WindowsTitleDesigner))]
- public partial class WindowsTitle : UserControl
- {
- public WindowsTitle()
- {
- InitializeComponent();
- Dock = DockStyle.Top;
- }
- [EditorBrowsable(EditorBrowsableState.Always )]
- [Browsable(true)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- public string Title
- {
- get { return lblTitle.Text; }
- set { lblTitle.Text = value; }
- }
- [EditorBrowsable( EditorBrowsableState.Always )]
- [Browsable( true )]
- [DesignerSerializationVisibility( DesignerSerializationVisibility.Content )]
- public string Description
- {
- get { return lblDescription.Text; }
- set { lblDescription.Text = value; }
- }
- }
- public class Line : Control
- {
- public Line()
- {
- SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true );
- lineColor = Color.Black;
- LineAlignment = Alignment.Horizontal;
- Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
- Size = new Size( 250, 1 );
- }
- public enum Alignment
- {
- Vertical,
- Horizontal,
- }
- private Color lineColor;
- private Alignment lineAlignment;
- public Color LineColor
- {
- get { return lineColor; }
- set
- {
- lineColor = value;
- Invalidate();
- }
- }
- public Alignment LineAlignment
- {
- get { return lineAlignment; }
- set
- {
- lineAlignment = value;
- Invalidate();
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint( e );
- if (lineAlignment == Alignment.Horizontal)
- e.Graphics.DrawLine( new Pen( new SolidBrush( lineColor ), 1 ), new Point( 0, Height / 2 ), new Point( Width, Height / 2 ) );
- else if (lineAlignment == Alignment.Vertical)
- e.Graphics.DrawLine( new Pen( new SolidBrush( lineColor ), 1 ), new Point( 0, Height / 2 ), new Point( 0, Height / 2 ) );
- }
- protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
- {
- base.SetBoundsCore( x, y, width, height, specified );
- }
- }
- public class WindowsTitleDesigner : System.Windows.Forms.Design.ControlDesigner
- {
- #region variables
- private DesignerActionListCollection lists;
- #endregion
- #region callbacks
- public override DesignerActionListCollection ActionLists
- {
- get
- {
- if (lists == null)
- {
- lists = new DesignerActionListCollection
- {
- new WindowsTitleActionList( this.Component )
- };
- }
- return lists;
- }
- }
- #endregion
- }
- public class WindowsTitleActionList : DesignerActionList
- {
- #region constructor
- public WindowsTitleActionList(IComponent component) : base( component )
- {
- _ctrl = (WindowsTitle)component;
- this.designerActionSvc = (DesignerActionUIService)GetService( typeof( DesignerActionUIService ) );
- }
- #endregion
- #region variables
- private readonly WindowsTitle _ctrl;
- private readonly DesignerActionUIService designerActionSvc = null/* TODO Change to default(_) if this is not a reference type */;
- #endregion
- #region properties
- public string Title
- {
- get
- {
- return _ctrl.Title;
- }
- set
- {
- _ctrl.Title = value;
- }
- }
- public string Description
- {
- get
- {
- return _ctrl.Description;
- }
- set
- {
- _ctrl.Description = value;
- }
- }
- #endregion
- #region callbacks
- public override System.ComponentModel.Design.DesignerActionItemCollection GetSortedActionItems()
- {
- DesignerActionItemCollection items = new DesignerActionItemCollection();
- //items.Add( new DesignerActionHeaderItem( "--- ActionList ---" ) );
- items.Add( new DesignerActionHeaderItem( "Eigenschaften" ) );
- items.Add( new DesignerActionPropertyItem( "Title", "Titel:", "Eigenschaften", "Der anzuzeigende Titel." ) );
- items.Add( new DesignerActionPropertyItem( "Description", "Beschreibung:", "Eigenschaften", "Die anzuzeigende Beschreibung." ) );
- return ( items );
- }
- #endregion
- }
Und der Designer-Teil:
C#-Quellcode
- partial class WindowsTitle
- {
- /// <summary>
- /// Erforderliche Designervariable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Verwendete Ressourcen bereinigen.
- /// </summary>
- /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && ( components != null ))
- {
- components.Dispose();
- }
- base.Dispose( disposing );
- }
- #region Vom Komponenten-Designer generierter Code
- /// <summary>
- /// Erforderliche Methode für die Designerunterstützung.
- /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
- /// </summary>
- private void InitializeComponent()
- {
- this.lblDescription = new System.Windows.Forms.Label();
- this.lblTitle = new System.Windows.Forms.Label();
- this.line2 = new Line();
- this.SuspendLayout();
- //
- // lblDescription
- //
- this.lblDescription.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.lblDescription.AutoEllipsis = true;
- this.lblDescription.Location = new System.Drawing.Point(12, 39);
- this.lblDescription.Name = "lblDescription";
- this.lblDescription.Size = new System.Drawing.Size(221, 33);
- this.lblDescription.TabIndex = 6;
- this.lblDescription.Text = "Description";
- //
- // lblTitle
- //
- this.lblTitle.AutoSize = true;
- this.lblTitle.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(51)))), ((int)(((byte)(153)))));
- this.lblTitle.Location = new System.Drawing.Point(12, 12);
- this.lblTitle.Name = "lblTitle";
- this.lblTitle.Size = new System.Drawing.Size(39, 21);
- this.lblTitle.TabIndex = 7;
- this.lblTitle.Text = "Title";
- //
- // line2
- //
- this.line2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.line2.LineAlignment = Line.Alignment.Horizontal;
- this.line2.LineColor = System.Drawing.Color.Gainsboro;
- this.line2.Location = new System.Drawing.Point(12, 75);
- this.line2.Name = "line2";
- this.line2.Size = new System.Drawing.Size(221, 1);
- this.line2.TabIndex = 8;
- this.line2.Text = "line2";
- //
- // WindowsTitle
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.Color.White;
- this.Controls.Add(this.lblDescription);
- this.Controls.Add(this.lblTitle);
- this.Controls.Add(this.line2);
- this.Name = "WindowsTitle";
- this.Size = new System.Drawing.Size(245, 78);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.Label lblDescription;
- private System.Windows.Forms.Label lblTitle;
- private Line line2;
- }
Mein Problem ist nun, dass sich beide Properties, also Title und Description immer wieder zurücksetzen, wenn ich das Projekt neu kompiliere oder starte...
Weiß jemand, warum
Dieser Beitrag wurde bereits 7 mal editiert, zuletzt von „TRiViUM“ ()