WxBitmapButton

From WxWiki

Jump to: navigation, search

Contents

[edit] wxBitmapButton

See also:

[edit] Sample Code

[edit] wxBASIC

This short demo program shows how to use wxBitmapButton:


 frame = new wxFrame( Null, -1, "Graphic demo for wxBasic",wxPoint(20,20),wxSize(320,200+25))
 ' 25 is the height of titlebar.
 
 panel = new wxPanel( frame, -1 ,wxPoint(0,100),wxSize(320,100)) ' Panel covers only bottom half of window.
 dummy_panel=new wxPanel(frame,-1,wxPoint(-1,-1),wxSize(0,0)) ' If you create only one panel, it will
                                                              ' cover ALL the window, so we create an
                                                              ' "invisible" second panel.
 
 bmp = new wxEmptyBitmap(0,0)  ' Create an empty bitmap. Size does NOT matter...
 bmp2 = new wxEmptyBitmap(0,0)
  bmpDC = wxMemoryDC()   ' Allocate memory: this space will be used to store the bitmap.
 
 
 bmp.LoadFile("f:/documenti/calcio.bmp", wxBITMAP_TYPE_BMP)   'You can load an existing BMP/GIF
                                                                  'into your image (wxBITMAP_TYPE_GIF).
                                                                  ' ****Spcecify the right path for your image!!****
 
 bmp2.LoadFile("f:/documenti/calcio.bmp", wxBITMAP_TYPE_BMP)
 
 bmpDC.SelectObject(bmp)   ' To draw onto your bitmap, you must associate it to a pre-allocated memory space.
 bmpDC.DrawLine(0,0,10,20) ' Now you can draw your bitmap.
 
 'You can also insert this bitmap inside a button.
 button1=new wxBitmapButton(panel,-1,bmp2,wxPoint(10,10),wxSize(-1,-1))
 
 'If you specify wxNO_3D, button will be "flat", looking like a normal bitmap: so you can draw
 'bitmaps inside a panel (else, you could only draw them onto the main frame)..
 button2=new wxBitmapButton(panel,-1,bmp2,wxPoint(60,10),wxSize(50,50))
 
 
 Sub onPaint( event )
 dc = wxPaintDC( frame )
 dc.BeginDrawing()
 dc.Blit(0,0,320,200,bmpDC,0,0)
 dc.EndDrawing()
 End Sub
 Connect( frame, -1, wxEVT_PAINT, "onPaint" )
 
 frame.Show(True)
 


[edit] Additional example

bool HelloWorldApp::OnInit()
{
       wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
		

       wxPanel *panel = new wxPanel( frame, -1 ,wxPoint(0,100),wxSize(320,100)); 
       wxBitmap bitmap;


       bitmap.LoadFile("Blue.bmp", wxBITMAP_TYPE_BMP);
 
       // The last parameter (0) - so we have 2D behaviour
       wxBitmapButton *button1=new wxBitmapButton(panel,-1,bitmap,wxPoint(10,10),wxSize(50,50),0);
		
       frame->Show(TRUE);
       SetTopWindow(frame);
       return true;
}
Personal tools