Click here to Skip to main content
15,886,732 members
Home / Discussions / C#
   

C#

 
AnswerRe: C sharp / mysql saving a blob variable into mysql Database Pin
Eddy Vluggen30-Nov-18 2:13
professionalEddy Vluggen30-Nov-18 2:13 
QuestionUsercontrol poser ( rusty Winforms guy ) Pin
pkfox29-Nov-18 4:16
professionalpkfox29-Nov-18 4:16 
AnswerRe: Usercontrol poser ( rusty Winforms guy ) Pin
OriginalGriff29-Nov-18 4:49
mveOriginalGriff29-Nov-18 4:49 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
pkfox29-Nov-18 5:24
professionalpkfox29-Nov-18 5:24 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
OriginalGriff29-Nov-18 5:32
mveOriginalGriff29-Nov-18 5:32 
AnswerRe: Usercontrol poser ( rusty Winforms guy ) Pin
BillWoodruff1-Dec-18 16:52
professionalBillWoodruff1-Dec-18 16:52 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
pkfox1-Dec-18 21:04
professionalpkfox1-Dec-18 21:04 
AnswerRe: Usercontrol poser ( rusty Winforms guy ) Pin
BillWoodruff2-Dec-18 0:43
professionalBillWoodruff2-Dec-18 0:43 
Okay, keeping in mind what OriginalGriff said about not being able to move sub-classed Controls at design-time ... or edit any of their properties ...

By "publishing" a data structure that exposes the run-time created Controls: you can modify them any way you like. I prefer to create a Dictionary<string, Control> ... and, here's how I do that: note the code you see here uses Extension methods in the 'ControlExtensions class appended to this post ... depending on task at hand, I may want only to expose the top-level Controls, or I may want to recurse to get nested Controls.

Example: In the sub-classed UserControl Load EventHandler:
public Dictionary<string, Control> ControlDict;

private void SubClassOfBaseUserControl_Load(object sender, t[EventArgs e)
{
    ControlDict = this.Controls.FindAll();

    // assuming 'button1 is a valid name for a Control on the UserControl
    ControlDict["button1"].Text - "changed."
}
The limits of this are, of course, that you can't access the unique properties of Controls ... those which are not inherited from Control ... unless you up-cast back to their native Type. That's as simple as using 'as, or as complex as using reflection when you don't know the Type to up-cast to.

Hope this helps, and I;m not saying you should do things this way. cheers, Bill
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace YourNameSpace
{
    public static class ControlExtensions
    {
        public static Dictionary<string, Control> FindAll(this Control.ControlCollection controls, bool recurse = true)
        {
            if (recurse)
            {
                return GetAllControls(controls).ToDictionary(c => c.Name, c => c); ;
            }
            else
            {
                return controls.Cast<Control>()
                    .ToDictionary(c => c.Name, c => c);
            }
        }

        public static IEnumerable<Control> GetAllControls(Control.ControlCollection controls)
        {
            Stack<Control> stack = new Stack<Control>(controls.Cast<Control>().ToArray());

            while (stack.Any())
            {
                var nextControl = stack.Pop();

                foreach (Control childControl in nextControl.Controls)
                {
                    stack.Push(childControl);
                }

                yield return nextControl;
            }
        }
    }
}

«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
pkfox2-Dec-18 3:48
professionalpkfox2-Dec-18 3:48 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
BillWoodruff2-Dec-18 4:06
professionalBillWoodruff2-Dec-18 4:06 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
pkfox2-Dec-18 6:03
professionalpkfox2-Dec-18 6:03 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
BillWoodruff2-Dec-18 6:51
professionalBillWoodruff2-Dec-18 6:51 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
BillWoodruff2-Dec-18 18:57
professionalBillWoodruff2-Dec-18 18:57 
GeneralRe: Usercontrol poser ( rusty Winforms guy ) Pin
pkfox2-Dec-18 19:21
professionalpkfox2-Dec-18 19:21 
QuestionRead and write JSON in c# WinForms Pin
jkirkerx28-Nov-18 13:20
professionaljkirkerx28-Nov-18 13:20 
AnswerRe: Read and write JSON in c# WinForms Pin
OriginalGriff28-Nov-18 19:39
mveOriginalGriff28-Nov-18 19:39 
GeneralRe: Read and write JSON in c# WinForms Pin
jkirkerx29-Nov-18 8:51
professionaljkirkerx29-Nov-18 8:51 
AnswerRe: Read and write JSON in c# WinForms Pin
Mc_Topaz28-Nov-18 20:05
Mc_Topaz28-Nov-18 20:05 
GeneralRe: Read and write JSON in c# WinForms Pin
jkirkerx29-Nov-18 8:49
professionaljkirkerx29-Nov-18 8:49 
AnswerRe: Read and write JSON in c# WinForms Pin
Richard Deeming29-Nov-18 1:09
mveRichard Deeming29-Nov-18 1:09 
GeneralRe: Read and write JSON in c# WinForms Pin
jkirkerx29-Nov-18 9:47
professionaljkirkerx29-Nov-18 9:47 
AnswerRe: Read and write JSON in c# WinForms Pin
jkirkerx29-Nov-18 9:46
professionaljkirkerx29-Nov-18 9:46 
AnswerI finally got it Pin
jkirkerx29-Nov-18 10:42
professionaljkirkerx29-Nov-18 10:42 
QuestionGet Numbers That Make Up A Binary Number Pin
Kevin Marois28-Nov-18 5:48
professionalKevin Marois28-Nov-18 5:48 
AnswerRe: Get Numbers That Make Up A Binary Number Pin
OriginalGriff28-Nov-18 5:55
mveOriginalGriff28-Nov-18 5:55 

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.