Click here to Skip to main content
15,890,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Random class in C# Pin
Kythen8-Mar-10 9:45
Kythen8-Mar-10 9:45 
Questionhow to browse Pin
Guru Brahmam Chowdary8-Mar-10 0:58
Guru Brahmam Chowdary8-Mar-10 0:58 
QuestionRe: how to browse Pin
Calla8-Mar-10 1:08
Calla8-Mar-10 1:08 
AnswerRe: how to browse Pin
Guru Brahmam Chowdary8-Mar-10 1:52
Guru Brahmam Chowdary8-Mar-10 1:52 
GeneralRe: how to browse Pin
OriginalGriff8-Mar-10 2:02
mveOriginalGriff8-Mar-10 2:02 
GeneralRe: how to browse Pin
Guru Brahmam Chowdary8-Mar-10 2:33
Guru Brahmam Chowdary8-Mar-10 2:33 
Questionhow i can capture that print command is generating Pin
22087-Mar-10 23:52
22087-Mar-10 23:52 
AnswerMessage Closed Pin
8-Mar-10 0:19
stancrm8-Mar-10 0:19 
GeneralRe: how i can capture that print command is generating Pin
22088-Mar-10 0:28
22088-Mar-10 0:28 
GeneralRe: how i can capture that print command is generating Pin
Richard MacCutchan8-Mar-10 1:12
mveRichard MacCutchan8-Mar-10 1:12 
Questionhow to detect mouse over the picturebox? Pin
Tridip Bhattacharjee7-Mar-10 23:44
professionalTridip Bhattacharjee7-Mar-10 23:44 
AnswerRe: how to detect mouse over the picturebox? Pin
Luc Pattyn8-Mar-10 1:17
sitebuilderLuc Pattyn8-Mar-10 1:17 
AnswerRe: how to detect mouse over the picturebox? Pin
OriginalGriff8-Mar-10 1:29
mveOriginalGriff8-Mar-10 1:29 
AnswerRe: how to detect mouse over the picturebox? Pin
johannesnestler8-Mar-10 3:33
johannesnestler8-Mar-10 3:33 
QuestionCheck if expath exist Pin
ONeil Tomlinson7-Mar-10 23:12
ONeil Tomlinson7-Mar-10 23:12 
AnswerRe: Check if expath exist Pin
Mirko19807-Mar-10 23:42
Mirko19807-Mar-10 23:42 
QuestionConvert word file to pdf with openxml Pin
Pankaj Saha7-Mar-10 23:00
Pankaj Saha7-Mar-10 23:00 
QuestionWebClient and Events Pin
Teuz7-Mar-10 22:50
Teuz7-Mar-10 22:50 
AnswerRe: WebClient and Events Pin
johannesnestler8-Mar-10 4:17
johannesnestler8-Mar-10 4:17 
GeneralRe: WebClient and Events Pin
Teuz8-Mar-10 22:01
Teuz8-Mar-10 22:01 
Thank you for the reply.
How did you managed to make it work in a windows form project? This code acts exactly like the console one, no event are fired but the file is downloaded:

using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void CheckUpdate(object arg)
        {
            // This simulates my update process
            DownloadFile();
            Thread.Sleep(5000);
            Debug.WriteLine("Update completed");
        }

        public void DownloadFile()
        {
            var webClient = new WebClient();

            var progressBar = new ProgressBar(); 
            AddControl(progressBar);

            webClient.DownloadProgressChanged += (o, e) =>
                                                     {
                                                         Debug.WriteLine(e.ProgressPercentage);
                                                         progressBar.Value = e.ProgressPercentage;
                                                     };
            webClient.DownloadFileCompleted += (o, e) => Debug.WriteLine("Download completed.");

            Debug.WriteLine("Starting download...");
            webClient.DownloadFileAsync(new Uri("http://cdimage.debian.org/debian-cd/5.0.4/i386/iso-cd/debian-504-i386-netinst.iso"), "debian-504-i386-netinst.iso");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThreadPool.QueueUserWorkItem(CheckUpdate);
        }

        private void AddControl(Control control)
        {
            if (flowLayoutPanel1.InvokeRequired)
                flowLayoutPanel1.BeginInvoke(new MethodInvoker(() => AddControl(control)));
            else
                flowLayoutPanel1.Controls.Add(control);
        }

    }
}


This is also quite similar the code I'm actually using in my project. I forgot to mention that for this project I'm using NET 2.0 so maybe this can work differently in later versions.
QuestionRecord Not Insert Pin
mjawadkhatri7-Mar-10 21:00
mjawadkhatri7-Mar-10 21:00 
AnswerRe: Record Not Insert Pin
OriginalGriff7-Mar-10 21:47
mveOriginalGriff7-Mar-10 21:47 
GeneralRe: Record Not Insert Pin
R. Giskard Reventlov7-Mar-10 22:12
R. Giskard Reventlov7-Mar-10 22:12 
AnswerRe: Record Not Insert Pin
Thomas Krojer8-Mar-10 1:16
Thomas Krojer8-Mar-10 1:16 
QuestionCustom TypeConverter for SubProperties Pin
akamper7-Mar-10 20:54
akamper7-Mar-10 20:54 

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.