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. Calling Dialog from Thread

Calling Dialog from Thread

Scheduled Pinned Locked Moved C#
helpquestion
2 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.
  • M Offline
    M Offline
    MudkiSekhon
    wrote on last edited by
    #1

    I am developing a windows application in which I am calling a dialog window in a thread. When I minimize the Dialog, it not only minimize but also closes. Why it is showing this kind of behaviour? The code i used is: On Form1: private void button1_Click(object sender, System.EventArgs e) { Thread td = new Thread(new ThreadStart(initiateForm2)); td.Start(); } private void initiateForm2() { Demo frm2 = new Demo(); this.Hide(); frm2.ShowDialog(); } On Form2: private void btnMinimize_Click(object sender, System.EventArgs e) { this.Hide(); } The problem is that when I hide the second form, it also call the Closing event of the Dialog form. It closes the dialog window. Why it is so?

    Thanks, Sandeep S. Sekhon

    S 1 Reply Last reply
    0
    • M MudkiSekhon

      I am developing a windows application in which I am calling a dialog window in a thread. When I minimize the Dialog, it not only minimize but also closes. Why it is showing this kind of behaviour? The code i used is: On Form1: private void button1_Click(object sender, System.EventArgs e) { Thread td = new Thread(new ThreadStart(initiateForm2)); td.Start(); } private void initiateForm2() { Demo frm2 = new Demo(); this.Hide(); frm2.ShowDialog(); } On Form2: private void btnMinimize_Click(object sender, System.EventArgs e) { this.Hide(); } The problem is that when I hide the second form, it also call the Closing event of the Dialog form. It closes the dialog window. Why it is so?

      Thanks, Sandeep S. Sekhon

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      I guess this behaviour is caused by the fact that you show the second form as modal dialog. Use the Form.Show method to display the second form. Furthermore you should no longer need to do this inside an extra thread, so the whole thing cuts down to:

      private void button1_Click(object sender, System.EventArgs e)
      {
      Demo frm2 = new Demo();
      this.Hide();
      frm2.Show();
      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      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