Changing wxButton Label with a Variable? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Changing wxButton Label with a Variable?

Post by dominover »

I'm trying to change a wxButton Label with a variable but the button label only takes strings.
I'm not sure why the below won't work? I specifically want to change the button label to an int as shown below.

The tutorial below says that I should be able to return the int value to a wxString variable but I'm getting an error on this. The error says 'Conversion from unsigned int to wxString is ambigous'.

According to this tute I thought I could do this.
http://wiki.codeblocks.org/index.php?ti ... n_resource

Code below.
Thanks

Code: Select all

void ListBox2Frame::OnButton3Click(wxCommandEvent& event)
{
    wxString tests = ListBox1->GetCount();    // I want 'tests' to capture the number of entries in ListBox1 and have that
                                                                   // appear in the Label field of Button3 when pressed. 
    Button3->SetLabel(wxT(tests));
}
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: Changing wxButton Label with a Variable?

Post by dominover »

I just solved this myself. The tutorial is on the below link and is incredibly useful..
http://wiki.wxwidgets.org/Converting_e ... m_wxString

Here's the solution.... And it works.

Code: Select all

void ListBox2Frame::OnButton3Click(wxCommandEvent& event)
{
    wxString tests = wxString::Format(wxT("%i"),ListBox1->GetCount());

    Button3->SetLabel(tests);
}
Post Reply