Custom controls subclassing System.Windows.Forms.Control or UserControl?
By : user2932413
Date : March 29 2020, 07:55 AM
|
How to extend control events IExtenderProvider?
By : user3423231
Date : March 29 2020, 07:55 AM
hop of those help? The SetErrorText method is your key. You need to keep a List<> of controls for which you have error text. You add the control to the list in SetErrorText when it is not already in the list. And subscribe its Validating event. You remove it from the list when the value argument is null or empty. And unsubscribe the event. This is well explained in the MSDN Library article for IExtenderProvider, check the code for the SetHelpText() method in the example given there. There's a problem in the way you do it, a control could set the error text but not the ErrorProvider. Or the other way around, neither is good. It is best to keep your own ErrorProvider as a private member of your class or assignable through a property. One is enough.
|
Hide child controls in UserControl with another control
By : anax32
Date : March 29 2020, 07:55 AM
this will help I am writing a custom control deriving from UserControl. In it are some controls that I want to prevent from being accessible (some textboxes, comboboxes). They are to become available for interacting only when the user clicks an 'Edit' button. , You can write your's Enabled property in your UserControl and use it. code :
private new bool Enabled
{
get { return _enabled; }
set
{
foreach (System.Windows.Forms.Control c in this.Controls)
{
if (c is SomeTypeThatShouldBeExcluded)
continue;
c.Enabled = value;
}
_enabled = value;
}
}
|
Base UserControl with controls - incorrect alignment in derived control
By : Ashlesha Kshirsagar
Date : March 29 2020, 07:55 AM
seems to work fine You can use a Panel as container of buttons In BasePanel. Then set Dock property of panel to Top and put your Button controls in the panel and set their Anchor property to Top, Right. This way, when you inherit from BasePanel, all controls including the container panel and buttons are private and can not be edited, but the designer respects to positioning of controls. code :
public BasePanel()
{
InitializeComponent();
TypeDescriptor.AddAttributes(this.panel1, new DesignerAttribute(typeof(object)));
TypeDescriptor.AddAttributes(this.button1, new DesignerAttribute(typeof(object)));
TypeDescriptor.AddAttributes(this.button2, new DesignerAttribute(typeof(object)));
TypeDescriptor.AddAttributes(this.button3, new DesignerAttribute(typeof(object)));
TypeDescriptor.AddAttributes(this.button4, new DesignerAttribute(typeof(object)));
}
|
Binding click events of all UserControl's controls to single event on parent Control
By : Pete R.
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am trying to implement an event handler for my user control that triggers a click whenever any control inside the user control or the user control itself is clicked. , Okay I figured out another way of doing this: code :
Action clickAction;
public Action CardClickAction
{
get
{
return clickAction;
}
set
{
Action x;
if (value == null)
{
x = () => { };
}
else
x = value;
clickAction = x;
pictureBox1.Click += new EventHandler((object sender, EventArgs e) =>
{
x();
});
label2.Click+= new EventHandler((object sender, EventArgs e) =>
{
x();
});
tableLayoutPanel3.Click += new EventHandler((object sender, EventArgs e) =>
{
x();
});
}
}
Card1.CardClickAction = new Action(() =>
{
//your code to execute when user control is clicked
});
|