Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Programmatically Create A WinForm Gui With C++/Cli


Recommended Posts

Hi,

I am working on a gui using c++/cli and winforms, I am using it for my nesting add on but it sure could be put to use elsewhere here is the code :


System::Windows::Forms::ListView^ GetListViewFromPoint(int x, int y, System::Windows::Forms::Control ^ control);
//function declaration should be moved to header.h file
void DynamicButtonClick(System::Object ^ sender, System::EventArgs ^ e);
void DynamicListClick(System::Object ^ sender, System::EventArgs ^ e);
void CreateListViewOnWinform(int Left, int Top, int Width, int Height, System::Windows::Forms::Form ^ Form,int mainlistview);

void CreateTextboxOnWinform(int Left4, int Top4, int Width4, int Height4, System::Windows::Forms::Form ^ Form);


public ref struct NestingPart
{
	System::String ^ pathtofile;
	System::String ^ filename;
	System::Int32 ^ quantity; 
};
array<NestingPart ^> ^ NestingPartArray(array<System::String ^> ^ StringArray)
{
	bool arrayisempty = true;
	auto nestingpartlist = gcnew System::Collections::Generic::List<NestingPart^>;
	if (StringArray->Length > 0)
	{
		for (auto i = 0; i < StringArray->Length; i++)
		{
			auto currentpart = gcnew NestingPart();
			currentpart->pathtofile = StringArray[i];
			currentpart->filename = System::IO::Path::GetFileName(StringArray[i]);
			currentpart->quantity = 1;
			nestingpartlist->Add(currentpart);
			arrayisempty = false;
		}

	}
	return !arrayisempty ? nestingpartlist->ToArray() : gcnew array<NestingPart ^>(0);
}

void CreateTextboxOnWinform(int Left4, int Top4, int Width4, int Height4, System::Windows::Forms::Form ^ Form)
{

	System::Windows::Forms::TextBox ^ txtbox = gcnew System::Windows::Forms::TextBox;
	txtbox->Left = Left4;
	txtbox->Top = Top4;
	txtbox->Width = Width4;
	txtbox->Height = Height4;
	txtbox->Text = "";
	txtbox->BackColor = System::Drawing::Color::Black;
	txtbox->ForeColor = System::Drawing::Color::White;
	Form->Controls->Add(txtbox);
}

int main()
{
	//add the windows form
	System::Windows::Forms::Form ^ Form = gcnew System::Windows::Forms::Form;
	Form->BackColor = System::Drawing::Color::DarkGray;
	Form->Width = 1250;
	Form->Height = 650;
	Form->AutoScroll = true;
	Form->HorizontalScroll->Maximum = 0;
	Form->VerticalScroll->Visible = true;
	Form->VerticalScroll->Enabled = true;
	Form->HorizontalScroll->Enabled = false;
	Form->HorizontalScroll->Enabled = false;
	Form->HorizontalScroll->Visible = false;
	
	//add the list view to the windows form
	int Left = 10; int Top = 75; int Width = 500; int Height = Form->Height - 150;
	CreateListViewOnWinform(Left, Top, Width, Height, Form,1);
	int Left2 = 550; int Top2 = 75; int Width2 = 50; int Height2 = Form->Height - 150;
	CreateListViewOnWinform(Left2, Top2, Width2, Height2, Form,0);
	int Left3 = 625; int Top3 = 75; int Width3 = 400; int Height3 = Form->Height - 150;
	CreateListViewOnWinform(Left3, Top3, Width3, Height3, Form,0);
	//add the textbox to the windows form
	
	int Left4 = 135; int Top4 = 10; int Width4 = 600; int Height4 = 50; 
	CreateTextboxOnWinform(Left4, Top4, Width4, Height4, Form);
	int Left5 = 0; int Top5 = 50; int Width5 = 100; int Height5 = 50;
	CreateTextboxOnWinform(Left5, Top5, Width5, Height5, Form);
	//add the label control to the windows form
	System::Windows::Forms::Label ^ label = gcnew System::Windows::Forms::Label;
	label->Left = 10;
	label->Top = 10;
	label->Width = 135;
	label->Height = 18;
	label->Text = "Folder Path To Nest ->";
	label->BackColor = System::Drawing::Color::Black;
	label->ForeColor = System::Drawing::Color::White;
	Form->Controls->Add(label);
	//add the button control to the windows form
	System::Windows::Forms::Button ^ button = gcnew System::Windows::Forms::Button;
	button->Left = 720;
	button->Top = 10;
	button->Width = 100;
	button->Height = 18;
	button->Name = "button1";
	button->Text = "Load Parts";
	button->BackColor = System::Drawing::Color::Black;
	button->ForeColor = System::Drawing::Color::White;
	//add event handler to the button //function below
	button->Click += gcnew System::EventHandler(DynamicButtonClick);
	

	Form->Controls->Add(button);
	//spawn the windows form
    System::Windows::Forms::Application::Run(Form);
	return 0;
}

void CreateListViewOnWinform(int Left, int Top, int Width, int Height, System::Windows::Forms::Form ^ Form,int mainlistitem)
{
	System::Windows::Forms::ListView ^ ListView1 = gcnew System::Windows::Forms::ListView;
	ListView1->Left = Left;
	ListView1->Top = Top;
	ListView1->Width = Width;
	ListView1->Height = Height;
	ListView1->BackColor = System::Drawing::Color::Black;
	ListView1->ForeColor = System::Drawing::Color::White;
	auto header = gcnew System::Windows::Forms::ColumnHeader();
	header->Text = "                            ";
	header->Name = "col1";
	header->Width = Width;
	ListView1->Columns->Add(header);
	ListView1->Scrollable = true;
	ListView1->View = System::Windows::Forms::View::Details;
	if (mainlistitem == 1)
	{
		ListView1->Click += gcnew System::EventHandler(DynamicListClick);
	}
	//ShowScrollBar(static_cast<HWND>(ListView1->Handle.ToPointer()), (int)SB_VERT, true)
	Form->Controls->Add(ListView1);
}

System::Windows::Forms::ListView^ GetListViewFromPoint(int x, int y, System::Windows::Forms::Control ^ control)
{
	System::Drawing::Point listviewpoint;
	//define x position
	listviewpoint.X = x;
	//define y position
	listviewpoint.Y = y;
	//get the parent System::Windows::Forms::Form
	auto listviewformcontrol = control->GetChildAtPoint(listviewpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	return dynamic_cast<System::Windows::Forms::ListView^>(listviewformcontrol);
}

//The signature of Button click event handler is listed in the following code snippet.
void DynamicListClick(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto list = dynamic_cast<System::Windows::Forms::ListView ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = list->Parent;
	//create a point to use as a reference to identify a contro
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);
	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control); 
	//auto item = listview->FindItemWithText(list->Text);
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist = listview->Items;// SelectedItems;
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist2 = listview2->Items;// SelectedItems;
	System::Drawing::Point textpoint;
	//define x position
	textpoint.X = 0;
	//define y position
	textpoint.Y = 50;
	//get the parent System::Windows::Forms::Form
	auto txtformcontrol = control->GetChildAtPoint(textpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	auto textbox = dynamic_cast<System::Windows::Forms::TextBox^>(txtformcontrol);

	System::String ^ msg1 = "Enter a new Quantity!";	System::String ^ msg2 = "Nesting"; System::String ^ msg3 = "1";
	auto response = Microsoft::VisualBasic::Interaction::InputBox(msg1, msg2, msg3, 100, 100);
	for (auto i = 0; i < itemlist->Count; i++)
	{
		
		if (itemlist[i]->Selected == true)

		
		{
			textbox->Text = itemlist2[i]->Text;
			//System::Windows::Forms::MessageBox::Show(itemlist[i]->Text);
			itemlist2[i]->Text = response;
		}
	}
}
//The signature of Button click event handler is listed in the following code snippet.
void DynamicButtonClick(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto button = dynamic_cast<System::Windows::Forms::Button ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = button->Parent; 
	//create a point to use as a reference to identify a control
	System::Drawing::Point textpoint;
	//define x position
	textpoint.X = 150;
	//define y position
	textpoint.Y = 10;
	//get the parent System::Windows::Forms::Form
	auto txtformcontrol = control->GetChildAtPoint(textpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	auto textbox = dynamic_cast<System::Windows::Forms::TextBox^>(txtformcontrol);
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);
	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control);
	//create a variable to hold the path for clarity
	auto filepathtodirectory = textbox->Text;
	//check that the user entered something
	if (filepathtodirectory != "")
	{
		//check that we have a valid path
		if (System::IO::Directory::Exists(filepathtodirectory))
		{
			
			//get the files in the user defined folder using a filter to check the extension
			auto list = System::IO::Directory::GetFiles(filepathtodirectory, "*.txt*");
			if (list->Length > 0)
			{
				auto nestingpartarray = NestingPartArray(list);
				//System::Windows::Forms::MessageBox::Show(nestingpartarray->Length.ToString());
				for (auto i = 0; i < nestingpartarray->Length; i++)
				{
					auto filename = nestingpartarray[i]->filename;
					auto filepath = nestingpartarray[i]->pathtofile;
					auto quantity = nestingpartarray[i]->quantity;
					auto listViewItem1 = gcnew System::Windows::Forms::ListViewItem(filename);
					listview->Items->Add(listViewItem1);
					auto listViewItem2 = gcnew System::Windows::Forms::ListViewItem(quantity->ToString());
					listview2->Items->Add(listViewItem2);
					auto listViewItem3 = gcnew System::Windows::Forms::ListViewItem(filepath);
					listview3->Items->Add(listViewItem3);
				}
			}
		}
	}
}

 

Link to comment
Share on other sites

void ClickEventLaunchNesting(System::Object ^ sender, System::EventArgs ^ e);
void ClickEventClearAllParts(System::Object ^ sender, System::EventArgs ^ e);
System::Windows::Forms::ListView^ GetListViewFromPoint(int x, int y, System::Windows::Forms::Control ^ control);
//function declaration should be moved to header.h file
void ClickEventLoadParts(System::Object ^ sender, System::EventArgs ^ e);

System::Windows::Forms::Control ^ GetTextboxControlFromPoint(System::Windows::Forms::Control ^ control, int x, int y);

void ClickEventIncreasePartQuantity(System::Object ^ sender, System::EventArgs ^ e);

void CreateListViewOnWinform(int Left, int Top, int Width, int Height, System::Windows::Forms::Form ^ Form,int mainlistview);

void CreateTextboxOnWinform(int Left4, int Top4, int Width4, int Height4, System::Windows::Forms::Form ^ Form);

void CreateButtonOnForm(int buttonleft, int buttontop, int buttonwidth, int buttonheight, System::String ^ buttonname, System::String ^ buttonname2, System::Windows::Forms::Form ^ Form, void(*funtioninput)(System::Object ^ sender, System::EventArgs ^ e));

void CreateLabelOnForm(int labelleft, int labeltop, int labelwidth, int labelheight, System::String ^ labelmessage, System::Windows::Forms::Form ^ Form);

void DynamicListClick(System::Object ^ sender, System::EventArgs ^ e);
public ref struct NestingPart
{
	System::String ^ pathtofile;
	System::String ^ filename;
	System::Int32 ^ quantity; 
};
public ref struct NestingSheet
{
	System::String ^ materialname;
	int ^ width;
	int ^ height;
	System::Double ^ stockthickness;
};
array<NestingPart ^> ^ NestingPartArray(array<System::String ^> ^ StringArray)
{
	bool arrayisempty = true;
	auto nestingpartlist = gcnew System::Collections::Generic::List<NestingPart^>;
	if (StringArray->Length > 0)
	{
		for (auto i = 0; i < StringArray->Length; i++)
		{
			auto currentpart = gcnew NestingPart();
			currentpart->pathtofile = StringArray[i];
			currentpart->filename = System::IO::Path::GetFileName(StringArray[i]);
			currentpart->quantity = 1;
			nestingpartlist->Add(currentpart);
			arrayisempty = false;
		}

	}
	return !arrayisempty ? nestingpartlist->ToArray() : gcnew array<NestingPart ^>(0);
}

void CreateTextboxOnWinform(int Left4, int Top4, int Width4, int Height4, System::Windows::Forms::Form ^ Form)
{

	System::Windows::Forms::TextBox ^ txtbox = gcnew System::Windows::Forms::TextBox;
	txtbox->Left = Left4;
	txtbox->Top = Top4;
	txtbox->Width = Width4;
	txtbox->Height = Height4;
	txtbox->Text = "";
	txtbox->BackColor = System::Drawing::Color::Black;
	txtbox->ForeColor = System::Drawing::Color::White;
	Form->Controls->Add(txtbox);
}

int main()
{
	//add the windows form
	System::Windows::Forms::Form ^ Form = gcnew System::Windows::Forms::Form;
	Form->BackColor = System::Drawing::Color::DarkGray;
	Form->Width = 1500;
	Form->Height = 650;
	Form->AutoScroll = true;
	Form->HorizontalScroll->Maximum = 0;
	Form->VerticalScroll->Visible = true;
	Form->VerticalScroll->Enabled = true;
	Form->HorizontalScroll->Enabled = false;
	Form->HorizontalScroll->Enabled = false;
	Form->HorizontalScroll->Visible = false;
	
	//add the list view to the windows form
	int Left = 10; int Top = 75; int Width = 500; int Height = Form->Height - 150;
	CreateListViewOnWinform(Left, Top, Width, Height, Form,1);
	int Left2 = 550; int Top2 = 75; int Width2 = 50; int Height2 = Form->Height - 150;
	CreateListViewOnWinform(Left2, Top2, Width2, Height2, Form,0);
	int Left3 = 625; int Top3 = 75; int Width3 = 400; int Height3 = Form->Height - 150;
	CreateListViewOnWinform(Left3, Top3, Width3, Height3, Form,0);
	//add the textbox to the windows form
	int Left4 = 135; int Top4 = 10; int Width4 = 600; int Height4 = 50; 

	CreateTextboxOnWinform(Left4, Top4, Width4, Height4, Form);

	int Left5 = 135; int Top5 = 50; int Width5 = 100; int Height5 = 50;

	CreateTextboxOnWinform(Left5, Top5, Width5, Height5, Form);

	CreateTextboxOnWinform(725, Top5, 150, Height5, Form);

	CreateTextboxOnWinform(900, Top5, 50, Height5, Form);

	CreateTextboxOnWinform(975, Top5, 50, Height5, Form);
	//add the label control to the windows form
	int labelheight = 18; int labelwidth = 135; int labelleft = 10; int labeltop = 10; 

	CreateLabelOnForm(labelleft, labeltop, labelwidth, labelheight, "Folder Path To Nest ->", Form);

	CreateLabelOnForm(10, Top5, Width5, labelheight, "Current Qty : ", Form);

	CreateLabelOnForm(625, Top5, Width5, labelheight, "Material Name -> ", Form);

	CreateLabelOnForm(875, Top5, 25, labelheight, "X->", Form);

	CreateLabelOnForm(950, Top5, 25, labelheight, "Y->", Form);

	int buttonheight = 18; int buttonwidth = 100; int buttonleft = 720; int buttontop = 10;
	//add the button control to the windows form
	CreateButtonOnForm(buttonleft, buttontop, buttonwidth, buttonheight, "button1", "Load Parts", Form, ClickEventLoadParts);
	//add the button control to the windows form
	CreateButtonOnForm(buttonleft + buttonwidth, buttontop, buttonwidth, buttonheight, "button2", "Clear All Parts", Form, ClickEventClearAllParts);
	//add the button control to the windows form
	CreateButtonOnForm(buttonleft + buttonwidth + buttonwidth, buttontop, buttonwidth, buttonheight, "button3", "Launch Nesting", Form, ClickEventLaunchNesting);
	//add the button control to the windows form
	CreateButtonOnForm(250, Top5, Width5, buttonheight, "button4", "Set New Quantity", Form, ClickEventIncreasePartQuantity);


	//spawn the windows form
    System::Windows::Forms::Application::Run(Form);
	return 0;
}

void CreateButtonOnForm(int buttonleft, int buttontop, int buttonwidth, int buttonheight, System::String ^ buttonname, System::String ^ buttonname2, System::Windows::Forms::Form ^ Form, void(*funtioninput)(System::Object ^ sender, System::EventArgs ^ e))
{
	System::Windows::Forms::Button ^ button = gcnew System::Windows::Forms::Button;
	button->Left = buttonleft;
	button->Top = buttontop;
	button->Width = buttonwidth;
	button->Height = buttonheight;
	button->Name = buttonname;
	button->Text = buttonname2;
	button->BackColor = System::Drawing::Color::Black;
	button->ForeColor = System::Drawing::Color::White;
	//add event handler to the button //function below
	button->Click += gcnew System::EventHandler(funtioninput);


	Form->Controls->Add(button);
}

void CreateLabelOnForm(int labelleft, int labeltop, int labelwidth, int labelheight, System::String ^ labelmessage, System::Windows::Forms::Form ^ Form)
{
	System::Windows::Forms::Label ^ label = gcnew System::Windows::Forms::Label;
	label->Left = labelleft;
	label->Top = labeltop;
	label->Width = labelwidth;
	label->Height = labelheight;
	label->Text = labelmessage;
	label->BackColor = System::Drawing::Color::Black;
	label->ForeColor = System::Drawing::Color::White;
	Form->Controls->Add(label);
}

void CreateListViewOnWinform(int Left, int Top, int Width, int Height, System::Windows::Forms::Form ^ Form,int mainlistitem)
{
	System::Windows::Forms::ListView ^ ListView1 = gcnew System::Windows::Forms::ListView;
	ListView1->Left = Left;
	ListView1->Top = Top;
	ListView1->Width = Width;
	ListView1->Height = Height;
	ListView1->BackColor = System::Drawing::Color::Black;
	ListView1->ForeColor = System::Drawing::Color::White;
	auto header = gcnew System::Windows::Forms::ColumnHeader();
	header->Text = "                            ";
	header->Name = "col1";
	header->Width = Width;
	ListView1->Columns->Add(header);
	ListView1->Scrollable = true;
	ListView1->View = System::Windows::Forms::View::Details;
	if (mainlistitem == 1)
	{
		ListView1->Click += gcnew System::EventHandler(DynamicListClick);
	}
	//ShowScrollBar(static_cast<HWND>(ListView1->Handle.ToPointer()), (int)SB_VERT, true)
	Form->Controls->Add(ListView1);
}

System::Windows::Forms::ListView^ GetListViewFromPoint(int x, int y, System::Windows::Forms::Control ^ control)
{
	System::Drawing::Point listviewpoint;
	//define x position
	listviewpoint.X = x;
	//define y position
	listviewpoint.Y = y;
	//get the parent System::Windows::Forms::Form
	auto listviewformcontrol = control->GetChildAtPoint(listviewpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	return dynamic_cast<System::Windows::Forms::ListView^>(listviewformcontrol);
}

//The signature of Button click event handler is listed in the following code snippet.
void ClickEventIncreasePartQuantity(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto list = dynamic_cast<System::Windows::Forms::Button ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = list->Parent;
	//create a point to use as a reference to identify a contro
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);

	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control); 
	//auto item = listview->FindItemWithText(list->Text);
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist = listview->Items;// SelectedItems;
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist2 = listview2->Items;// SelectedItems;
	System::Drawing::Point textpoint;
	//define x position
	textpoint.X = 135;
	//define y position
	textpoint.Y = 50;
	//get the parent System::Windows::Forms::Form
	auto txtformcontrol = control->GetChildAtPoint(textpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	auto textbox = dynamic_cast<System::Windows::Forms::TextBox^>(txtformcontrol);

	//System::String ^ msg1 = "Enter a new Quantity!";	System::String ^ msg2 = "Nesting"; System::String ^ msg3 = "1";
	auto response = textbox->Text;//Microsoft::VisualBasic::Interaction::InputBox(msg1, msg2, msg3, 100, 100);
	for (auto i = 0; i < itemlist->Count; i++)
	{
		
		if (itemlist[i]->Selected == true)

		
		{
			//textbox->Text = itemlist2[i]->Text;
			//System::Windows::Forms::MessageBox::Show(itemlist[i]->Text);
			itemlist2[i]->Text = response;
		}
	}
}

//The signature of Button click event handler is listed in the following code snippet.
void ClickEventClearAllParts(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto list = dynamic_cast<System::Windows::Forms::Button ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = list->Parent;
	//create a point to use as a reference to identify a contro
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);

	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control);
	//auto item = listview->FindItemWithText(list->Text);
	listview->Items->Clear();
	listview->Update(); // In case there is databinding
	listview->Refresh(); // Redraw items
	listview2->Items->Clear();
	listview2->Update(); // In case there is databinding
	listview2->Refresh(); // Redraw items
	listview3->Items->Clear();
	listview3->Update(); // In case there is databinding
	listview3->Refresh(); // Redraw items

}
//The signature of Button click event handler is listed in the following code snippet.
void ClickEventLaunchNesting(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto list = dynamic_cast<System::Windows::Forms::Button ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = list->Parent;
	//create a point to use as a reference to identify a contro
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);

	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control);
	//auto item = listview->FindItemWithText(list->Text);
//TO DO : add in function to pass the necessary information to the nesting

}
//The signature of Button click event handler is listed in the following code snippet.
void DynamicListClick(System::Object ^ sender, System::EventArgs ^ e)
{

	//typecast the sender object as a button so we can use it to access the parent winform
	auto list = dynamic_cast<System::Windows::Forms::ListView ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = list->Parent;
	//create a point to use as a reference to identify a contro
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);
	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control);
	//auto item = listview->FindItemWithText(list->Text);
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist = listview->Items;// SelectedItems;
	System::Windows::Forms::ListView::ListViewItemCollection ^ itemlist2 = listview2->Items;// SelectedItems;
	System::Drawing::Point labelpoint;
	//define x position
	labelpoint.X = 10;
	//define y position
	labelpoint.Y = 50;
	//get the parent System::Windows::Forms::Form
	auto labelformcontrol = control->GetChildAtPoint(labelpoint);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	auto label = dynamic_cast<System::Windows::Forms::Label^>(labelformcontrol);


	for (auto i = 0; i < itemlist->Count; i++)
	{

		if (itemlist[i]->Selected == true)


		{
			label->Text = "Current Qty: " + itemlist2[i]->Text;
			//System::Windows::Forms::MessageBox::Show(itemlist[i]->Text);
			//itemlist2[i]->Text = response;
		}
	}
	
}
//The signature of Button click event handler is listed in the following code snippet.
//The signature of Button click event handler is listed in the following code snippet.
void ClickEventLoadParts(System::Object ^ sender, System::EventArgs ^ e)
{
	array<NestingSheet ^>^ materialarray = gcnew array<NestingSheet ^>(2);//
	NestingSheet ^ mdfsheet = gcnew NestingSheet;
	mdfsheet->height = 48;
	mdfsheet->width = 96;
	mdfsheet->stockthickness = .75;
	mdfsheet->materialname = "mdf";
	materialarray[0] = mdfsheet;
	NestingSheet ^ carbonfibersheet = gcnew NestingSheet;
	carbonfibersheet->height = 24;
	carbonfibersheet->width = 24;
	carbonfibersheet->stockthickness = .08;
	carbonfibersheet->materialname = "carbon-fiber";
	materialarray[1] = carbonfibersheet;
	//typecast the sender object as a button so we can use it to access the parent winform
	auto button = dynamic_cast<System::Windows::Forms::Button ^> (sender);
	//access the parent winform (System::Windows::Forms::Form)
	auto control = button->Parent;
	//create a point to use as a reference to identify a control
	auto txtformcontrol = GetTextboxControlFromPoint(control, 150, 10);

	auto txtformcontrol2 = GetTextboxControlFromPoint(control, 725, 50);

	auto txtformcontrol3 = GetTextboxControlFromPoint(control, 900, 50);

	auto txtformcontrol4 = GetTextboxControlFromPoint(control, 975, 50);
	//typecast the System::Windows::Forms::Control as a textbox so we can access it
	auto textbox = dynamic_cast<System::Windows::Forms::TextBox^>(txtformcontrol);
	int x = 10; int y = 75;
	//create a point to use as a reference to identify a control
	auto listview = GetListViewFromPoint(x, y, control);
	int x2 = 550; int y2 = 75;
	//create a point to use as a reference to identify a control
	auto listview2 = GetListViewFromPoint(x2, y2, control);
	int x3 = 625; int y3 = 75;
	//create a point to use as a reference to identify a control
	auto listview3 = GetListViewFromPoint(x3, y3, control);
	listview->Items->Clear();
	listview->Update(); // In case there is databinding
	listview->Refresh(); // Redraw items
	listview2->Items->Clear();
	listview2->Update(); // In case there is databinding
	listview2->Refresh(); // Redraw items
	listview3->Items->Clear();
	listview3->Update(); // In case there is databinding
	listview3->Refresh(); // Redraw items
	//create a variable to hold the path for clarity
	auto filepathtodirectory = textbox->Text;
	//check that the user entered something
	if (filepathtodirectory != "")
	{
		//check that we have a valid path
		if (System::IO::Directory::Exists(filepathtodirectory))
		{

			//get the files in the user defined folder using a filter to check the extension
			auto list = System::IO::Directory::GetFiles(filepathtodirectory, "*.txt*");
			if (list->Length > 0)
			{
				auto nestingpartarray = NestingPartArray(list);
				//System::Windows::Forms::MessageBox::Show(nestingpartarray->Length.ToString());
				for (auto i = 0; i < nestingpartarray->Length; i++)
				{
					
					auto filename = nestingpartarray[i]->filename;
					auto filepath = nestingpartarray[i]->pathtofile;
					auto quantity = nestingpartarray[i]->quantity;
					for (auto j = 0; j < materialarray->Length; j++)
					{
						if (filename->IndexOf( materialarray[j]->materialname,System::StringComparison::InvariantCultureIgnoreCase) >= 0)
							
						{
							txtformcontrol2->Text = materialarray[j]->materialname;
							txtformcontrol3->Text = materialarray[j]->width->ToString();
							txtformcontrol4->Text = materialarray[j]->height->ToString();
						}
					}
					auto listViewItem1 = gcnew System::Windows::Forms::ListViewItem(filename);
					listview->Items->Add(listViewItem1);
					auto listViewItem2 = gcnew System::Windows::Forms::ListViewItem(quantity->ToString());
					listview2->Items->Add(listViewItem2);
					auto listViewItem3 = gcnew System::Windows::Forms::ListViewItem(filepath);
					listview3->Items->Add(listViewItem3);
				}
			}
		}
	}
}

System::Windows::Forms::Control ^ GetTextboxControlFromPoint(System::Windows::Forms::Control ^ control,int x ,int y)
{
	System::Drawing::Point textpoint;
	//define x position
	textpoint.X = x;
	//define y position
	textpoint.Y = y;
	//get the parent System::Windows::Forms::Form
	return control->GetChildAtPoint(textpoint);
}

I added in a few more boxes and controls, now I should be able to tie the nesting add on I created with this form and that should get me as far as the stock setup/drilling location holes point.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...