c++ cli - Drawing on Form_Load C++/CLI -


i'm drawing on panel method , when call method via button draw, when call method on form_load doesn't draw anything. when debug it, goes through code without problem, still won't draw anything.

below can see form_load , button_click events:

private: system::void selectelementform_load(system::object^  sender, system::eventargs^ e) {     if (elementlist->count > 0)     {         index = 0;         drawlinesinlayout();     } } 

and button

private: system::void btnleft_click(system::object^  sender, system::eventargs^  e) {     if (elementlist->count > 0)     {         if (index + 1 > 1)         {             index--;             drawlinesinlayout();         }         else         {             index = elementlist->count - 1;             drawlinesinlayout();         }     } } 

when use paint-event works when form pops up. got code twice in program kinda pointless.

so questions are:

  • why isn't form_load using method correctly , button is?
  • can call paint event on button click?

as hans passant mentioned, can't draw on isn't there yet. solution: draw after created.

invalidate(); doesn't work since there variables change in drawing method (that's why there indexchange in each call event).

instead of using load event, use shown event. draw lines on form:

private: system::void selectelementform_shown(system::object^  sender, system::eventargs^  e)  {     if (elementlist->count > 0)     {         index = 0;         drawlinesinlayout();     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -