Click here to Skip to main content
15,889,335 members
Home / Discussions / C#
   

C#

 
Questionzooming Pin
Member 1038315926-Nov-14 20:46
Member 1038315926-Nov-14 20:46 
AnswerRe: zooming Pin
Pete O'Hanlon26-Nov-14 23:29
mvePete O'Hanlon26-Nov-14 23:29 
GeneralRe: zooming Pin
Member 1038315928-Nov-14 8:39
Member 1038315928-Nov-14 8:39 
GeneralRe: zooming Pin
Eddy Vluggen28-Nov-14 9:19
professionalEddy Vluggen28-Nov-14 9:19 
AnswerRe: zooming Pin
V.27-Nov-14 1:55
professionalV.27-Nov-14 1:55 
QuestionRemove Dynamically Created Controls Pin
Django_Untaken26-Nov-14 1:58
Django_Untaken26-Nov-14 1:58 
AnswerRe: Remove Dynamically Created Controls Pin
OriginalGriff26-Nov-14 2:38
mveOriginalGriff26-Nov-14 2:38 
AnswerRe: Remove Dynamically Created Controls Pin
BillWoodruff26-Nov-14 9:58
professionalBillWoodruff26-Nov-14 9:58 
One of the best arguments for using Generic Lists is that you do not have to deal with explicit re-sizing, and there is no effective way to remove a value from an Array except by re-sizing. Note that it wasn't until .NET FrameWork 3.5 that we had an Array 'Resize method, and that multi-dimensional Arrays cannot be re-sized.

If you re-use the same Array, and add more elements (Panels) in any given re-use, then your Array is going to grow in size, possibly, become "cluttered" as you re-use it.
C#
// in Form scope
List<Panel> m_panels = new List<Panel>();

// in the method you call to create a new Panel
Panel newPanel = new Panel();

newPanel.Name = "panel m_" + i.ToString();
newPanel.BackColor = Color.Red;
newPanel.Location = e.Location; // doing this on mouse click event
newPanel.Size = new System.Drawing.Size(12, 12);
newPanel.Visible = true;

m_panels.Add(newPanel);
panel1.Controls.Add(newPanel);

// to force an error in testing add this:
// m_panels.Add(new Panel { Name = "make an error" });

// in the method you call to clear the current Panels
for (int i = 0; i < m_panels.Count; i++)
{
    Panel panelToRemove = m_panels[i];

    // being paranoid is good !
    if (panel1.Controls.Contains(panelToRemove))
    {
        panel1.Controls.Remove(panelToRemove);
    }
    else
    {
        throw new MissingMemberException(
            string.Format("Panel: {0} in source list of Panels not in panel1.Controls", 
            panelToRemove.Name));
    }
}

// clear the List for re-use
m_panels.Clear()

«If you search in Google for 'no-one ever got fired for buying IBM:' the top-hit is the Wikipedia article on 'Fear, uncertainty and doubt'»  What does that tell you about sanity in these times?


modified 26-Nov-14 16:23pm.

QuestionImage source BitmapImage update problem Pin
massisoda25-Nov-14 22:40
massisoda25-Nov-14 22:40 
AnswerRe: Image source BitmapImage update problem Pin
M.Scheeren1-Dec-14 22:48
professionalM.Scheeren1-Dec-14 22:48 
Questionhow to retrieve only date from datetime from database Pin
Member 1126447925-Nov-14 18:54
Member 1126447925-Nov-14 18:54 
AnswerRe: how to retrieve only date from datetime from database Pin
Pete O'Hanlon25-Nov-14 19:20
mvePete O'Hanlon25-Nov-14 19:20 
SuggestionRe: how to retrieve only date from datetime from database Pin
Richard Deeming26-Nov-14 1:37
mveRichard Deeming26-Nov-14 1:37 
QuestionWindows mobile App with VS2013 C# Pin
Member 1068390225-Nov-14 8:22
Member 1068390225-Nov-14 8:22 
AnswerRe: Windows mobile App with VS2013 C# Pin
Richard MacCutchan25-Nov-14 22:24
mveRichard MacCutchan25-Nov-14 22:24 
GeneralRe: Windows mobile App with VS2013 C# Pin
Member 1068390226-Nov-14 9:58
Member 1068390226-Nov-14 9:58 
QuestionC sharp Pin
Sarita S24-Nov-14 23:50
Sarita S24-Nov-14 23:50 
AnswerRe: C sharp Pin
den2k8825-Nov-14 0:00
professionalden2k8825-Nov-14 0:00 
GeneralRe: C sharp Pin
Sarita S25-Nov-14 0:10
Sarita S25-Nov-14 0:10 
GeneralRe: C sharp Pin
den2k8825-Nov-14 0:24
professionalden2k8825-Nov-14 0:24 
GeneralRe: C sharp Pin
Nicholas Marty25-Nov-14 0:28
professionalNicholas Marty25-Nov-14 0:28 
GeneralRe: C sharp Pin
Sarita S25-Nov-14 0:35
Sarita S25-Nov-14 0:35 
GeneralRe: C sharp Pin
Eddy Vluggen25-Nov-14 0:20
professionalEddy Vluggen25-Nov-14 0:20 
AnswerRe: C sharp Pin
Eddy Vluggen25-Nov-14 0:21
professionalEddy Vluggen25-Nov-14 0:21 
AnswerRe: C sharp Pin
Simon_Whale25-Nov-14 0:23
Simon_Whale25-Nov-14 0:23 

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.