Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:42:01+00:00 2026-06-13T18:42:01+00:00

I’m still a bit green on C# so please forgive me if I’m asking

  • 0

I’m still a bit green on C# so please forgive me if I’m asking the question in the wrong way.

I’m writing a windows Forms program. I have a form with a Tab control on it. Inside the Tab control on one of the tabs is a FlowlayoutPanel control
I have a class with various properties. This class represents the data on a contacts card, i.e. Name Address, Phone etc. and is designed to look like a Panel control. Here is some code:

public class clsContactCard
{
#region Fields (8) 

    private Color _backColour;
    private BorderStyle _borderStyle;
    private List<string> _detailLines = new List<string>();
    private Color _foreColour;
    private Size _size;
    private string _subTitle;
    private string _title;

#endregion Fields 

#region Constructors (1) 

    public clsContactCard()
    {}

#endregion Constructors 

#region Properties (8) 

    public Color BackColour
    {
        get { return _backColour; }
        set { _backColour = value; }
    }

    public BorderStyle BorderStyle
    {
        get { return _borderStyle; }
        set { _borderStyle = value; }
    }

    public List<string> DetailLines
    {
        get { return _detailLines; }
        set { _detailLines = value; }
    }

    public Color ForeColour
    {
        get { return _foreColour; }
        set { _foreColour = value; }
    }

    public Size Size
    {
        get { return _size; }
        set { _size = value; }
    }

    public string SubTitle
    {
        get { return _subTitle; }
        set { _subTitle = value; }
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }

#endregion Properties 

    public Panel CreateCard()
    {
        // New Contact Card  
        Point labelLoc = new Point(18, 11);             //Location for a label
        Size labelSize = new Size(218, 16);             //default label size

        Panel pnl = new Panel();                        //Instantiate a new Panel
        pnl.BackColor = _backColour;                    //Set the new panel's properties
        pnl.BorderStyle = _borderStyle;
        pnl.Size = _size;
        pnl.Visible = true;

        //Title
        Label l = new Label();                          //Create new label object
        l.Name = "uxTitle";                             //Give it a name
        l.Text = _title;                                //Assign it data from properties
        l.Size = labelSize;                             //set its size & font
        l.Font = new Font("Microsoft Sans Serif",10,FontStyle.Bold);
        l.Location = labelLoc;                          //set its location
        labelLoc.Y += labelSize.Height;                 //update next labels location
        pnl.Controls.Add(l);                            //add label to panel controls

        //Type
        //Label l = new Label();
        l.Name = "uxSubTitle";
        l.Text = _subTitle;
        l.Size = new Size(215, 15);
        l.Font = new Font("Microsoft Sans Serif",7,FontStyle.Regular);
        l.Location = new Point(21, 27);
        labelLoc.Y += labelSize.Height + 5;

        //Detail lines
        int lineCount = 0;
        bool firstPhone = true;

        foreach (string line in _detailLines)
        {
            if (SAPSCommon.Instance.IsNumeric(line.Trim()) && firstPhone)
            {
                firstPhone = false;
                labelLoc.Y += 5;
            }
            lineCount += 1;
            //Label l = new Label();
            l.Name = "uxLine" + lineCount;
            l.Text = line;
            l.Size = labelSize;
            l.Font = new Font("Microsoft Sans Serif",8,FontStyle.Regular);
            l.Location = labelLoc;
            labelLoc.Y += labelSize.Height + 5;
        }
        return pnl;
    }
}

The idea is to show the card object in a FlowLayoutPanel control akin to MS Outlook contacts list. I have the code to populate the object properties, but when I try to add the card object (panel) to the FlowlayoutPanel control the compiler complains about the types:

Error 2 Argument 1: cannot convert from ‘SAPS.clsContactCard’ to ‘System.Windows.Forms.Control’

The code is a s follows:

foreach (clsContacts contact in _pensioner.Contacts)
{
    clsContactCard card = new clsContactCard();
    if (contact.OtherNames != "")
    {
        card.Title = string.Format("{0} {1} {2}", contact.Givname, contact.OtherNames,
                                   contact.Surname);
    }
    else
    {
        card.Title = string.Format("{0} {1}", contact.Givname, contact.Surname);
    }
    card.SubTitle = contact.ContactTypeDescription;
    card.DetailLines.Add(contact.Addr1);
    string addr2 = contact.Addr2;
    if (addr2.Length >= 0) 
        card.DetailLines.Add(addr2);
    card.DetailLines.Add(string.Format("{0} {1} {2}", contact.Suburb, contact.State, contact.PCode).Trim());
    string country = contact.Country;
    if (country.Length >= 0)
        card.DetailLines.Add(country);
    foreach(clsPhoneNumbers phone in contact.PhoneNumbers)
    {
        card.DetailLines.Add(string.Format("{0} - {1}", phone.PhoneNumber, phone.PhoneType));
    }
    foreach(clsEmailAddresses email in contact.EmailAddresses)
    {
        card.DetailLines.Add(string.Format("{0} - {1}", email.EmailAddress, email.EmailType));
    }
    card.CreateCard();

    uxContactDetsFlp.Controls.Add(card);
}

Can anyone shed a light on what I’m doing wrong and how to fix it? I thought the panel control could be added to the flowlayout panel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:42:02+00:00Added an answer on June 13, 2026 at 6:42 pm

    You can not add anything else that is not a control to container control like FlowLayoutPanel. You should instead add the panel itself rather than the card object. Do it like this:

    Panel pnl = card.CreateCard();
    pnl.Tag = card; //optional
    uxContactDetsFlp.Controls.Add(pnl);
    

    Additionally you can Tag the panel with the card object if you have to retrieve the card object later on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.