将数据插入mysql时如何显示图片框 [英] How to show picturebox when inserting data to mysql

查看:63
本文介绍了将数据插入mysql时如何显示图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我正在使用c#开发一个桌面应用程序,因为它将一些数据保存到mysql服务器,需要保存5毫秒.所以意思是我想显示包含一个.gif文件的picturebox.但它不起作用.当插入时,它也是可见的假,我也用过线程.但它没有显示.还有其他显示方式吗?请帮助我

谢谢
Sujith

Hai,

i am developing one desktop application using c#, in that am saving some datas to mysql server its taking 5 mts to save. So mean while i want to show picturebox which contain one .gif file. But its not working. When inserting also it is visible false, i have used thread also. but its not showing. is there any other way to display? please help me

Thanks
Sujith

推荐答案

您可以尝试 BackgroundWorker 类.
帮助和示例在此处提供
http://msdn.microsoft.com/en-us/library/system.componentmodel. backgroundworker.aspx [ ^ ]
如果您的问题得到解决,则可以接受该解决方案,否则,请发布您的查询.

PES
You can try BackgroundWorker class.
Help and example are available here
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]
If your problem is solved you may accept the solution, otherwise please post your queries.

PES


此处是使用后台工作程序的示例代码.您还可以使用其他线程类,例如Thread,Task或简单的委托.

here a sample code using background worker. You can also use other threading class like Thread, Task or simple delegate.

public partial class Form1 : Form
    {
        private BackgroundWorker backgroundWorker;
        public Form1()
        {
            InitializeComponent();

            Button btnSave = new Button();
            btnSave.Text = "&Save";
            btnSave.Click += new EventHandler(btnSave_Click);


            backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            SampleModel model = new SampleModel()
                                    {
                                        Data1 = "Put your model here"
                                    };
            

            backgroundWorker.RunWorkerAsync(model);
        }

        void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // put code here to hide the gif/progress bar.
        }

        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            
            SampleModel model = e.Argument as SampleModel;
            
            // Put insert code here on the my sql or your BLL/Dal layer 
            //e.Result = Dal.Save(model);
        }

      
        class SampleModel
        {
            public string Data1 { get; set; }
        }
    }


使用 BackgroundWorker class
将一个PictureBox控件添加到您的窗体并将Visible属性设置为false
在您的代码中执行以下操作

Use BackgroundWorker class
Add One PictureBox control to your form and set Visible property to false
do the following in your code

        private void btnSave_Click(object sender, EventArgs e)
        {
            //Call save operation on worker thread
            BackgroundWorker backgroundWorker1 = new BackgroundWorker();
            backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            pictureBox1.Visible = true;
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //do your long running save operation here
            //Note: You cannot accese UI control here like lable's value
            //but you can pass the same while calling RunWorkerAsync() method as parameter 
//check overloaded RunWorkerAsync() method
        }

        // This event handler deals with the results of the background operation.
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //set Visible property of your pictureBox control to false like
            pictureBox1.Visible = false;
        }



你完成了

希望这能对您有所帮助,请接受解决方案,否则请回到我身边.
谢谢



And you are done

Hope this will help you if this works fine accept the solution otherwise revert back to me.
Thanks


这篇关于将数据插入mysql时如何显示图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆