Sign in to follow this  

Windows Form Help

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I thought I'd have ago at just doing a basic card game using windows forms. The problem is that I'm having trouble understanding how you actually tell windows to use the custom form designed in forms designer. I've got my basic message loop and window but how do I tell it to populate the window with the designed form ? Below is just a basic form created in the designer,
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace Main {

	/// <summary>
	/// Summary for BlackJackForm
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class BlackJackForm : public System::Windows::Forms::Form
	{
	public:
		BlackJackForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~BlackJackForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::TextBox^  textBox1;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#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->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(267, 174);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(187, 51);
			this->button1->TabIndex = 0;
			this->button1->Text = L"button1";
			this->button1->UseVisualstyleBackColor = true;
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(203, 94);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(322, 22);
			this->textBox1->TabIndex = 1;
			// 
			// BlackJackForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(841, 446);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button1);
			this->Name = L"BlackJackForm";
			this->Text = L"BlackJackForm";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	};
}

I'm having real trouble understanding the basics of this but what do I need to do to get windows to reconise the form ? I've programmed the game and its just a case of creating an interface. I know how to hardcode the menu using the windows api but it would take way too long for me to add each button and label etc. Anyone know of a good tutorial site that explains the very basics of windows forms as msdn seems so vague and assumes so much.

Share this post


Link to post
Share on other sites
Visual Studio is supposed to create the basic application framework for you, if you're using Windows Forms Designer.

That said, you need a main() function. main() in Managed C++ works the same way as regular C++ - its where the program starts. From there, you should instantiate your form class. By default, this is what Visual Studio should have generated for you:


#include "Main.h"

using namespace Main;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew BlackJackForm());
return 0;
}

Share this post


Link to post
Share on other sites

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this