SetBackgroundColour for wxStatiticText 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
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

SetBackgroundColour for wxStatiticText

Post by Wolfgang » Thu Oct 03, 2019 6:49 am

Inside the creation I use the following, and it is working

Code: Select all

    m_c1 = new wxStaticText(panel, Bu_c1, sp_text[96]);
     wxColour col;
    col.Set("#" + strcolor);
    if (col.IsOk())
    {
        m_c1->SetOwnBackgroundColour(col);
    }
Inside the eventhandlerfunction it does not work.
First the relevant code for the function:

Code: Select all

 m_c1->Connect(Bu_c1, wxEVT_LEFT_UP, wxMouseEventHandler(MyFrameeinst::Oncoldia), NULL, m_c1);
And the function

Code: Select all

void MyFrameeinst::Oncoldia(wxMouseEvent& event)
{
    wxInt16 test;
    test= event.GetId();
    if (test = Bu_c1)
    {
        wxColourData data;
        data.SetChooseFull(true);

        wxColour my_col;
        my_col = wxColour("#" + strcolor);

        data.SetCustomColour(1, my_col);
        data.SetColour(my_col);

        wxColourDialog dialog(this, &data);
        if (dialog.ShowModal() == wxID_OK)
        {
            wxColourData retData = dialog.GetColourData();
            wxColour col = retData.GetColour();
            wxString newcol;
            newcol = col.GetAsString(wxC2S_HTML_SYNTAX);
  
            newcol = newcol.Right(newcol.Length() - 1);
            strcolor = newcol;
         //   FindWindowById(einst_frame)->Destroy();
            col.Set("#" + strcolor);
            if (col.IsOk())
            {
                m_c1->SetBackgroundColour(col); //Here comes the error
                m_c1 -> Update();

            }
   
        }
    }
}
Get the error:
Ausgelöster Ausnahmefehler: Lesezugriffsverletzung
"this->m_c1->****" war "0xFFFFFFFFFFFFFCDF".
How can I solve that?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2512
Joined: Sun Jan 03, 2010 5:45 pm

Re: SetBackgroundColour for wxStatiticText

Post by PB » Thu Oct 03, 2019 7:08 am

I think you have a beginner bug there which you could have avoided had you used Bind() instead of de-facto deprecated Connect().

You are using a wrong event sink (the last parameter of the Connect() call): it should be the instance of a MyFrameeinst (i.e., this) where the method is actually implemented. However, you are using m_c1 which is wrong, you end up calling MyFrameeinst method with this pointing to a wxStaticText instance and then the code implodes when you try to access MyFrameinst member variable...

BTW, do you think that posting your errors in German is generally useful on an English speaking forum?

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: SetBackgroundColour for wxStatiticText

Post by Wolfgang » Thu Oct 03, 2019 9:34 am

PB wrote:
Thu Oct 03, 2019 7:08 am
BTW, do you think that posting your errors in German is generally useful on an English speaking forum?

Sorry, I just copied and pasted it. And i read english almost like I read german, so that's why it did not even jump to my eyes.

Post Reply