简体   繁体   中英

Close C# form but not close calling application?

What I have is a project that is called from our ERP. The ERP calls functions that are exposed in the C# project and info is passed back and forth. This works great, but I am having an issue with the "Cancel" button. When the cancel button is clicked I want it to jsut close the C# form and not return anything.... Pretty much just terminate any action in C# and sever the connection to the ERP. I have tried many forms of the environment and application commands but they also close the ERP as well as the C# form. Are there any recommendations of the best approach for this? I can send the dialog from the button back to the ERP and just have the ERP not do anything with a true value but I am wondering if there isn't a more efficient way to accomplish this. Thank in advance.

Edit: Here is the current code on the form that contains the buttons. The cancel button is and has been set with DialogResult = Cancel as well...

The problem is that certain functions will be called from the ERP when this form is instantiated. Using this.close() does close the form but it also returns values back to the ERP, which I do not want it to do.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NavAutomation
{
    public partial class NAVForm : Form
    {
        public NAVForm(string frmName, int maxLen)
        {
            InitializeComponent();
        }

        private void NAVForm_Load(object sender, EventArgs e)
        {
        }

        public string RetVal1 { get; set; }
        public string txtB1 { get; set; }
        public int txtB1Len { get; set; }
        private void button2_Click(object sender, EventArgs e)
        {
            this.RetVal1 = textBox1.Text;

            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}

What I ended up doing, which works great is default a bool to true, and pass back false on the cancel button/close button and then simply exited the calling code in our ERP and it works like a dream. Thanks for the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM