Button

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
Artem
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 07, 2005 12:50 pm

Button

Post by Artem » Mon Aug 08, 2005 10:50 am

Can you tell me what is a wxValidator?
Or at least what wrong with this:

Code: Select all

wxButton *button = new wxButton(NULL, -1, "Click", wxPoint(10,10), wxSize(10,10), 1,0, "button");
I'm pretty shure that there should be something instead of the 0, it should be wxValidator type. But what this type is?

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Mon Aug 08, 2005 10:56 am

OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Artem
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 07, 2005 12:50 pm

Post by Artem » Mon Aug 08, 2005 2:29 pm

Thanks, it compiles but I can't see the button. Maybe creating a button is not enough, and I need also to make it show?
The new code:

Code: Select all

wxButton *button = new wxButton(NULL, -1, "Click", wxPoint(100,100), wxSize(10,10), wxBU_EXACTFIT, wxDefaultValidator, "button"); 
[/quote]

vdell
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell » Mon Aug 08, 2005 3:22 pm

Artem wrote:Thanks, it compiles but I can't see the button. Maybe creating a button is not enough, and I need also to make it show?
The new code:

Code: Select all

wxButton *button = new wxButton(NULL, -1, "Click", wxPoint(100,100), wxSize(10,10), wxBU_EXACTFIT, wxDefaultValidator, "button"); 
Parent must not be NULL, as said in the docs. Use your frame/dialog/panel as the parent for the button.
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere

Artem
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 07, 2005 12:50 pm

Post by Artem » Mon Aug 08, 2005 5:51 pm

Oh, I thought it said that it must be NULL....
Now I have another problem, the button expands itself to the hole window.
Image
How do I put a button inside my tool bar? I use this function to create a toolbar, how do I give it a name

Code: Select all

CreateToolBar(wxNO_BORDER|wxHORIZONTAL);

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon Aug 08, 2005 6:42 pm

It's an (undocumented) feature that the first control on the dialog / frame will expand completely, but only when there is one control on the top level. You can prevent this by putting the panel on the frame as single control, and the button as child of the frame.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Post by toxicBunny » Mon Aug 08, 2005 8:03 pm

Artem wrote:How do I put a button inside my tool bar? I use this function to create a toolbar, how do I give it a name

Code: Select all

CreateToolBar(wxNO_BORDER|wxHORIZONTAL);
Almost any control can be added to a Toolbar using wxToolBar::AddTool or wxToolBar::AddControl. The easiest thing for a button is to use the AddTool function.

http://www.wxwidgets.org/manuals/2.6.1/ ... baraddtool

Artem
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 07, 2005 12:50 pm

Post by Artem » Wed Aug 10, 2005 6:45 pm

Thanks for the reply.
I tried to make the toolbar bigger (by changing the size vaule in the constructor) to make it fit the button's size, but the tool bar stays the same size. Why is that happening?
Now I have another question. I read about setting a bitmap on the screen but I didn't understood it well, can some one give me a example of how to set a bitmap from a file. (a file such .png .jpeg .bmp etc.)
I hope it's not too much questions I'm asking.

Thank you
Artem

Artem
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Aug 07, 2005 12:50 pm

Post by Artem » Fri Aug 19, 2005 9:42 pm

Any help please :(

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Sat Aug 20, 2005 12:04 pm

Put something like this in your frame constructor:

Code: Select all

  // Create a toolbar.
  CreateToolBar(wxTB_FLAT);
  GetToolBar()->SetToolBitmapSize(wxSize(16, 16));
  GetToolBar()->AddTool(TOOLBAR_TRANSLATE, "Translate", wxImage("icons/translate.gif"), wxNullBitmap, wxITEM_NORMAL, "Translate", " Moves selected item.");
  GetToolBar()->AddTool(TOOLBAR_ROTATE, "Rotate", wxImage("icons/rotate.gif"), wxNullBitmap, wxITEM_NORMAL, "Rotate", " Rotates selected item.");
  GetToolBar()->AddTool(TOOLBAR_SCALE, "Scale", wxImage("icons/scale.gif"), wxNullBitmap, wxITEM_NORMAL, "Scale", " Scales selected item.");
  GetToolBar()->AddSeparator();
  GetToolBar()->AddTool(TOOLBAR_INFLATE, "Inflate", wxImage("icons/inflate.gif"), wxNullBitmap, wxITEM_NORMAL, "Inflate", " Translates surface along normal.");
  GetToolBar()->AddTool(TOOLBAR_EXTRUDE, "Extrude", wxImage("icons/extrude.gif"), wxNullBitmap, wxITEM_NORMAL, "Extrude", " Pulls out a new segment.");
  GetToolBar()->AddTool(TOOLBAR_SHRINK, "Shrink", wxImage("icons/shrink.gif"), wxNullBitmap, wxITEM_NORMAL, "Shrink", " Shrinks patch.");
  GetToolBar()->AddTool(TOOLBAR_CUT, "Cut", wxImage("icons/cut.gif"), wxNullBitmap, wxITEM_NORMAL, "Cut", " Cut, slice and dice.");
  GetToolBar()->Realize();

Post Reply