radWaitingBar vs radWaitingBarElement

4 posts, 0 answers
  1. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 26 Oct 2012 Link to this post

    What is the difference between these 2 beasts?

    I am having a truly miserable time trying to add a radLabelElement (autosized) followed by a radWaitingBarElement in a radStatusStrip.

    I note that using the designer, I can add a radWaitingBarElement to the radStatusStrip, but not a radWaitingBar.

    These controls are supposedly updated before and after a backgroundworker completes its job. However, they seem to step on each others' toes, so the radlabelElement's text does not get properly updated, even though the code updates it before starting the background worker. I've tried rolling my own by hosting both a radWaitingBar and a radWaitingBarElement in a radLabelElement and a radHostItem added to the radStatusStrips Items.

    None of these things actually works.

    Ideas?
  2. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 27 Oct 2012 Link to this post

    OK, I finally figured out how to get this done. It appears that you have to add a radLabelElement to the StatusBar using the designer, then add the waitingbar to the children of the radLabelElement programmatically.

    Here is my code, based on the example from the documentation on using a waitingbar with a background worker.

    ---
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    using Telerik.WinControls;
      
    using System.Threading;
      
    namespace RadStatusBarWaiting
    {
        public partial class Form1 : ShapedForm
        {
            RadHostItem host;
            RadWaitingBar waitingBar;
      
            BackgroundWorker myBackgroundWorker;
      
            public Form1()
            {
                InitializeComponent();
      
                waitingBar = new RadWaitingBar();
                waitingBar.BeginInit();
                Size waitingBarSize = new Size(this.radLabelElement1.Size.Width, this.radLabelElement1.Size.Height);
                waitingBar.MinimumSize = waitingBarSize;
                waitingBar.MaximumSize = waitingBarSize;
                waitingBar.EndInit();
                host = new RadHostItem(waitingBar);
                this.radLabelElement1.Text = "";
                this.radLabelElement1.Margin = new Padding(10,0,0,0);
                this.radLabelElement1.Children.Add(host);
            }
      
            private void Form1_Load(object sender, EventArgs e)
            {
                this.radLabelElement2.Text = "My very very long test field why I'm gonna make it really long";
                waitingBar.Visible = false;
            }
      
            private void btnClose_Click(object sender, EventArgs e)
            {
                this.Close();
            }
      
            private void btnStart_Click(object sender, EventArgs e)
            {
      
                myBackgroundWorker = new BackgroundWorker();
                myBackgroundWorker.WorkerReportsProgress = true;
                myBackgroundWorker.WorkerSupportsCancellation = false;
                myBackgroundWorker.DoWork += new DoWorkEventHandler(myBackgroundWorker1_DoWork);
                myBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(myBackgroundWorker1_RunWorkerCompleted);
                this.radLabelElement2.Text = "Starting Calculation";
                this.waitingBar.Visible = true;
                this.waitingBar.StartWaiting();
                myBackgroundWorker.RunWorkerAsync(40);
           }
      
            void myBackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            {
                BackgroundWorker worker = sender as BackgroundWorker;
                int n = Convert.ToInt32(e.Argument);
                e.Result = PerformComplexComputations(n, worker, e);
            }
      
            private long PerformComplexComputations(int n, BackgroundWorker worker, DoWorkEventArgs e)
            {
                long result = 0;
      
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
                  
                else
                {
                    if (n < 2) return 1;
                    result = PerformComplexComputations(n - 1, worker, e) + PerformComplexComputations(n - 2, worker, e);
                }
      
                return result;
            }
      
            void myBackgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                this.waitingBar.StopWaiting();
                this.waitingBar.ResetWaiting();
                this.waitingBar.Visible = false;
      
                if ((e.Cancelled == true))
                {
                    this.radLabelElement2.Text = "Calculations are canceled!";
                }
                else if (!(e.Error == null))
                {
                    this.radLabelElement2.Text = ("Error: " + e.Error.Message);
                }
                else
                {
                    this.radLabelElement2.Text = "The  member of the Fibonacci sequence is: " + e.Result.ToString();
      
                }
            }
        }
    }
  3. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 31 Oct 2012 Link to this post

    Hello Helen,

    Thank you for writing.

    RadWaitingBar is a successor of RadControl (and Control), whereas RadWaitingBarElement is a descendant of RadItem (and RadElement). The difference between these two is that RadWaitingBar (the control) contains RadWaitingBarElement (the element) and it is this nested element that holds the whole waiting bar functionality. Indeed, each of our RadControls wraps up a corresponding RadElement - RadListView contains a field of type RadListViewElement, RadDropDownList contains a RadDropDownListElement field. RadControls are designed in such a manner to ensure that elements can be used as standalone units, when added to the Items collections of other controls.

    In a nutshell, if you would like to have a waitingbar on a form, you should use RadWaitingBar control. If you would like to have a waitingbar in a RadStatusStrip, you should add a RadWaitingBarElement to the Items collection of the RadStatusStrip. 

    That said, to have a label and a waiting bar next to it in a RadStatusStrip, you should add a RadLabelElement and a RadWaitingBarElement to the Items collection of the RadStatusStrip. The attached sample project demonstrates this approach. Would you please let me know whether the sample application matches your requirements? If this is not the case, please provide a bit more information on the layout you would like to achieve.

    I am looking forward to your reply.

    Kind regards,
    Boryana
    the Telerik team
    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
  4. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 31 Oct 2012 Link to this post

    Thank you Boryana!

    I'll look at your sample code, and see how it differs from what I came up with.

    Best

    Helen
Back to Top