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

C#

 
GeneralRe: Seperate one string into 2 Pin
KIDYA10-May-09 21:25
KIDYA10-May-09 21:25 
GeneralRe: Seperate one string into 2 Pin
Anubhava Dimri10-May-09 21:40
Anubhava Dimri10-May-09 21:40 
AnswerRe: Seperate one string into 2 Pin
OriginalGriff10-May-09 21:46
mveOriginalGriff10-May-09 21:46 
GeneralRe: Seperate one string into 2 Pin
KIDYA10-May-09 23:05
KIDYA10-May-09 23:05 
QuestionProgress Bar Pin
S K Y10-May-09 16:02
S K Y10-May-09 16:02 
AnswerRe: Progress Bar Pin
N a v a n e e t h10-May-09 16:25
N a v a n e e t h10-May-09 16:25 
GeneralRe: Progress Bar Pin
S K Y10-May-09 16:39
S K Y10-May-09 16:39 
GeneralRe: Progress Bar Pin
N a v a n e e t h10-May-09 17:21
N a v a n e e t h10-May-09 17:21 
S K Y wrote:
i couldn't get progress bar like message box..


What do you mean by progress bar like message box? A modal progress bar which will not allow to click on other forms when progress is shown? If yes, here is a method

1 - Create a new form say Progress
2 - Add a progress bar say "pb" to this form.
3 - Create a delegate in this form which will call back the method to execute from the progress window. Refer the following code
// use this class to interact with progress form your form
public class ProgressEventArgs
{
    ProgressBar pb;
    Form form;

    public ProgressEventArgs(ProgressBar pb, Form form)
    {
        this.pb = pb;
        this.form = form;
    }

    public void PerformProgress(int value)
    {
        form.BeginInvoke((MethodInvoker)delegate
        {
            this.pb.Value = value;
        });
    }

    public void StopProgress()
    {
        form.BeginInvoke((MethodInvoker)delegate
        {
            form.Close();
        });
    }
}

public delegate void WorkStartedHandler(ProgressEventArgs pe);

// your progress form
public partial class Progress : Form
{
    WorkStartedHandler method;
    public Progress()
    {
        InitializeComponent();
    }

    public void ShowProgress(int minimum, int maximum, WorkStartedHandler method)
    {
        pb.Minimum = minimum;
        pb.Maximum = maximum;
        this.method = method;
        new Thread(DoWork).Start();
        this.ShowDialog();
    }

    void DoWork()
    {
        method(new ProgressEventArgs(this.pb, this));
    }
}
The above code is simple and self explaining. You can use this like
private void import(object sender, EventArgs e)
{
    if (listView1.Items.Count == 0)
    {
         Progress p = new Progress();
         p.ShowProgress(1, dlg.FileNames.Length, DoWork);
    }
}

void DoWork(ProgressEventArgs pe)
{
    int i = 0;
    foreach (string path in dlg.FileNames)
    {
        .............
        .............
        ++i;
        pe.PerformProgress(i);
    }
    pe.StopProgress();
}
I wrote the above code in CP editor directly, so expect some compile time errors.

Smile | :)


QuestionRead Sql Server Message from C# Pin
I Believe In GOD10-May-09 13:53
I Believe In GOD10-May-09 13:53 
AnswerRe: Read Sql Server Message from C# Pin
Luc Pattyn10-May-09 14:28
sitebuilderLuc Pattyn10-May-09 14:28 
GeneralRe: Read Sql Server Message from C# Pin
N a v a n e e t h10-May-09 16:30
N a v a n e e t h10-May-09 16:30 
GeneralRe: Read Sql Server Message from C# Pin
Luc Pattyn10-May-09 17:34
sitebuilderLuc Pattyn10-May-09 17:34 
AnswerRe: Read Sql Server Message from C# Pin
N a v a n e e t h10-May-09 16:27
N a v a n e e t h10-May-09 16:27 
AnswerRe: Read Sql Server Message from C# Pin
I Believe In GOD26-May-09 14:26
I Believe In GOD26-May-09 14:26 
QuestionError when creating new C# project Pin
Alan Burkhart10-May-09 13:19
Alan Burkhart10-May-09 13:19 
AnswerRe: Error when creating new C# project Pin
Luc Pattyn10-May-09 13:27
sitebuilderLuc Pattyn10-May-09 13:27 
GeneralRe: Error when creating new C# project Pin
Alan Burkhart10-May-09 16:32
Alan Burkhart10-May-09 16:32 
AnswerRe: Error when creating new C# project Pin
Anubhava Dimri10-May-09 20:07
Anubhava Dimri10-May-09 20:07 
GeneralRe: Error when creating new C# project Pin
Alan Burkhart11-May-09 2:55
Alan Burkhart11-May-09 2:55 
QuestionHow to know if my database update was done ? Pin
Yanshof10-May-09 9:46
Yanshof10-May-09 9:46 
AnswerRe: How to know if my database update was done ? Pin
Abhishek Sur10-May-09 10:06
professionalAbhishek Sur10-May-09 10:06 
GeneralRe: How to know if my database update was done ? Pin
Yanshof10-May-09 17:42
Yanshof10-May-09 17:42 
Question[Message Deleted] Pin
nike_arh10-May-09 9:03
nike_arh10-May-09 9:03 
AnswerRe: A program deleting itself Pin
DaveyM6910-May-09 9:05
professionalDaveyM6910-May-09 9:05 
AnswerRe: A program deleting itself Pin
Pete O'Hanlon10-May-09 9:08
mvePete O'Hanlon10-May-09 9:08 

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.