Не получается реализовать кнопку Show

Есть клас Car

internal class Car
{
    public string Model { get; set; }

    public int Year { get; set; }

    public string Color { get; set; }

    public long Probig { get; set; }

    public double Volume { get; set; }

    public Car() : this("no model", 0, "no color", 0, 0.0)
    {
    }

    public Car(string model, int year, string color, long probig, double volume)
    {
        Model = model;
        Year = year;
        Color = color;
        Probig = probig;
        Volume = volume;
    }

    public void Print()
    {
        Console.WriteLine("-----------------------------------");
        Console.WriteLine($"Model: {Model}");
        Console.WriteLine($"Year: {Year}");
        Console.WriteLine($"Color: {Color}");
        Console.WriteLine($"Probig: {Probig}");
        Console.WriteLine($"Volume: {Volume}");
    }
}

И Form1.cs

public partial class Form1 : Form
{
    List<Car> cars = new List<Car>();
    Random rand = new Random();

    public Form1()
    {
        InitializeComponent();

        cars.Add(new Car("Tesla", 2020, "Red", 140000, 3.0));
        cars.Add(new Car("Lamborghini", 2010, "Yellow", 170000, 7.0));
        cars.Add(new Car("BMW", 2021, "Green", 160000, 5.0));
        cars.Add(new Car("Mercedes", 2018, "White", 130000, 4.0));
        cars.Add(new Car("Toyota", 2017, "Black", 140000, 3.0));
        cars.Add(new Car("Honda", 2015, "Gray", 120000, 2.0));
        cars.Add(new Car("Ferrari", 2020, "Red", 180000, 8.0));
    }

    private void showbtn_Click(object sender, EventArgs e)
    {
        if (colorComboBox.SelectedIndex == -1)
        {
            MessageBox.Show("Select a color");
            return;
        }
        if (modelTextBox == null)
        {
            MessageBox.Show("Select a model");
            return;
        }
        if (yearNumericUpDown == null)
        {
            MessageBox.Show("Select a year");
            return;
        }
        if (probigNumericUpDown == null)
        {
            MessageBox.Show("Select a probig");
            return;
        }
        if (volumeNumericUpDown == null)
        {
            MessageBox.Show("Select a volume");
            return;
        }

        //Это пример вывода с прошлой задачи
        //Order? selected = OrdersComboBox.SelectedItem as Order;
        //MessageBox.Show(selected.ToString(), "Order details", MessageBoxButtons.OK, MessageBoxIcon.Information);

        //Car? selected = colorComboBox.SelectedItem as Car;
        Car car = new Car();
        MessageBox.Show(selected.Print(), "Order details", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    private void addbtn_Click(object sender, EventArgs e)
    {

    }
}

Не могу понять как вывести выбранную пользователем информацию в отдельном окне. Раньше я делала так только с ComboBox и все работало, а сейчас помимо этого используется TextBox и NumericUpDown, у них нету метода SelectedItem, так как в ComboBox.


Ответы (0 шт):