Bonjour.

Mon but est d'utiliser la fonction OnPaint pour dessiner un rectangle sur une fenetre (facile). Mais je souhaite que les dimensions de ce rectangle soient proportionnelles aux dimensions de la fenêtre. ainsi, si l'utilisateur agrandit la fenêtre (en faisant glisser le bord), les dimensions du rectangle doivent s'adapter.

Dans ma fonction OnPaint, j'actualise aussi le titre de la fenêtre avec les dimensions du rectangle, histoire de voir si le calcul est correct ou pas.

Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
  EVT_PAINT(MainFrame::OnPaint)
END_EVENT_TABLE()
 
 
bool MyApp::OnInit()
{
  MainFrame *myMainFrame = new MainFrame("Essais", wxPoint(150,150), wxSize(480,360));
  myMainFrame->Show(TRUE);
 
  return TRUE;
}
 
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
  : wxFrame((wxFrame*)NULL,-1,title,pos,size)
{
  SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
}
 
 
void MainFrame::OnPaint(wxPaintEvent& event)
{
  wxPaintDC myDc(this);
 
  // get size:
  int maxX;
  int maxY;
  this->GetSize(&maxX, &maxY);
 
  int origX = maxX/10;
  int origY = maxY/10;
  int width = maxX*8/10;
  int height = maxY*8/10;
 
  myDc.DrawRectangle(origX,origY,width,height);
  this->SetTitle(wxString::Format("maxX=%d maxY=%d origX=%d origY=%d width=%d height=%d",maxX,maxY,origX,origY,width,height));
}
Seulement voila: quand j'agrandis ma fenêtre, je vois bien dans le titre de ma fenêtre que les variables sont recalculées et modifiées, mais le rectangle ne change pas de taille...

Quelqu'un sait pourquoi?
Merci