C++ CLI Form Problems - Label Display

My overall goal is to create a program to read the mouse position on a form and control a servo motor attached to the program based on the mouse position. However, I am coming across an issue (or several) in the creation of the form and reading mouse position. I initially wrote the program using C++ console application to read to mouse position (since I am fairly new to Visual C++), which worked fine. Now I am trying to convert the program into something I can use with a form as I previously described. No errors occur and the form renders without an issue, however, no matter how long I have tried I can't get the label to display the coordinate position of the mouse. After thinking it might be an issue with my variables, I tried to just display anything into the label, and nothing happens.


MAIN FILE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "stdafx.h"
#include "Form1.h"
#include <stdio.h>
#include "windows.h"
#include <conio.h>
#include <iostream>

using namespace std;
using namespace MouseDynamixel;


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 Form1());
	return 0;

	Label ^ lblMouseX = gcnew Label;
	Label ^ lblMouseY;

	//get the position of cursor first
	POINT pos;
	GetCursorPos(&pos);
	int x=pos.x;
	int y=pos.y;

	//lblMouseX->Text = String::Format("L",x,y);
	lblMouseX->Text = "Hi";
	//lblMouseX->Text= Convert::ToString(x);
	lblMouseY->Text= Convert::ToString(y);	
}



Form1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once


namespace MouseDynamixel {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// 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 Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	public: System::Windows::Forms::Label^  lblMouseX;
	protected: 

	protected: 

	protected: 


	private: System::Windows::Forms::PictureBox^  pictureBox1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	public: System::Windows::Forms::Label^  lblMouseY;
	private: 
	private: System::Windows::Forms::Label^  label3;
	public: 
	public: 

	public: 
	private: 



	protected: 

	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)
		{
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
		this->lblMouseX = (gcnew System::Windows::Forms::Label());
		this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
		this->label1 = (gcnew System::Windows::Forms::Label());
		this->label2 = (gcnew System::Windows::Forms::Label());
		this->lblMouseY = (gcnew System::Windows::Forms::Label());
		this->label3 = (gcnew System::Windows::Forms::Label());
		(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
		this->SuspendLayout();
		// 
		// lblMouseX
		// 
		this->lblMouseX->BackColor = System::Drawing::SystemColors::ControlLight;
		this->lblMouseX->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
		this->lblMouseX->Location = System::Drawing::Point(135, 240);
		this->lblMouseX->Name = L"lblMouseX";
		this->lblMouseX->Size = System::Drawing::Size(35, 24);
		this->lblMouseX->TabIndex = 1;
		this->lblMouseX->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
		// 
		// pictureBox1
		// 
		this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.Image")));
		this->pictureBox1->InitialImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.InitialImage")));
		this->pictureBox1->Location = System::Drawing::Point(36, 12);
		this->pictureBox1->Name = L"pictureBox1";
		this->pictureBox1->Size = System::Drawing::Size(224, 225);
		this->pictureBox1->TabIndex = 0;
		this->pictureBox1->TabStop = false;
		this->pictureBox1->WaitOnLoad = true;
		this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
		// 
		// label1
		// 
		this->label1->AutoSize = true;
		this->label1->Location = System::Drawing::Point(12, 246);
		this->label1->Name = L"label1";
		this->label1->Size = System::Drawing::Size(81, 13);
		this->label1->TabIndex = 2;
		this->label1->Text = L"Current Position";
		// 
		// label2
		// 
		this->label2->AutoSize = true;
		this->label2->Location = System::Drawing::Point(111, 246);
		this->label2->Name = L"label2";
		this->label2->Size = System::Drawing::Size(17, 13);
		this->label2->TabIndex = 3;
		this->label2->Text = L"X:";
		// 
		// lblMouseY
		// 
		this->lblMouseY->BackColor = System::Drawing::SystemColors::ControlLight;
		this->lblMouseY->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
		this->lblMouseY->Location = System::Drawing::Point(234, 240);
		this->lblMouseY->Name = L"lblMouseY";
		this->lblMouseY->Size = System::Drawing::Size(35, 24);
		this->lblMouseY->TabIndex = 4;
		this->lblMouseY->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
		// 
		// label3
		// 
		this->label3->AutoSize = true;
		this->label3->Location = System::Drawing::Point(199, 246);
		this->label3->Name = L"label3";
		this->label3->Size = System::Drawing::Size(17, 13);
		this->label3->TabIndex = 5;
		this->label3->Text = L"Y:";
		// 
		// Form1
		// 
		this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
		this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
		this->ClientSize = System::Drawing::Size(292, 266);
		this->Controls->Add(this->label3);
		this->Controls->Add(this->lblMouseY);
		this->Controls->Add(this->label2);
		this->Controls->Add(this->label1);
		this->Controls->Add(this->lblMouseX);
		this->Controls->Add(this->pictureBox1);
		this->ForeColor = System::Drawing::SystemColors::ControlText;
		this->Name = L"Form1";
		this->Text = L"Form1";
		(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
		this->ResumeLayout(false);
		this->PerformLayout();

			}
#pragma endregion
	private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
				 }
		};
}


As you can see in the main program, I have tried many ways to do things, based on advice I saw on other posts, but nothing has worked. I am sure I am probably just missing some simple error, however, I cannot find it. Any advice to help me out would be greatly appreciate. The labels I am trying to display the text in are lblMouseX (for X coordinate) and lblMouseY (for Y coordinate).

Thanks

Note: Some parts of my code that I thought might be useful are commented out.
Topic archived. No new replies allowed.