吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1421|回复: 14
收起左侧

[求助] C#多线程进度条

[复制链接]
回帖奖励 1 CB吾爱币 回复本帖可获得 1 CB吾爱币奖励! 每人限 1 次(中奖概率 80%)
lizf2019 发表于 2020-8-1 20:12
本帖最后由 lizf2019 于 2020-8-1 20:13 编辑

本人正在做一个模拟xp的项目:

image.png

遇到了几个问题,想在此求助下大佬:








问题1:C#如何实现多线程进度条?(5秒走完)自己弄的进度条拖慢了程序启动








问题2:C#如何播放音乐资源(将音乐资源包含进程序)








问题3:C#如何指定弹出的提示信息(messagebox)的图标,按钮

如: image.png







求大佬解惑,将将您的吾爱用户名写入感谢名单

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

windy_ll 发表于 2020-8-1 20:15
利用委托事件机制实现,以前做过这种多线程进度条
 楼主| lizf2019 发表于 2020-8-1 20:19
windy_ll 发表于 2020-8-1 20:15
利用委托事件机制实现,以前做过这种多线程进度条

大佬可否给个源码
天高路远 发表于 2020-8-1 21:15
https://blog.csdn.net/huanglin529/article/details/70239387

MessageBox.Show (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)
显示具有指定文本、标题、按钮、图标和默认按钮的消息框。

我技术不高 但愿能帮到你

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
lizf2019 + 2 + 1 谢谢您!

查看全部评分

silverkey 发表于 2020-8-1 21:46

回帖奖励 +1 CB吾爱币

MSDN有现成,去抄了改改就能用了
 楼主| lizf2019 发表于 2020-8-1 21:53
silverkey 发表于 2020-8-1 21:46
MSDN有现成,去抄了改改就能用了

大佬可否给个链接
头像被屏蔽
偶尔平凡 发表于 2020-8-1 22:11

回帖奖励 +1 CB吾爱币

提示: 作者被禁止或删除 内容自动屏蔽
windy_ll 发表于 2020-8-1 22:52

回帖奖励 +1 CB吾爱币

lizf2019 发表于 2020-8-1 20:19
大佬可否给个源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Collections;
using System.Diagnostics;

namespace RC4文件加解密
{
    public partial class Form1 : Form
    {

        delegate void AsynUpdateUI(int step);
        public int openAexitMark = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void GroupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "D:\\";
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;
            if(openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = openFileDialog.FileName;
                this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 选择了文件" + openFileDialog.FileName + "\r\n");
            }
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            int checkresult;
            checkresult = check();
            if (checkresult == 1)
            {
                int flag;
                int mark = 0;
                flag = init();
                if(flag == 1 || flag == 3)
                {
                    mark = 1;
                }
                eadThread ead = new eadThread(this.textBox2.Text, this.textBox1.Text,mark);
                ead.UpdateUIDelegate += UpdataUIStatus;
                Thread thread1 = new Thread(new ThreadStart(ead.execEaD));
                thread1.Start();
            }
            else if(checkresult == 0)
            {
                MessageBox.Show("请选择待加密文件以及密钥!", "提示");
            }
            else if(checkresult == 2)
            {
                MessageBox.Show("请选择待加密文件!", "提示");
            }
            else
            {
                MessageBox.Show("请输入密钥!", "提示");
            }
        }

        public int init()
        {
            int flag = 0;
            this.progressBar1.Value = 0;
            this.label4.Text = this.progressBar1.Value.ToString() + "%";
            if(this.checkBox1.Checked == true && this.checkBox2.Checked == true)
            {
                flag = 3;
                this.openAexitMark = 1;
            }
            else if(this.checkBox1.Checked == true && this.checkBox2.Checked == false)
            {
                flag = 1;
            }
            else if(this.checkBox1.Checked == false && this.checkBox2.Checked == true)
            {
                flag = 2;
                this.openAexitMark = 1;
            }
            else
            {
                flag = 0;
            }
            return flag;
        }

        public int check()
        {
            int flag = 0;
            if(this.textBox1.Text != "" && this.textBox2.Text != "")
            {
                flag = 1;
            }
            else if(this.textBox1.Text == "" && this.textBox2.Text != "")
            {
                flag = 2;
            }
            else if(this.textBox1.Text != "" && this.textBox2.Text == "")
            {
                flag = 3;
            }
            else
            {
                flag = 0;
            }
            return flag;
        }

        private void UpdataUIStatus(int step)
        {
            if (InvokeRequired)
            {
                this.Invoke(new AsynUpdateUI(delegate (int s)
                {
                    this.progressBar1.Value = step;
                    this.label4.Text = this.progressBar1.Value.ToString() + "%";
                    if (step == 10)
                    {
                        this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 进入子线程,开始执行加解密操作\r\n");
                    }
                    else if(step == 20)
                    {
                        this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 密钥初始化完成\r\n");
                    }
                    else if(step == 40)
                    {
                        this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 开始调用DLL导出函数\r\n");
                    }
                    else if(step == 90)
                    {
                        this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 文件加解密操作完成\r\n");
                    }
                    else if(step == 100)
                    {
                        this.textBox3.AppendText("[+] " + DateTime.Now.ToLocalTime().ToString() + " 打开文件夹操作(退出程序操作)完成\r\n");
                        MessageBox.Show("文件加解密成功!", "提示");
                        if (this.openAexitMark == 1)
                        {
                            Process.GetCurrentProcess().Kill();
                        }
                    }
                }), step);
            }
            else
            {
                this.progressBar1.Value = step;
                this.label4.Text = this.progressBar1.Value.ToString() + "%";
            }
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            int checkresult;
            checkresult = check();
            if (checkresult == 1)
            {
                int flag;
                int mark = 0;
                flag = init();
                if (flag == 1 || flag == 3)
                {
                    mark = 1;
                }
                eadThread ead = new eadThread(this.textBox2.Text, this.textBox1.Text, mark);
                ead.UpdateUIDelegate += UpdataUIStatus;
                Thread thread1 = new Thread(new ThreadStart(ead.execEaD));
                thread1.Start();
            }
            else if (checkresult == 0)
            {
                MessageBox.Show("请选择待加密文件以及密钥!", "提示");
            }
            else if (checkresult == 2)
            {
                MessageBox.Show("请选择待加密文件!", "提示");
            }
            else
            {
                MessageBox.Show("请输入密钥!", "提示");
            }
        }
    }


    class eadThread
    {
        public delegate void UpdateUI(int step);
        public UpdateUI UpdateUIDelegate;

        private string filename;
        private ArrayList arr = new ArrayList();
        private int flag;

        [DllImport("RC4.dll", EntryPoint = "rc4", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]

        public static extern int rc4(int[] key, string filename, int keylen);

        public eadThread(string KEY, string file, int mark)
        {
            char[] temp = KEY.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                arr.Add((int)temp);
            }
            this.filename = file;
            this.flag = mark;
        }

        public void execEaD()
        {
            UpdateUIDelegate(10);
            int[] key = new int[arr.Count];
            for (int i = 0; i < arr.Count; i++)
            {
                key = (int)arr;
            }
            UpdateUIDelegate(20);
            int len = key.Length;
            UpdateUIDelegate(40);
            int result = rc4(key, this.filename, len);
            UpdateUIDelegate(90);
            if (this.flag == 1)
            {
                openFile(this.filename);
            }
            UpdateUIDelegate(100);
        }

        public void openFile(string filename)
        {
            Process p = new Process();
            p.StartInfo.FileName = "explorer.exe";
            p.StartInfo.Arguments = " /e,/select," + filename;
            p.Start();
        }

    }
}
liouxin 发表于 2020-8-1 22:57

回帖奖励 +1 CB吾爱币

本帖最后由 liouxin 于 2020-8-2 00:23 编辑

该内容已删除
内容已删除
 楼主| lizf2019 发表于 2020-8-1 23:11
liouxin 发表于 2020-8-1 22:57
【楼主说的是这种吗?】

这个是?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 19:45

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表