Page 1 of 1

How to Change a Bitmap Based on a ListBox Value

Posted: Fri Apr 01, 2016 9:56 pm
by ColleenKobe
Hi!

I have created a wxListBox called Icon. It contains the following Choices: Question Mark; Asterisk; Exclamation Point; Superman; Batman; and Homer.

In the same sizer, I have created a wxStaticBitmap called Pichow (ie "Picture").

And I have a directory containing images of each of those Choices, in either *.png or *.jpg format.

My goal is to change the image in Pichow based upon the current value of Choice.
Question Mark and List.jpg
Is there an example file, or tutorial, that can tell me how to do that? Conceptually, I know what to do, but I don't know the syntax.

---
Per viewtopic.php?f=11&t=804:
1. Your codelite version: 9.1.5
2. Is it a self compiled version of codelite: I don't understand this question. I did not compile it; I'm using it as-is. Does that answer the question?
3. Your OS: Windows 7. Target is Windows.
4. Compiler version: g++ TDM-GCC, version 5.1.0.3

Thank you!

Colleen

Re: How to Change a Bitmap Based on a ListBox Value

Posted: Fri Apr 01, 2016 11:28 pm
by eranif
Add event handler to the wxListBox event type: wxEVT_COMMAND_LISTBOX_SELECTED
In the handler:

Code: Select all

void MyClass::OnItemSelected(wxCommandEvent& event)
{
    int selectedIndex = listBox->GetSelection();
    if(selectedIndex == wxNOT_FOUND) return;
    wxString label = listBox->GetString(selectedIndex);
    // Replace the image
    
    if(label == " .... ") {
        staticBitmap->SetBitmap(my_bitmap);
    } else if ( label == " ..." ) {
        ...
    } else {
        ...
    }
    staticBitmap->Refresh();
}
NOTE: these kind of questions are more related to wxWidgets than CodeLite, and should be asked on the wxForum (https://forums.wxwidgets.org)

Eran

Re: How to Change a Bitmap Based on a ListBox Value

Posted: Mon Apr 04, 2016 6:30 pm
by ColleenKobe
Eran, thank you for the code!
It doesn't quite run yet. I get an error message saying "Can't load bitmap 'exclamationpoint01.png' from resources! Check .rc file." So I will try to figure out what is wrong. If I can't, I'll post on the wxWidgets forum.

I apologize for posting this message in the wrong forum. I am still new and I am not always clear on whether the issue is wxWidgets, CodeLite, or TPM-GCC.

Thank you again.

Colleen