In Visual C++ Express Edition you can insert button controls on a form.
These buttons has a rectangular form. You can even do them like a square.

Is it possible to do Round Buttons in C++, like this letter: O ?

(It is important that the area where you click is Rounded.)
Thank you...

Recommended Answers

All 8 Replies

That was nice. I have to ask though. On the link I will downloaded the sourcefiles wich includes a RoundButton.h and another file RoundButton C++ Source file.

What I now need to do is to include this headerfile into the project like this ?

#include "RoundButton.h"

I have tried to put both the source file and headerfile into these path locations

C:\Program Files\Microsoft Visual Studio 9.0\VC\Include

C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\.NET\WinForm\templates\1033

and also trid to #include "RoundButton.h" but the compiler says:

'CButton' : base class undefined
'DECLARE_MESSAGE_MAP': missing return type; assumed to be a member function returning 'int'

Have I included the files in a correct way, I wonder ?


I think this is what you need http://www.codeproject.com/KB/buttons/roundbuttons.aspx

Have you added these files to your solution?

You are right. Now I did manage to Add these Items to the solution.
Both the .h header file for "Header Files" and the Source File for "Source Files".

The funny is now that when I compile with these 2 added to the project is that these files seems to contain a lot of bugs and errors

This shows about 20 % of the compilererrors:

1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(120) : error C2146: syntax error : missing ')' before identifier 'p'
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(120) : error C2182: 'DrawCircle' : illegal use of type 'void'
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(120) : error C2374: 'DrawCircle' : redefinition; multiple initialization
1>        ..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(43) : see declaration of 'DrawCircle'
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(120) : error C2078: too many initializers
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(120) : error C2059: syntax error : ')'
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(121) : error C2143: syntax error : missing ';' before '{'
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(121) : error C2447: '{' : missing function header (old-style formal list?)
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(181) : error C2065: 'm_bDrawDashedFocusCircle' : undeclared identifier
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(181) : error C2065: 'TRUE' : undeclared identifier
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(186) : error C2065: 'm_rgn' : undeclared identifier
1>..\..\..\..\..\Desktop\RoundButtons_src\RoundButton.cpp(186) : error C2228: left of '.DeleteObject' must have class/struct/union

Have I done something wrong or could it be that there are a lot of bugs in these files ?

Have you added these files to your solution?

I did found out that this headerfiles was for a MFC applicaton.

I am using a FormApplication and are trying to get a class for this type.

I have managed to use the _Paint Event of the button to "Repaint" the button to make it Rounded.
So this Code works greatly that I have set up.

However there is one last thing with the button that I am trying to achieve(I have attached a picture of the button) and that is that the button shows borders.

What I want to do is to make the button completely Transparent so an image could be set to the button without any disturbing borders around it.

The button has now FlatStyle Flat and In FlatAppearance I have set BorderColor to White and BorderSize to 0, so it should not be any borders on this button but it is anyway.
Then also the BackColor of the Button is Transparant.

Perheps any Paint method could be added to take the borders away from the rounded button below ?

private: System::Void button5_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
{
		 
System::Drawing::Drawing2D::GraphicsPath^ buttonPath = gcnew System::Drawing::Drawing2D::GraphicsPath();


// Set a new rectangle to the same size as the button's ClientRectangle property.System::Drawing::Rectangle newRectangle = button5->ClientRectangle;


// Decrease the size of the rectangle.
newRectangle.Inflate(-25, -1.5);


// Draw the button's border.
e->Graphics->DrawEllipse(System::Drawing::Pens::Black, newRectangle);


// Increase the size of the rectangle to include the border.
newRectangle.Inflate(1, 1);


// Create a circle within the new rectangle.
buttonPath->AddEllipse(newRectangle);


// Set the button's Region property to the newly created circle region.
button5->Region = gcnew System::Drawing::Region(buttonPath);
		 
}

In the previous post I have created a Round button with code and the image in the previous post shows that the button has Black Borders.
My problem is that I need the button to have no borders, so I have tried to use this code but when running the program, an error says that Transparent is not possible to use.

How can I take the black borders away from the button ?

button1->FlatAppearance->BorderColor = Color::Transparent;

I am not sure if this could solve it in the constructor of the button.

// Draw the button's border.
e->Graphics->DrawEllipse(System::Drawing::Pens::Transparent, newRectangle);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.