Question

In a windows application in visual studio 2010 c# i have the follow problem :

I am making a static Form S1HiddenForm; and then i use it to open an application like this :

Command("Something[AUTOEXEC=2]", S1HiddenForm);

which opens me an usual windows form. I want to make an event that when the user presses X then he will not let him close the window.

If i have a usual Form i knew i could make it like this

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason == CloseReason.UserClosing)
        {
            e.Cancel = true; //I'm sorry Dave, I'm afraid I can't do that.
        }
    }

using the event handler in the designer view.

But in this S1HiddenForm i cant do it. Any suggestions? It seems easy but i cant find anything useful.

Was it helpful?

Solution

try with Delegates. For help check Delegates Help

type S1HiddenForm.FormClosing+= and type TAB, write your custom code in the event.

are you looking for this...

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        static Form2 f1=new Form2();

        private void Form1_Load(object sender, EventArgs e)
        {
            f1.Show();
            f1.FormClosing += new FormClosingEventHandler(f1_FormClosing);
        }

        void f1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true; //I'm sorry Dave, I'm afraid I can't do that.
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top