0

旅行フォーム、配送フォーム、集荷フォーム

メインフォームには、テキストボックスにデータを入力する場所から旅行に移動するボタンがあり、追加を押すとlistbox、メインフォームに入力したデータに応じて集荷または配達が追加されます

listboxメイン フォームの に配信を追加すると、配信フォームの にもlistbox配信が追加されるようにするにはどうすればよいですか

またはlistbox、メインフォームにピックアップを追加すると、ピックアップフォームにもピックアップが追加さlistboxれます

配信を追加する方法のサンプルコード:

メイン フォームの [配送を追加] ボタン:

    private void btnDelivery_Click(object sender, EventArgs e)
    {


        deliveryForm.deliverytrips = new DeliveryTrips();
        //New delivery- note added to the deliveryForm object


        deliveryForm.ShowDialog();
        //Show the deliveryForm. ShowDialog ensures that the form has the exclusive focus until it is closed.

        if (deliveryForm.deliverytrips != null)
        //if null then the "cancel" button was pressed
        {
            DeliveryTrips newApp = deliveryForm.deliverytrips;
            //Get the delivery object from the form

            theDelivery.addDeliveryTrip(newApp);
            //Add the delivery to the summary
        }
        updateList();
        //Update the list object to reflect the delivery in the summary

メイン フォームのリストボックスに配達を追加するための TRIP FROM のコード:

    public partial class frmDelivery : Form
    {
    private DeliveryTrips theDeliveryTrips;
    //The DeliveryTrips object being created/edited


    public DeliveryTrips deliverytrips
    {   //Property to allow access to theDeliveryTrips
        get { return theDeliveryTrips; }
        set { theDeliveryTrips = value; }
    }

    public frmDelivery()
    {   //Constructor
        InitializeComponent();
    }


    private void frmDelivery_Load(object sender, EventArgs e)
    {
        //When makeing the form visible, set the text boxes to reflect the values in
        //theDeliveryTrips.

        if (theDeliveryTrips != null)
        {

            txtDescription.Text = "Delivery";
            txtDescription.ReadOnly = true;
            txtCustomerName.Text = theDeliveryTrips.customername;
            txtCustomerAddress.Text = theDeliveryTrips.customeraddress;
            txtTime.Text = theDeliveryTrips.arrivaltime.ToString();


        }

    }


    private void btnAdd_Click_1(object sender, EventArgs e)
    {


        theDeliveryTrips.description = txtDescription.Text;
        theDeliveryTrips.customername = txtCustomerName.Text;
        theDeliveryTrips.customeraddress = txtCustomerAddress.Text;
        theDeliveryTrips.arrivaltime = TimeSpan.Parse(txtTime.Text);

        this.Hide();
        //Hide the forum
    }

    private void btnCancel_Click_1(object sender, EventArgs e)
    {
        theDeliveryTrips = null;
        //Set theDeliveryTrips to null as to remove any changes made

        this.Hide();
        //Hide the forum
    }
}
4

1 に答える 1

0

frmDelivery クラスにパブリック メソッドを作成できます。

public void ListBoxAdd(string item)
{
     listbox_frmDelivery.Items.Add(item); // or whatever your list box is called
}

次に、frmDelivery を初期化したメインで次のように呼び出すことができます。

deliveryForm.ListBoxAdd("Added From Main Form by pub method");

または、メイン フォームで検索することもできます。

        int indexOfListBox = deliveryForm.Controls.IndexOfKey("frmDelivery listbox id");
        if (indexOfListBox != -1)// if not -1 we found it
        {
            ListBox deliveryListBox = (ListBox)deliveryForm.Controls[indexOfListBox];
            deliveryListBox.Items.Add("Added from Main form by searching index");
        }
于 2012-11-26T20:25:26.417 に答える