Hello
i'm using visual studio 2010 express. I'm beginner. I'm searching how to design a button and to program it ?
Thanks for any help

Recommended Answers

All 6 Replies

In the properties window, you can change many properties of a button to fit your needs. Have a look at the generated code in the form.h file. See how it works and if you wish, you can write this code for yourself also.

In truth, this isn't a C++ issue. It is a Visual Studio issue. Ok, I may be nit-picking now, but this ISN'T a C++ problem!

i'm searching how to start with c++ ( how to have first the .h then then the .cpp ) and which code for example to write for obtaining a coded button.

The Designer in Visual Studio generated code for a button like this:
I simply dragged a button from the toolbox window onto the form and changed its Text property in the Property window.

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());

            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(37, 192);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"start";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);

Nothing withholds you to implement a code like this in your own code instead of using a designer. This can be even necessary if you need lots of buttons in an array.(eg you want to make a calculator) But my guess is you are an absolute beginner. So why not start with a console application?You will have no buttons in a console window however.

Thanks a lot, i have tried a console application. now i'm asking which steps to obtain a button (for example which can import data or import an image in my screen or either your

button1_Click

how to initialise it? by which steps ? for example i add a cpp file where i add your code ?
thanks for your advice and details.

It is not my code, it is generated automaticaly by the designer.
In the designer, when you doubleclick a button, it will generate the code to handle a click event on the button.

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.