Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 10:57
professionalSascha Lefèvre29-Apr-15 10:57 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 10:58
professionalKevin Marois29-Apr-15 10:58 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 11:17
professionalSascha Lefèvre29-Apr-15 11:17 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 11:23
professionalKevin Marois29-Apr-15 11:23 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 11:50
professionalSascha Lefèvre29-Apr-15 11:50 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 11:54
professionalKevin Marois29-Apr-15 11:54 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 12:23
professionalKevin Marois29-Apr-15 12:23 
AnswerRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 13:00
professionalSascha Lefèvre29-Apr-15 13:00 
Don't put any UI stuff into the BW. It should look something like the following. Not tested, obviously, and it's a bit hacky. It would actually make sense to start the BW from the DownloadDialog in order to ensure that the DownloadDialog "exists" when ProgressChanged and RunWorkerCompleted fire.
C#
class Form1 : Form
{
    BackgroundWorker worker;
    DownloadDialog downloadDialog;

    public Form1()
    {
        InitializeComponent();

        worker = new BackgroundWorker();
        worker.WorkerReportsProgress = true;
        worker.ProgressChanged += worker_ProgressChanged;
        worker.DoWork += worker_DoWork;
        worker.RunWorkerCompleted += worker_RunWorkerCompleted;
    }

    void DownloadStartButton_Click(object sender, EventArgs e)
    {
        DownloadDeviceFiles();
    }

    void DownloadDeviceFiles()
    {
        worker.RunWorkerAsync();

        DownloadDialog downloadDialog = new DownloadDialog();
        downloadDialog.Text = "Retrieving Mission Data";
        downloadDialog.Progress1Caption = "Config File";
        downloadDialog.Progress2Caption = "Database";
        downloadDialog.StartPosition = FormStartPosition.CenterScreen;

        downloadDialog.ShowDialog(this);
    }

    void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        e.Result = DownloadConfigFile() && DownloadDatabase();
    }

    void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // I didn't account for the fact here that you have two separate progressbars

        if (downloadDialog != null)
            downloadDialog.Progress1PercentDone = e.ProgressPercentage;
    }

    void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        downloadDialog.Close();
        downloadDialog.Dispose();

        if (e.Result == true)
            // continue app
        else
            // close app
    }

    bool DownloadConfigFile() // same for DownloadDatabase()
    {
        // ... init ...

        while (true)
        {
            // downloadstuff

            worker.ReportProgress(percentDone);
        }

        return downloadSuccess;
    }
}

If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 13:16
professionalKevin Marois29-Apr-15 13:16 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 13:33
professionalSascha Lefèvre29-Apr-15 13:33 
QuestionFit text to label without changing label font and size Pin
Al-Rehman29-Apr-15 2:55
Al-Rehman29-Apr-15 2:55 
AnswerRe: Fit text to label without changing label font and size Pin
OriginalGriff29-Apr-15 4:58
mveOriginalGriff29-Apr-15 4:58 
GeneralRe: Fit text to label without changing label font and size Pin
Al-Rehman29-Apr-15 5:10
Al-Rehman29-Apr-15 5:10 
GeneralRe: Fit text to label without changing label font and size Pin
Sascha Lefèvre29-Apr-15 5:14
professionalSascha Lefèvre29-Apr-15 5:14 
GeneralRe: Fit text to label without changing label font and size Pin
Pete O'Hanlon29-Apr-15 5:15
mvePete O'Hanlon29-Apr-15 5:15 
GeneralRe: Fit text to label without changing label font and size Pin
OriginalGriff29-Apr-15 5:22
mveOriginalGriff29-Apr-15 5:22 
Questionc# window Application"How to resize the control proportionally at runtime using c# window application " Pin
Pranita Gupta29-Apr-15 0:14
professionalPranita Gupta29-Apr-15 0:14 
AnswerRe: c# window Application"How to resize the control proportionally at runtime using c# window application " Pin
Pete O'Hanlon29-Apr-15 0:18
mvePete O'Hanlon29-Apr-15 0:18 
AnswerRe: c# window Application"How to resize the control proportionally at runtime using c# window application " Pin
Eddy Vluggen29-Apr-15 1:12
professionalEddy Vluggen29-Apr-15 1:12 
GeneralRe: c# window Application"How to resize the control proportionally at runtime using c# window application " Pin
OriginalGriff29-Apr-15 4:59
mveOriginalGriff29-Apr-15 4:59 
QuestionWhy designer save Bad COORDINATES of UserControl's Child (EnableDesign) ? Pin
Emanuele Bonin28-Apr-15 23:39
Emanuele Bonin28-Apr-15 23:39 
AnswerRe: Why designer save Bad COORDINATES of UserControl's Child (EnableDesign) ? Pin
BillWoodruff30-Apr-15 3:37
professionalBillWoodruff30-Apr-15 3:37 
GeneralRe: Why designer save Bad COORDINATES of UserControl's Child (EnableDesign) ? Pin
Emanuele Bonin30-Apr-15 6:08
Emanuele Bonin30-Apr-15 6:08 
QuestionMake a faster search of folders Pin
Member 1140151628-Apr-15 11:34
Member 1140151628-Apr-15 11:34 
AnswerRe: Make a faster search of folders Pin
Mycroft Holmes28-Apr-15 14:05
professionalMycroft Holmes28-Apr-15 14:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.