logo
down
shadow

Show form that showDialog from mainForm won't block it, but closing mainForm will close it


Show form that showDialog from mainForm won't block it, but closing mainForm will close it

By : Andrew Robert Wiggin
Date : January 10 2021, 01:49 PM
it helps some times This is something you really should not fix. Keeping a form enabled while a dialog is displayed is risky. The user could start code from that form that shouldn't run while a dialog is active. Like displaying another dialog.
But you can with a trick and doing it carefully. The ShowDialog() call iterates all open forms and disables them. You could re-enable one by P/Invoking the EnableWindow() API function. The trick is to do so while the dialog is displayed, Control.BeginInvoke() can do this.
code :


Share : facebook icon twitter icon
When using form.ShowDialog() a thread in mainform doesn't work

When using form.ShowDialog() a thread in mainform doesn't work


By : Hasan Priyo
Date : March 29 2020, 07:55 AM
around this issue ShowDialog() is a blocking call. The thread actually runs, it is busy pumping the message loop for the dialog. This is no different from what happens on the main thread of your program.
Doing this is very unwise, the dialog has no Z-order relationship with the rest of the windows in your app. One classic mishap is that it can disappear behind another window but no good way for the user to find it back. Use Control.BeginInvoke to create the dialog on the UI thread instead. This also ensures that your thread keeps 'running'.
accessing variable like this MainForm.property , without instantiating MainForm mf = new MainForm;

accessing variable like this MainForm.property , without instantiating MainForm mf = new MainForm;


By : FrederikK
Date : March 29 2020, 07:55 AM
help you fix your problem Two options:
Pass a reference of MainForm to Form2 and access it from there. Make the property static on MainForm.
How can I close the MainForm, without closing the others?

How can I close the MainForm, without closing the others?


By : Trafton Kenney
Date : March 29 2020, 07:55 AM
may help you . If you want a basic form that will pretty much just allow the user to play until they close the other form then close this form, use this:
code :
private void button2_Click(object sender, EventArgs e)
{
    Form f2 = new Form1();
    this.Hide();
    f2.ShowDialog();
    this.Close();           
}
private void button2_Click(object sender, EventArgs e)
{
    Form f2 = new Form1();
    this.Hide();
    if(f2.ShowDialog() == DialogResult.OK)
    {
        this.Show();
    }
    else
    {
        this.Close();
    }
}
How to close a form and come back to mainform

How to close a form and come back to mainform


By : Olga Epshteyn
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You actually do not need to call form3 from form1 just to pass a value. If I understand you correctly, the desired flow should be like this
code :
form1
  opens
    form2
      opens
        form3
          |
          | value
          |
form1 <---+
public string ValueFromForm3
{
    get;
    private set;
}


public void ShowForm3()
{
    using (Form3 f3 = new Form3())
    {
       if (f3.ShowDialog(this) == DialogResult.OK)
           ValueFromForm3 = f3.TheValueYouNeed;
    }
}
public void ShowForm2()
{
    using (Form2 f2 = new Form2())
    {
        if (f2.ShowDialog(this) == DialogResult.OK)
            DoSomethingWith(f2.ValueFromForm3);
    }
}
mainform trying to show on closing the login form

mainform trying to show on closing the login form


By : sfik
Date : March 29 2020, 07:55 AM
I hope this helps you . Instead of hiding Main Form before you show Login you should use initialize Application to start with Main Form hidden. To do that just add Application.ShowMainForm := false before you create main form.
Application.Run that executes after you close your login form will show or not show Main Form based on value of Application.ShowMainForm variable that is by default true. So that will introduce flicker because main form will be shown before application terminates.
code :
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.ShowMainForm := false;
  Application.CreateForm(TForm1, Form1);
  Login;
  Application.Run;
end.
Related Posts Related Posts :
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • All possible combinations of n items selected randomly from a set of x items (algorithm)
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • c# control location precision
  • Printing to Zebra printer gives faint and blurry images
  • How to avoid stepping into dll code file?
  • Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
  • Is there anyway to reduce IsolatedStorage capacity in Silverlight?
  • C#: How to print a unicode string to console?
  • Frequency Table with Random Values
  • My Visual Studio 2008 web application keeps throwing a .Net error when I first run it, but refreshing fixes it
  • TCP Connection Creation and Closing Event Hooking
  • Find changed properties of a class
  • C#: Object with custom marshaller not containing data after PInvoke call
  • Version Control System with API. Need to get metrics
  • Performance comparison of Dictionaries
  • How to get process name and title of the top window on Windows / C#
  • How to save the ListView contents to a text file?
  • Why not .NET-style delegates rather than closures in Java?
  • Get CLSID by PIA interface Type
  • Visual Studio 2008 C# - Recover solution from application manifest possible?
  • Is a good practice to initialize private data members from within ctor by calling the associated properties instead of t
  • Inserting into a bitstream
  • How do you write byte[] array using log4.net
  • Clickonce + .NET client profile 4 framework + offline
  • Developing a GPS car tracking system
  • dynamic log4net appender name?
  • Visual studio formatting issue
  • IndexOutOfRangeException when a stream is a multiple of the buffer size
  • How to deal with calculated values with Dependency Properties on a custom WPF control
  • counting from textbox,asp.net
  • Threading best practice when using SFTP in C#
  • how to load PDF file in website page using C#
  • Parent child class relationship design pattern
  • MessageQueue.BeginReceive() null ref error - c#
  • A C# collection, which behaves like C++ set or priority_queue?
  • Animating WPF buttons from inside a style
  • WPF Grid : GridSplitter event
  • Server 2008 Task Scheduler Mapped Drive Access C#
  • Cast problem with LINQ
  • Combo box Item source = ObservableCollection & I need a '-None-' dummy entry at the top
  • Which GUI control is suitable for this purpose?
  • Trying to access App.config file for mail settings but fails to work
  • Invoke PowerShell script from c# in runspace and get line number where error occured
  • How to show html contents with a RichTextBox?
  • FTP monitoring and downloading of new files
  • MEF + Plug-In not updating
  • Efficient handling of super wide, but not so tall, bitmap?
  • .NET 3.0 Unit Testing getting System.MethodAccessException calling .NET 2.0
  • Web Services vs Persistent Sockets
  • How do I dynamically reference incremented properties in C#?
  • Windows Installer (C#) error code 2869
  • Exception "The operation is not valid for the state of the transaction" using TransactionScope
  • Tools for listing database accesses from .NET code
  • Excel VSTO set selection
  • Creating a subscription based website in ASP.NET
  • Merging Resources Dictionaries
  • How to launch a .bat file in a C# windows Service project
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk