Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: Coding music rhythms Pin
PIEBALDconsult30-Sep-14 10:52
mvePIEBALDconsult30-Sep-14 10:52 
AnswerRe: Coding music rhythms Pin
Bassam Abdul-Baki3-Oct-14 5:57
professionalBassam Abdul-Baki3-Oct-14 5:57 
AnswerRe: Coding music rhythms Pin
Bassam Abdul-Baki3-Oct-14 7:19
professionalBassam Abdul-Baki3-Oct-14 7:19 
AnswerRe: Coding music rhythms Pin
Bassam Abdul-Baki5-Oct-14 11:42
professionalBassam Abdul-Baki5-Oct-14 11:42 
QuestionHow to prevent a child control to be added in usercontrol Pin
Phil Thomson24-Sep-14 4:43
Phil Thomson24-Sep-14 4:43 
AnswerRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff24-Sep-14 6:11
professionalBillWoodruff24-Sep-14 6:11 
GeneralRe: How to prevent a child control to be added in usercontrol Pin
Phil Thomson24-Sep-14 6:49
Phil Thomson24-Sep-14 6:49 
AnswerRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff24-Sep-14 21:41
professionalBillWoodruff24-Sep-14 21:41 
Let me do a little reality check and make sure we are talking about the same thing Smile | :)

1. you created your UserControl by creating a new WindowsFormsControlLibrary Project whose compiled output is a Class Library (dll)

2. the way you expect users of your UserControl to use it at design-time in their projects is by setting a reference to it in the Project/References, then installing it in the ToolBox in the usual way, and then drag-dropping it on to a Form from the ToolBox.

3. all this is working fine now ... you've tested this.

4. you understand that any Control drag-dropped from the ToolBox, and dropped inside the bounds of an instance of your UserControl on some other user's Form, will never be added to your UserControl's Control Collection. In fact there is a way to modify your UserControl to allow other Controls to be added by drag-drop at design-time, but I assume that's not of interest to you right now.

If all this is correct, then the only way a user could add new Controls to the instance of your UserControl, would be in code, and in your code you can add an EventHandler for 'ControlAdded:
C#
private void UserControl1_ControlAdded(object sender, ControlEventArgs e)
{
    Control controlAdded = e.Control;

    if (e.Control.GetType() != typeof (Button))
    {
        this.Controls.Remove(controlAdded);

        // for testing only
        MessageBox.Show("bad add: UC Controls count = " + this.Controls.Count.ToString());
    }
}
To reverse the addition of any Control whose Type is not 'Button.

I don't like this technique ... it's a smelly hack ... but, it does work; I'd like to see a better way to do this where any Control could be prevented from being added to the UserControl.

My hope is that the questions asked here, and the brief code example, will, at least, lead to your clarifying exactly what you want to achieve ... since I'm still not sure I understand that fully Smile | :)
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

GeneralRe: How to prevent a child control to be added in usercontrol Pin
Phil Thomson25-Sep-14 10:01
Phil Thomson25-Sep-14 10:01 
GeneralRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff25-Sep-14 20:46
professionalBillWoodruff25-Sep-14 20:46 
QuestionHow to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee24-Sep-14 4:23
professionalTridip Bhattacharjee24-Sep-14 4:23 
SuggestionRe: How to stop exposing multiple endpoint at client side in WCF Pin
Richard MacCutchan24-Sep-14 5:33
mveRichard MacCutchan24-Sep-14 5:33 
AnswerRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford24-Sep-14 5:43
professionalDominic Burford24-Sep-14 5:43 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee24-Sep-14 21:35
professionalTridip Bhattacharjee24-Sep-14 21:35 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford25-Sep-14 1:24
professionalDominic Burford25-Sep-14 1:24 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee25-Sep-14 2:39
professionalTridip Bhattacharjee25-Sep-14 2:39 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford25-Sep-14 3:57
professionalDominic Burford25-Sep-14 3:57 
Questionerror: "Not a legal OleAut"when importing Excel2007 into SQL Pin
Member 245846723-Sep-14 21:51
Member 245846723-Sep-14 21:51 
AnswerRe: error: "Not a legal OleAut"when importing Excel2007 into SQL Pin
Bernhard Hiller24-Sep-14 20:56
Bernhard Hiller24-Sep-14 20:56 
QuestionRegarding a basic question about Serialization Pin
Tridip Bhattacharjee23-Sep-14 21:26
professionalTridip Bhattacharjee23-Sep-14 21:26 
AnswerRe: Regarding a basic question about Serialization PinPopular
Eddy Vluggen23-Sep-14 21:50
professionalEddy Vluggen23-Sep-14 21:50 
AnswerRe: Regarding a basic question about Serialization Pin
George Jonsson24-Sep-14 18:14
professionalGeorge Jonsson24-Sep-14 18:14 
AnswerRe: Regarding a basic question about Serialization Pin
Sibeesh KV24-Sep-14 18:43
professionalSibeesh KV24-Sep-14 18:43 
Questionusing Peachtree API in C# Pin
Jassim Rahma23-Sep-14 11:08
Jassim Rahma23-Sep-14 11:08 
AnswerRe: using Peachtree API in C# Pin
jschell23-Sep-14 11:58
jschell23-Sep-14 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.