This is a migrated thread and some comments may be shown as answers.

Invoke() on RabButtonElement ?

3 Answers 41 Views
RibbonBar
This is a migrated thread and some comments may be shown as answers.
Delalin
Top achievements
Rank 1
Delalin asked on 01 Apr 2009, 05:11 PM
Hello

    How can I change the properties from a RadButtonElement from another thread ?

        Hervé

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 03 Apr 2009, 07:32 AM
Hello Delalin,

Thanks for your question.

Please take a look at the following code snippet:

private void Form_Load(object sender, EventArgs e) 
    ThreadStart startMethod = new ThreadStart(ThreadMethod); 
    Thread myThread = new Thread(startMethod); 
 
    myThread.Start();        
 
private void ThreadMethod() 
    this.radButton1.Invoke(new MethodInvoker(ChangeButtonSize)); 
 
 
private void ChangeButtonSize() 
     this.radButton1.Size = Size.Round(new SizeF(Math.Abs(this.radButton1.Width - 1), this.radButton1.Size.Height)); 

What I am doing is creating a Thread instance with a delegate to a method that will be executed by this thread. In this method I use the Invoke method of a RadButton that I have put onto my form. In the Invoke method I pass another delegate to a method that will reduce the width of the button by 1 pixel.

You can read more about the Invoke method here:

Control.Invoke() Method

I hope this will help you to achieve your goal.

Do not hesitate to get back to me in case of further questions.

Regards,
Deyan
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anders Bergström
Top achievements
Rank 1
answered on 10 Mar 2011, 09:51 AM
Hi,
But the RadButtonElement does not expose an Invoke method, in your example you use a RadButton and not a RadButtonElement?

I want to modify some RadButtonElements and RadRibbonBarButtonGroups in my RadRibbonBar by using a seperate thread. If I use the code snippet below in the seperate thread, the text does not appear on the RadButtonElement, which it does if I remove the threading and the invoke functionality and run it on the GUI thread directly.

this.Invoke((MethodInvoker)delegate
{
    myRadButtonElement.Enabled = true;
    myRadButtonElement.ButtonFillElement.BackColor = Color.Red;
    myRadButtonElement.Text = "some text";
});

What am I doing wrong? I am using the latest version of your product.

Thanks,
Anders
0
Ivan Petrov
Telerik team
answered on 15 Mar 2011, 03:14 PM
Hi Anders Bergström,

Thank you for writing.

I tested the code you have posted and it works fine on my side. Therefore, I would kindly ask you to send a more detailed explanation of the scenario you are using this code in or better yet a sample project.

I am looking forward to your reply. 

Kind regards,
Ivan Petrov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
RibbonBar
Asked by
Delalin
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Anders Bergström
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or