Hello,

I derived from System.Windows.Forms.Button and added a couple of properties
and overrided a single method, OnParentChanged, in order to reset one
property.

For an unknown reason, the control does not render correctly on the form.
The control is there (I can see the dashed outline), but I cannot interact
with it unless I select it with the help of the control dropdownlist in the
property toolbar. Even worse, I also cannot see it at runtime ?!

I tried adding base class attributes to my control, but it changes nothing.
If I only derive and do nothing else, then it works as expected. I fail to
see what can cause the problem I am seeing. Anybody could help me there ?

Here is the complete code of my new control:


using System;
using System.Windows.Forms;

using Foo.Security.Management;

namespace Foo.UI.WinForms.Controls.Securized
{
/// <summary>
/// Represents a securizable Button.
/// </summary>
public class SecurizedButton
 : Button, ISecurizable
{
 #region Fields

 /// <summary>
 /// Contains the control permissions.
 /// </summary>
 private Permissions _permissions;

 /// <summary>
 /// Contains a value indicating whether this securizable item inherits
permissions from its parent.
 /// </summary>
 private bool _inherits = true;

 /// <summary>
 /// Contains the cached unique ID.
 /// </summary>
 private string _cachedUniqueId;

 #endregion

 #region Constructors

 /// <summary>
 /// Initializes a new instance of the <see cref="SecurizedButton"/> class.
 /// </summary>
 public SecurizedButton()
  : base()
 {
 }

 #endregion

 #region Overrides

 /// <summary>
 /// Raises the <see cref="ParentChanged"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing
the event data.</param>
 protected override void OnParentChanged(EventArgs e)
 {
  base.OnParentChanged(e);

  _cachedUniqueId = null;
 }

 #endregion

 #region ISecurizable Members

 /// <summary>
 /// Returns the source ID of the securizable item.
 /// </summary>
 /// <value>The source ID of the securizable item.</value>
 public string SourceId
 {
  get
  {
   if (_cachedUniqueId == null)
    _cachedUniqueId = SecurizableHelper.GetSourceId(this);

   return _cachedUniqueId;
  }
 }

 /// <summary>
 /// Gets or sets the permissions.
 /// </summary>
 /// <value>The permissions.</value>
 public Permissions Permissions
 {
  get
  {
   return _permissions;
  }
  set
  {
   SecurizableHelper.SetPermissions(this, value);
   _permissions = value;
  }
 }

 /// <summary>
 /// Gets or sets a value indicating whether this securizable item inherits
permissions from its parent.
 /// </summary>
 /// <value>
 ///  <see langword="true"/> if this securizable item inherits permissions
from its parent; otherwise, <see langword="false"/>.
 /// </value>
 public bool Inherits
 {
  get
  {
   return _inherits;
  }
  set
  {
   _inherits = value;
  }
 }

 #endregion
}
}

--
Sébastien
www.sebastienlorion.com

Reply via email to