how to show opened form when clicking a list of forms?

Woodman 21 Reputation points
2021-10-12T10:08:12.387+00:00

I have a restaurant windows forms application
each time I click Sell in POS a new instance of frmPos is opened for a client table
when a new frmPos is opened I click to select the table number that client is using
the frmPos title change to Table number ( Table 10 for example)

My problem is when opening several tables they will be in the taskbar many and I want to easy find a table to place order again . I would like to create a list of opened tables and create column View (table #)
when I click the View it should open the opened table (table 10 for example ) that is already opened in the taskbar

please help I just need to recall or show the windows form table .
i see in taskbar the form opened table10 table 11 table 12 table6 table19
in the list i need to reopen table10 without clicking in taskbar

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,841 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,196 Reputation points
    2021-10-12T14:57:26.143+00:00

    Start off with

    var forms = Application.OpenForms.Cast<Form>().ToList();
    

    Which to get details say in a ListBox create a class for displaying forms as a List<FormItem>

    public class FormItem
    {
        /// <summary>
        /// Name of form
        /// </summary>
        public string DisplayName { get; set; }
        /// <summary>
        /// Actual form instance
        /// </summary>
        public Form Form { get; set; }
    
        public override string ToString() => DisplayName;
    
    }
    

    Assign the DataSource of a ListBox using

    List<FormItem> formNames = Application
        .OpenForms
        .Cast<Form>()
        .Select(form => new FormItem
        {
            DisplayName = form.Name, 
            Form = form
        }).ToList();
    

    For selection changed of the ListBox cast selected item to FormItem.

    Then something like this (hard coded)

    formNames.FirstOrDefault().Form.Activate();
    

1 additional answer

Sort by: Most helpful
  1. Woodman 21 Reputation points
    2021-10-12T19:31:40.163+00:00

    thanks Karen this formNames.FirstOrDefault().Form.Activate(); helped me with little bit playing with my code

    0 comments No comments