title: How do I make a box that i can move. I am new to wxwidgets and wondering if there is a way to move a box
body: <p>The Image is what I currently have made, I plan to make an Elevator that can go up and down. I am unsure of how I would move a box such that it stays at the same x cords but changes the y cords. Any help is appreciated.</p>
  <p>This is for a project I am doing. The specifications state</p>
  <pre><code> &quot;In this project, the group is required to 
  develop  a  programme  that  simulates  the  operation  of  arrays  (columns)  of  elevators 
  running over a multi‐storey building. The program  (application) should be able  to cope 
  with user defined number of elevators and number of storeys along with an ability for a 
  user to simulate or represent elevator passengers making request for elevator service to 
  particular  floors. The program  should have a user interface  that displays  the elevators’ 
  states  allows  user  input  and  ideally  shows  (simulates)  the  vertical  movement  of  each 
  elevator. &quot;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/rnte7.png" rel="nofollow noreferrer">Simulation Plane</a></p>
  <p>I am looking for something that will move the &quot;Elevator A&quot; box with the buttons up or down, along with a box inside the elevator shaft, both move up and down in unison. The code should do this automatically hopefully without having to drag the boxes and buttons with a mouse.</p>
  <p>cMain.hpp (Updated)</p>
  <pre><code>#pragma once
  #ifndef _cMain_
  #define _cMain_
  #include &lt;wx/frame.h&gt;
  #include &lt;wx/wx.h&gt;
  class cMain : public wxFrame {
  public:
      cMain(wxWindow* parent,
          wxWindowID id,
          const wxString&amp; title,
          const wxPoint&amp; pos = wxDefaultPosition,
          const wxSize&amp; size = wxDefaultSize,
          long style = wxDEFAULT_FRAME_STYLE,
          const wxString&amp; name = wxASCII_STR(wxFrameNameStr));
      ~cMain();
      wxStaticBox* m_box1 = nullptr;
      wxStaticBox* m_box2 = nullptr;
      wxStaticBox* m_box3 = nullptr;
      wxButton* m_btng = nullptr;
      wxButton* m_btn1 = nullptr;
      wxButton* m_btn2 = nullptr;
      wxButton* m_btn3 = nullptr;
      wxButton* m_btn_up = nullptr;
      wxButton* m_btn_down = nullptr;
      wxListBox* m_list1 = nullptr;
      void Ground_Button(wxCommandEvent&amp; evt);
      void Level_1_Button(wxCommandEvent&amp; evt);
      void Level_2_Button(wxCommandEvent&amp; evt);
      void Level_3_Button(wxCommandEvent&amp; evt);
      void Call_Up_Button(wxCommandEvent&amp; evt);
      void Call_Down_Button(wxCommandEvent&amp; evt);
      DECLARE_EVENT_TABLE();
  };
  
  #endif /* */
  </code></pre>
  <p>cMain.cpp (Updated)</p>
  <pre><code>#include &quot;cMain.h&quot;
  #include &quot;id.h&quot;
  #include &lt;wx/dc.h&gt;
  #include &lt;wx/graphics.h&gt;
  #include &lt;wx/dcbuffer.h&gt;
  #include &lt;wx/event.h&gt;
  #include &lt;iostream&gt;
  #include &quot;cElevator.h&quot;
  using namespace std;
  cElevator e;
  wxBEGIN_EVENT_TABLE(cMain, wxFrame)
  
  wxEND_EVENT_TABLE();
  cMain::cMain(wxWindow* parent,
  wxWindowID id,
  const wxString&amp; title,
  const wxPoint&amp; pos,
  const wxSize&amp; size,
  long style ,
  const wxString&amp; name) : wxFrame(parent,id,title,pos,size,style,name)
  {   
      this-&gt;SetBackgroundColour(*wxWHITE);
      m_box1 = new wxStaticBox(this, wxID_ANY, &quot;Call 1&quot;, wxPoint(252, 530), wxSize(50, 80));
      m_btn_up = new wxButton(this, wxID_ANY, &quot;/\\&quot;, wxPoint(265, 547), wxSize(25, 25));
      m_btn_down = new wxButton(this, wxID_ANY, &quot;\\/&quot;, wxPoint(265, 575), wxSize(25, 25));
  
      //Inner Panel
      m_box2 = new wxStaticBox(this, wxID_ANY, &quot;Elevator A&quot;, wxPoint(164, 530), wxSize(80, 80));
  
      m_btng = new wxButton(this, wxID_ANY, wxString(&quot;G&quot;), wxPoint(177, 575), wxSize(25, 25));
      m_btn1 = new wxButton(this, wxID_ANY, wxString(&quot;1&quot;), wxPoint(177, 547), wxSize(25, 25));
      m_btn2 = new wxButton(this, wxID_ANY, wxString(&quot;2&quot;), wxPoint(207, 575), wxSize(25, 25));
      m_btn3 = new wxButton(this, wxID_ANY, wxString(&quot;3&quot;), wxPoint(207, 547), wxSize(25, 25));
  
      //Elevator Shafts
      //m_box3 = new wxStaticBox(panel, wxID_ANY, &quot;&quot;, wxPoint(80, 10), wxSize(80, 600));
  
      //Other 
      m_list1 = new wxListBox(this, wxID_ANY, wxPoint(200, 10), wxSize(100, 100));
      m_btn_up-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Call_Up_Button, this);
      m_btn_down-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Call_Down_Button, this);
      m_btng-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Ground_Button, this);
      m_btn1-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Level_1_Button, this);
      m_btn2-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Level_2_Button, this);
      m_btn3-&gt;Bind(wxEVT_BUTTON, &amp;cMain::Level_3_Button, this);
  }
  void cMain::Ground_Button(wxCommandEvent&amp; evt)
  {
      e.GLevel = true;
      
      m_list1-&gt;AppendString(&quot;Going to Ground Level&quot;);
      evt.Skip();
  
  }
  void cMain::Level_1_Button(wxCommandEvent&amp; evt)
  {
      
      m_list1-&gt;AppendString(&quot;Going to Level 1&quot;);
      evt.Skip();
  }
  void cMain::Level_2_Button(wxCommandEvent&amp; evt)
  {
      
      m_list1-&gt;AppendString(&quot;Going to Level 2&quot;);
      evt.Skip();
  }
  void cMain::Level_3_Button(wxCommandEvent&amp; evt)
  {
      
      m_list1-&gt;AppendString(&quot;Going to Level 3&quot;);
      evt.Skip();
  }
  void cMain::Call_Up_Button(wxCommandEvent&amp; evt)
  {
      
      m_list1-&gt;AppendString(&quot;Going to Up&quot;);
      //evt.Skip();
  }
  void cMain::Call_Down_Button(wxCommandEvent&amp; evt)
  {
      
      m_list1-&gt;AppendString(&quot;Going Down&quot;);
      //evt.Skip();
  }
  
  cMain::~cMain() {
  
  }
  
  
  
  
  </code></pre>
  <p>cElevator.hpp</p>
  <pre><code>#include &lt;wx/wx.h&gt;
  
  class cElevator : public wxFrame
  {
  public:
      cElevator(wxWindow* parent,
          wxWindowID id,
          const wxString&amp; title,
          const wxPoint&amp; pos = wxDefaultPosition,
          const wxSize&amp; size = wxDefaultSize,
          long style = wxDEFAULT_FRAME_STYLE,
          const wxString&amp; name = wxASCII_STR(wxFrameNameStr));
      ~cElevator();
  
      bool GLevel;
      void OnPaint(wxPaintEvent&amp; evt);
  
  
      wxDECLARE_EVENT_TABLE();
  };
  
  </code></pre>
  <p>cElevator.cpp</p>
  <pre><code>#include &quot;cMain.h&quot;
  #include &quot;cElevator.h&quot;
  #include &lt;wx/dc.h&gt;
  #include &lt;wx/graphics.h&gt;
  #include &lt;wx/dcbuffer.h&gt;
  #include &lt;wx/event.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  wxBEGIN_EVENT_TABLE(cElevator,wxPanel)
  EVT_PAINT(cElevator::OnPaint)
  wxEND_EVENT_TABLE();
  
  cElevator::cElevator(wxWindow* parent,
      wxWindowID id,
      const wxString&amp; title,
      const wxPoint&amp; pos,
      const wxSize&amp; size,
      long style,
      const wxString&amp; name) : wxFrame(parent,id,title,pos,size,style,name)
  {
      this-&gt;SetBackgroundColour(*wxBLACK);
  
  }
  
  void cElevator::OnPaint(wxPaintEvent&amp; evt)
  {
      wxClientDC cdc(this);
      wxBufferedDC dc(&amp;cdc);
      wxGraphicsContext* gc = wxGraphicsContext::Create(dc);
  
  
      // make a path that contains a circle and some lines
      gc-&gt;SetPen(*wxWHITE_PEN);
      wxGraphicsPath path = gc-&gt;CreatePath();
      path.CloseSubpath();
      path.AddRectangle(80.0, 10.0, 80.0, 800.0);
      path.MoveToPoint(80, 600);
      path.AddLineToPoint(160, 600);
      path.MoveToPoint(80, 400);
      path.AddLineToPoint(160, 400);
      path.MoveToPoint(80, 200);
      path.AddLineToPoint(160, 200);
      //path.AddRectangle(90, 740, 60, 65);
      //path.AddRectangle(90, 530, 60, 65);
      //path.AddRectangle(90, 330, 60, 65);
      //path.AddRectangle(90, 130, 60, 65);
      gc-&gt;StrokePath(path);
  
      delete gc;
  }
  
  cElevator::~cElevator() {
  
  }
  
  </code></pre>
  <p>Paintting part</p>
  <pre><code>void cElevator::OnPaint(wxPaintEvent&amp; evt)
  {
      int CurrentPosy = 130;
      wxPaintDC dc(this);
      dc.DrawRectangle(80.0, 10.0, 80.0, 800.0);//overall rectangle for  elevator shaft
      dc.Clear();
      dc.SetPen(*wxWHITE);
      dc.SetBrush(*wxLIGHT_GREY_BRUSH);
      while (CurrentPosy != ExpectedPosy)
      {
          dc.DrawRectangle(90, CurrentPosy, 60, 65);
              //CurrentPosy--; // or currentPOs.y++;
          wxSleep(5);
          dc.Clear();
      }
      dc.SetPen(wxNullPen);
      dc.SetBrush(wxNullBrush);
  </code></pre>
  <p>The ExpectedPosy is in the header file as an int, that should get a value when the ground button (or other level buttons) is pressed.</p>