Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i close my Form

How can i close my Form

Scheduled Pinned Locked Moved C#
questioncsharphelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zapss
    wrote on last edited by
    #1

    button on the control box. i.e validation event is fired and form is not closed Form Causesvalidation property aslo set flase. if i write the code in the Form1_closing event then also the problem is not being solved. This is because the validation event of the textboxes is fired first so the execution never reaches the Form1_closing event. How can i close my Form when user user click [X] button on the control box. or button1??????????????????:eek:

    S 1 Reply Last reply
    0
    • Z Zapss

      button on the control box. i.e validation event is fired and form is not closed Form Causesvalidation property aslo set flase. if i write the code in the Form1_closing event then also the problem is not being solved. This is because the validation event of the textboxes is fired first so the execution never reaches the Form1_closing event. How can i close my Form when user user click [X] button on the control box. or button1??????????????????:eek:

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      You can override the form close event. and can give your own event handler. So what you can do is ,set e.Cancel=false inside the overrided handler. eg: protected override void OnClosing(CancelEventArgs e) { try { if(MessageBox.Show("This Will Close Your Form . Do You Want To Continue ?","Conformation",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.No) { e.Cancel = true; base.OnClosing (e); } else { this.Dispose(); } } catch(Exception Ex) { MessageBox.Show("Ex.Message.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information); } } Sreejith Nair [ My Articles ]

      Z 1 Reply Last reply
      0
      • S sreejith ss nair

        You can override the form close event. and can give your own event handler. So what you can do is ,set e.Cancel=false inside the overrided handler. eg: protected override void OnClosing(CancelEventArgs e) { try { if(MessageBox.Show("This Will Close Your Form . Do You Want To Continue ?","Conformation",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.No) { e.Cancel = true; base.OnClosing (e); } else { this.Dispose(); } } catch(Exception Ex) { MessageBox.Show("Ex.Message.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information); } } Sreejith Nair [ My Articles ]

        Z Offline
        Z Offline
        Zapss
        wrote on last edited by
        #3

        It works but validate event fires first before closing event ? again message displays that "please enter user id and pass word".............? after this closing How can i handle this event in button click???

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups