I'm beginner to Visual C++ Windows Forms and i have kind of huge problem (I can't find solution for a few days...)
Basically i have basic program form Online Templates. I added a few text boxes, labels, button and a class. Class is a BattleCard and it's supossed to "fight" using it's Defend() function and using text box Text as their stats. The problem appears when i try to make this like turn based, so you need to click Start button every round... Everything is fine except the fact, that once i clicked button and all calculations are finished... Object and all stats are deleted. That means object will start with start HP etc. instead of one it just calculated. Do you have any ideas how to work around it or just make these objects "undeletable"?
BattleCard.h
#pragma once
ref class BattleCard
{
public:
int Attack;
int Defense;
int HP;
bool Exist = false;
void Defend(int Attack, int Defense);
BattleCard(int A, int D, int H);
};
BattleCard.cpp
#include "BattleCard.h"
BattleCard::BattleCard(int A, int D, int H)
{
if (Exist == false) { Attack = A; Defense = D; HP = H; Exist = true; }
}
void BattleCard::Defend(int Attack, int Defense)
{
this->HP = (double)this->HP - (double)Attack*((double)1 - ((double)Defense / ((double)Defense + (double)50)));
}
MyForm.h
#pragma once
#include <stdlib.h>
#include <array>
#include <string>
#include <iostream>
#include "BattleCard.h"
namespace CppWinForm2 {
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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Panel^ panel1;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Panel^ panel2;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
#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->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->panel2 = (gcnew System::Windows::Forms::Panel());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->panel1->SuspendLayout();
this->panel2->SuspendLayout();
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(106, 0);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 0;
//
// panel1
//
this->panel1->Controls->Add(this->label3);
this->panel1->Controls->Add(this->label2);
this->panel1->Controls->Add(this->label1);
this->panel1->Controls->Add(this->textBox3);
this->panel1->Controls->Add(this->textBox2);
this->panel1->Controls->Add(this->textBox1);
this->panel1->Location = System::Drawing::Point(365, 202);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(206, 100);
this->panel1->TabIndex = 1;
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(1, 81);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(22, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"HP";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(1, 45);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(47, 13);
this->label2->TabIndex = 4;
this->label2->Text = L"Defense";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(1, 2);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(38, 13);
this->label1->TabIndex = 3;
this->label1->Text = L"Attack";
this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(106, 80);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(100, 20);
this->textBox3->TabIndex = 2;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(106, 40);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 1;
//
// panel2
//
this->panel2->Controls->Add(this->label4);
this->panel2->Controls->Add(this->label5);
this->panel2->Controls->Add(this->label6);
this->panel2->Controls->Add(this->textBox4);
this->panel2->Controls->Add(this->textBox5);
this->panel2->Controls->Add(this->textBox6);
this->panel2->Location = System::Drawing::Point(595, 202);
this->panel2->Name = L"panel2";
this->panel2->Size = System::Drawing::Size(206, 100);
this->panel2->TabIndex = 6;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(3, 83);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(22, 13);
this->label4->TabIndex = 5;
this->label4->Text = L"HP";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(3, 45);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(47, 13);
this->label5->TabIndex = 4;
this->label5->Text = L"Defense";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(3, 2);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(38, 13);
this->label6->TabIndex = 3;
this->label6->Text = L"Attack";
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(106, 80);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(100, 20);
this->textBox4->TabIndex = 2;
//
// textBox5
//
this->textBox5->Location = System::Drawing::Point(106, 40);
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System::Drawing::Size(100, 20);
this->textBox5->TabIndex = 1;
//
// textBox6
//
this->textBox6->Location = System::Drawing::Point(106, 0);
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System::Drawing::Size(100, 20);
this->textBox6->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(545, 326);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 7;
this->button1->Text = L"FIGHT!";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(543, 435);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(28, 13);
this->label7->TabIndex = 8;
this->label7->Text = L"XXX";
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(592, 435);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(28, 13);
this->label8->TabIndex = 9;
this->label8->Text = L"XXX";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1280, 720);
this->Controls->Add(this->label8);
this->Controls->Add(this->label7);
this->Controls->Add(this->button1);
this->Controls->Add(this->panel2);
this->Controls->Add(this->panel1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->panel1->ResumeLayout(false);
this->panel1->PerformLayout();
this->panel2->ResumeLayout(false);
this->panel2->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// Battle_Card Card1(Int32::Parse(textBox1->Text), Int32::Parse(textBox2->Text), Int32::Parse(textBox3->Text));
// Battle_Card Card2(Int32::Parse(textBox6->Text), Int32::Parse(textBox5->Text), Int32::Parse(textBox4->Text));
BattleCard^ Card1 = gcnew BattleCard(Int32::Parse(textBox1->Text), Int32::Parse(textBox2->Text), Int32::Parse(textBox3->Text));
BattleCard^ Card2 = gcnew BattleCard(Int32::Parse(textBox6->Text), Int32::Parse(textBox5->Text), Int32::Parse(textBox4->Text));
label8->Text = System::Convert::ToString(Card2->HP);
if (Card1->HP > 0 && Card2->HP > 0)
{
Card2->Defend(Card1->Attack, Card2->Defense);
}
label8->Text = System::Convert::ToString(Card2->HP);
if (Card2->HP > 0 && Card1->HP > 0)
{
Card1->Defend(Card2->Attack, Card1->Defense);
}
label7->Text = System::Convert::ToString(Card1->HP);
}
}; //After MyForm.h is finished, all variables are deleted.
}
How to prevent them from being deleted? Do i need to put them in MyForm.cpp or something?
Related
I created UserControl and put there a two GroupBox one at the top and one at the bottom... there is a screenshot
And then when I put this UserControl with my a views within to TabController I got such a result
So, as you see in the main form it looks like it is not enough space for all views within UserControl
Question is - is there a way to set that GroupBox at the top will take 50% of the height and GroupBox at the bottom will take also 50% of the height, such way this two GroupBox view will take 100% of the height each for 50%...
alternatively use TableLayoutPanel with two rows (each row gets 50% height)
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Controls.Add(this.groupBox1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 2);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 4F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(507, 408);
this.tableLayoutPanel1.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox1.Location = new System.Drawing.Point(3, 3);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(501, 196);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// groupBox2
//
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox2.Location = new System.Drawing.Point(3, 209);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(501, 196);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "groupBox2";
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(513, 414);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form3";
this.Padding = new System.Windows.Forms.Padding(3);
this.Text = "Form3";
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
you can use SplitContainer (IsSplitterFixed = true; will not allow to change proportions)
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.IsSplitterFixed = true;
this.splitContainer1.Location = new System.Drawing.Point(3, 3);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.groupBox1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.groupBox2);
this.splitContainer1.Size = new System.Drawing.Size(459, 395);
this.splitContainer1.SplitterDistance = 197;
this.splitContainer1.SplitterWidth = 1;
this.splitContainer1.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(459, 197);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// groupBox2
//
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox2.Location = new System.Drawing.Point(0, 0);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(459, 197);
this.groupBox2.TabIndex = 0;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "groupBox2";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(465, 401);
this.Controls.Add(this.splitContainer1);
this.Name = "Form2";
this.Padding = new System.Windows.Forms.Padding(3);
this.Text = "Form2";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
I've been given a project and I've been stuck for 2 days trying to figure it out.
I have a CPP file (base_station.cpp) that reads and writes to a port. I want to display the information on to the form's listbox (actionLogBox) created. The line where I want to add the item to has(base_station.cpp):
actionLogBox->AddString("Attempting Pin");
base_staion.cpp
/*********************
* base_station.cpp
* base_station.cpp holds the implementation for each individual
* function that applies to the base station. For a better understanding
* of each function, please, see reference the desired function.
*********************/
#pragma once
#include "mainForm.h"
#include "stdafx.h"
/* base station functionality */
#include "base_station.h"
/* used for serial (comm) port functionality */
#include "serial.h"
/***********************
* bs_ping
* bs_ping attempts to ping the base station attached to the given
* port handle, hPort.
* Command Format
* Length: 1 byte
* Byte 1: 0x01
* Good Response:
* Length: 1 byte
* Byte 1: 0x01
* PRE: hPort is a legitimate, open, port handle of type HANDLE
* POST: if successful, 0 is returned
* otherwise, some error code
***********************/
int bs_ping(/* in */ HANDLE hPort)
{
TRACE("bs_ping()\n");
unsigned char ucCmd = 0x01, // command to send
ucResponse; // holds the response
DWORD dwBytes_written = 0, // number of bytes written to the port
dwBytes_read = 0; // number of bytes read from the port
int iResult, // return value of port read/write functions
iPos; // position in the console that the command was written to
CString strFormat; // formatted string for output to command information window
/* send the 0x01 command to the serial port */
if ((iResult = port_write(hPort, &ucCmd, 1, dwBytes_written, iPos)) != 0)
return iResult;
/* append to the command description */
//strFormat.Format("Attempt to ping base station on port handle %i.\r\nCommand Byte: %#04x",
// hPort, ucCmd);
//strCmd_info[iPos] = strFormat;
actionLogBox->AddString("Attempting Pin"); /*Here is the line that adds the string to the listbox*/
/* attempt to read the correct response, 0x01, from the serial port */
if ((iResult = port_read(hPort, &ucResponse, 1, dwBytes_read, iPos)) != 0)
return iResult;
if (ucResponse != 0x01) {
/* append to the command description */
//strFormat.Format("Attempt to ping base station on port handle %i.", hPort);
//strCmd_info[iPos] = strFormat;
//return ERROR_INVALID_RESPONSE;
}
//strFormat.Format("Attempt to ping base station on port handle %i.", hPort);
//strCmd_info[iPos] = strFormat;
return 0;
}
mainForm.h
#pragma once
# include "stdafx.h"
# include "addBase.h"
# include "serial.h"
#include "base_station.h"
namespace WCM {
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 mainForm
/// </summary>
public ref class mainForm : public System::Windows::Forms::Form
{
public:
mainForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~mainForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ expDataDirMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ uploadDataMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ exitMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ editMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ prefMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ helpMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ aboutMenuItem;
private: System::Windows::Forms::ToolStrip^ toolStrip1;
private: System::Windows::Forms::ToolStripDropDownButton^ addBaseButton;
private: System::Windows::Forms::ToolStripMenuItem^ scanPortsMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ addBaseMenuItem;
private: System::Windows::Forms::ToolStripDropDownButton^ addNodesButton;
private: System::Windows::Forms::ToolStripMenuItem^ nodeDiscMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ addNodeMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripButton^ nodesInfoButton;
private: System::Windows::Forms::ToolStripButton^ nodesConfigButton;
private: System::Windows::Forms::GroupBox^ bottomBox;
private: System::Windows::Forms::ListBox^ actionLogBox;
private: System::Windows::Forms::ListBox^ baseStationBox;
private: System::Windows::Forms::GroupBox^ sideBox;
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(mainForm::typeid));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->expDataDirMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->uploadDataMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->exitMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->editMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->prefMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->helpMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->aboutMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
this->addBaseButton = (gcnew System::Windows::Forms::ToolStripDropDownButton());
this->scanPortsMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->addBaseMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->addNodesButton = (gcnew System::Windows::Forms::ToolStripDropDownButton());
this->nodeDiscMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->addNodeMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->nodesInfoButton = (gcnew System::Windows::Forms::ToolStripButton());
this->nodesConfigButton = (gcnew System::Windows::Forms::ToolStripButton());
this->bottomBox = (gcnew System::Windows::Forms::GroupBox());
this->actionLogBox = (gcnew System::Windows::Forms::ListBox());
this->baseStationBox = (gcnew System::Windows::Forms::ListBox());
this->sideBox = (gcnew System::Windows::Forms::GroupBox());
this->menuStrip1->SuspendLayout();
this->toolStrip1->SuspendLayout();
this->bottomBox->SuspendLayout();
this->sideBox->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
this->fileMenuItem, this->editMenuItem,
this->helpMenuItem
});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(638, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// fileMenuItem
//
this->fileMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
this->expDataDirMenuItem,
this->uploadDataMenuItem, this->exitMenuItem
});
this->fileMenuItem->Name = L"fileMenuItem";
this->fileMenuItem->Size = System::Drawing::Size(37, 20);
this->fileMenuItem->Text = L"File";
//
// expDataDirMenuItem
//
this->expDataDirMenuItem->Name = L"expDataDirMenuItem";
this->expDataDirMenuItem->Size = System::Drawing::Size(190, 22);
this->expDataDirMenuItem->Text = L"Explore Data Directory";
//
// uploadDataMenuItem
//
this->uploadDataMenuItem->Name = L"uploadDataMenuItem";
this->uploadDataMenuItem->Size = System::Drawing::Size(190, 22);
this->uploadDataMenuItem->Text = L"Upload Data";
//
// exitMenuItem
//
this->exitMenuItem->Name = L"exitMenuItem";
this->exitMenuItem->Size = System::Drawing::Size(190, 22);
this->exitMenuItem->Text = L"Exit";
//
// editMenuItem
//
this->editMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->prefMenuItem });
this->editMenuItem->Name = L"editMenuItem";
this->editMenuItem->Size = System::Drawing::Size(39, 20);
this->editMenuItem->Text = L"Edit";
//
// prefMenuItem
//
this->prefMenuItem->Name = L"prefMenuItem";
this->prefMenuItem->Size = System::Drawing::Size(135, 22);
this->prefMenuItem->Text = L"Preferences";
//
// helpMenuItem
//
this->helpMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->aboutMenuItem });
this->helpMenuItem->Name = L"helpMenuItem";
this->helpMenuItem->Size = System::Drawing::Size(44, 20);
this->helpMenuItem->Text = L"Help";
//
// aboutMenuItem
//
this->aboutMenuItem->Name = L"aboutMenuItem";
this->aboutMenuItem->Size = System::Drawing::Size(107, 22);
this->aboutMenuItem->Text = L"About";
//
// toolStrip1
//
this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {
this->addBaseButton, this->addNodesButton,
this->toolStripSeparator1, this->nodesInfoButton, this->nodesConfigButton
});
this->toolStrip1->Location = System::Drawing::Point(0, 24);
this->toolStrip1->Name = L"toolStrip1";
this->toolStrip1->Size = System::Drawing::Size(638, 25);
this->toolStrip1->TabIndex = 1;
this->toolStrip1->Text = L"toolStrip1";
//
// addBaseButton
//
this->addBaseButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->addBaseButton->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
this->scanPortsMenuItem,
this->addBaseMenuItem
});
this->addBaseButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"addBaseButton.Image")));
this->addBaseButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->addBaseButton->Name = L"addBaseButton";
this->addBaseButton->Size = System::Drawing::Size(29, 22);
this->addBaseButton->Text = L"Add Base";
//
// scanPortsMenuItem
//
this->scanPortsMenuItem->Name = L"scanPortsMenuItem";
this->scanPortsMenuItem->Size = System::Drawing::Size(129, 22);
this->scanPortsMenuItem->Text = L"Scan Ports";
//
// addBaseMenuItem
//
this->addBaseMenuItem->Name = L"addBaseMenuItem";
this->addBaseMenuItem->Size = System::Drawing::Size(129, 22);
this->addBaseMenuItem->Text = L"Add Base";
this->addBaseMenuItem->Click += gcnew System::EventHandler(this, &mainForm::addBaseMenuItem_Click);
//
// addNodesButton
//
this->addNodesButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->addNodesButton->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
this->nodeDiscMenuItem,
this->addNodeMenuItem
});
this->addNodesButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"addNodesButton.Image")));
this->addNodesButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->addNodesButton->Name = L"addNodesButton";
this->addNodesButton->Size = System::Drawing::Size(29, 22);
this->addNodesButton->Text = L"Add Nodes";
//
// nodeDiscMenuItem
//
this->nodeDiscMenuItem->Name = L"nodeDiscMenuItem";
this->nodeDiscMenuItem->Size = System::Drawing::Size(157, 22);
this->nodeDiscMenuItem->Text = L"Node Discovery";
//
// addNodeMenuItem
//
this->addNodeMenuItem->Name = L"addNodeMenuItem";
this->addNodeMenuItem->Size = System::Drawing::Size(157, 22);
this->addNodeMenuItem->Text = L"Add Node";
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(6, 25);
//
// nodesInfoButton
//
this->nodesInfoButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->nodesInfoButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"nodesInfoButton.Image")));
this->nodesInfoButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->nodesInfoButton->Name = L"nodesInfoButton";
this->nodesInfoButton->Size = System::Drawing::Size(23, 22);
this->nodesInfoButton->Text = L"Load Node Information";
this->nodesInfoButton->ToolTipText = L"Load Nodes Information";
//
// nodesConfigButton
//
this->nodesConfigButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->nodesConfigButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"nodesConfigButton.Image")));
this->nodesConfigButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->nodesConfigButton->Name = L"nodesConfigButton";
this->nodesConfigButton->Size = System::Drawing::Size(23, 22);
this->nodesConfigButton->Text = L"Configure Nodes";
//
// bottomBox
//
this->bottomBox->Controls->Add(this->actionLogBox);
this->bottomBox->Location = System::Drawing::Point(0, 281);
this->bottomBox->Name = L"bottomBox";
this->bottomBox->Size = System::Drawing::Size(638, 119);
this->bottomBox->TabIndex = 3;
this->bottomBox->TabStop = false;
this->bottomBox->Text = L"Action Log";
this->bottomBox->Enter += gcnew System::EventHandler(this, &mainForm::groupBox1_Enter);
//
// actionLogBox
//
this->actionLogBox->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->actionLogBox->BackColor = System::Drawing::SystemColors::Window;
this->actionLogBox->ForeColor = System::Drawing::SystemColors::InactiveCaptionText;
this->actionLogBox->FormattingEnabled = true;
this->actionLogBox->Items->AddRange(gcnew cli::array< System::Object^ >(1) { L"--- Ready ---" });
this->actionLogBox->Location = System::Drawing::Point(6, 17);
this->actionLogBox->Name = L"actionLogBox";
this->actionLogBox->Size = System::Drawing::Size(626, 95);
this->actionLogBox->TabIndex = 0;
this->actionLogBox->SelectedIndexChanged += gcnew System::EventHandler(this, &mainForm::actionLogBox_SelectedIndexChanged);
//
// baseStationBox
//
this->baseStationBox->BackColor = System::Drawing::SystemColors::Window;
this->baseStationBox->ForeColor = System::Drawing::SystemColors::InactiveCaptionText;
this->baseStationBox->FormattingEnabled = true;
this->baseStationBox->Items->AddRange(gcnew cli::array< System::Object^ >(1) { L"(Add a Base Station)" });
this->baseStationBox->Location = System::Drawing::Point(6, 19);
this->baseStationBox->Name = L"baseStationBox";
this->baseStationBox->Size = System::Drawing::Size(128, 199);
this->baseStationBox->TabIndex = 5;
this->baseStationBox->SelectedIndexChanged += gcnew System::EventHandler(this, &mainForm::baseStationBox_SelectedIndexChanged);
//
// sideBox
//
this->sideBox->Controls->Add(this->baseStationBox);
this->sideBox->Location = System::Drawing::Point(6, 52);
this->sideBox->Name = L"sideBox";
this->sideBox->Size = System::Drawing::Size(134, 225);
this->sideBox->TabIndex = 6;
this->sideBox->TabStop = false;
this->sideBox->Text = L"Base Station Controller";
//
// mainForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(638, 400);
this->Controls->Add(this->sideBox);
this->Controls->Add(this->bottomBox);
this->Controls->Add(this->toolStrip1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"mainForm";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Wireless Controll Manager";
this->Load += gcnew System::EventHandler(this, &mainForm::mainForm_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->toolStrip1->ResumeLayout(false);
this->toolStrip1->PerformLayout();
this->bottomBox->ResumeLayout(false);
this->sideBox->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void addBaseMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
addBase^ add_base = gcnew addBase();
add_base->ShowDialog();
}
private: System::Void groupBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void mainForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void baseStationBox_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void actionLogBox_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
actionLogBox->Items->Add("Blue") /*Test*/
}
};
}
I'm currently working on a visual c++ program where I have multiple textboxes on my first form, all of which require a number. What these are doing is asking for a number to be entered (amount of specific expense). For some of my expenses they involve multiple smaller expenses to calculate the expense. To accomplish that I have the corresponding textbox disabled at first, and have a button next to each disabled textbox. When the user clicks the button next to each textbox it brings up a separate form (while still keeping the main form open) that prompts the user to enter all of the smaller expenses that are totaled on a button click on that form. Then once they click the button to total the expenses on the form a return button appears that when clicked closes the form and leaves only the main expense form open. My predicament is I need to send back the total calculated value for the specific expense, place it in the corresponding textbox on the main expense form, as well as enabled that textbox. I believe I have the method down for returning the value to the main expense form, then assigning it to the textbox, but I'm not quite sure how to enable the textbox once the user clicks the button to return to the main expense form on the smaller pop-up expense form. Any tips or ideas would be greatly appreciated.
Side note of curiosity: Would I even need to enable the textbox on the main expense form in order to place the returned value into it, then use the value in a calculation that involves all the expenses on the main expense form?
//ExpensesForm.h
#pragma once
#include "MiscExpensesCalculateForm.h"
namespace Project1 {
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 ExpensesForm
/// </summary>
public ref class ExpensesForm : public System::Windows::Forms::Form
{
public:
ExpensesForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~ExpensesForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox1;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox2;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox3;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox4;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox5;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox7;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox8;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox9;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::Label^ label10;
private: System::Windows::Forms::Label^ label11;
private: System::Windows::Forms::Button^ button5;
public: System::Windows::Forms::MaskedTextBox^ misctotaltextbox;
private: System::Windows::Forms::Label^ label12;
private: System::Windows::Forms::Label^ label13;
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(ExpensesForm::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
this->maskedTextBox2 = (gcnew System::Windows::Forms::MaskedTextBox());
this->maskedTextBox3 = (gcnew System::Windows::Forms::MaskedTextBox());
this->maskedTextBox4 = (gcnew System::Windows::Forms::MaskedTextBox());
this->maskedTextBox5 = (gcnew System::Windows::Forms::MaskedTextBox());
this->maskedTextBox6 = (gcnew System::Windows::Forms::MaskedTextBox());
this->label7 = (gcnew System::Windows::Forms::Label());
this->maskedTextBox7 = (gcnew System::Windows::Forms::MaskedTextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->label8 = (gcnew System::Windows::Forms::Label());
this->button3 = (gcnew System::Windows::Forms::Button());
this->maskedTextBox8 = (gcnew System::Windows::Forms::MaskedTextBox());
this->button4 = (gcnew System::Windows::Forms::Button());
this->maskedTextBox9 = (gcnew System::Windows::Forms::MaskedTextBox());
this->label9 = (gcnew System::Windows::Forms::Label());
this->label10 = (gcnew System::Windows::Forms::Label());
this->label11 = (gcnew System::Windows::Forms::Label());
this->button5 = (gcnew System::Windows::Forms::Button());
this->misctotaltextbox = (gcnew System::Windows::Forms::MaskedTextBox());
this->label12 = (gcnew System::Windows::Forms::Label());
this->label13 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(22, 86);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(74, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Cell Phone Bill";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(22, 230);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(111, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"Doctors Appointments";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(22, 124);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(73, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"Car Insurance";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(22, 195);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(91, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"Therapy Sessions";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(22, 160);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(88, 13);
this->label5->TabIndex = 4;
this->label5->Text = L"Health Insurance";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(22, 343);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(30, 13);
this->label6->TabIndex = 5;
this->label6->Text = L"Rent";
//
// maskedTextBox1
//
this->maskedTextBox1->Location = System::Drawing::Point(158, 83);
this->maskedTextBox1->Mask = L"000.00";
this->maskedTextBox1->Name = L"maskedTextBox1";
this->maskedTextBox1->Size = System::Drawing::Size(100, 20);
this->maskedTextBox1->TabIndex = 6;
//
// maskedTextBox2
//
this->maskedTextBox2->Location = System::Drawing::Point(158, 121);
this->maskedTextBox2->Mask = L"000.00";
this->maskedTextBox2->Name = L"maskedTextBox2";
this->maskedTextBox2->Size = System::Drawing::Size(100, 20);
this->maskedTextBox2->TabIndex = 7;
//
// maskedTextBox3
//
this->maskedTextBox3->Location = System::Drawing::Point(158, 157);
this->maskedTextBox3->Mask = L"000.00";
this->maskedTextBox3->Name = L"maskedTextBox3";
this->maskedTextBox3->Size = System::Drawing::Size(100, 20);
this->maskedTextBox3->TabIndex = 8;
//
// maskedTextBox4
//
this->maskedTextBox4->Location = System::Drawing::Point(158, 192);
this->maskedTextBox4->Mask = L"000.00";
this->maskedTextBox4->Name = L"maskedTextBox4";
this->maskedTextBox4->Size = System::Drawing::Size(100, 20);
this->maskedTextBox4->TabIndex = 9;
//
// maskedTextBox5
//
this->maskedTextBox5->Location = System::Drawing::Point(158, 227);
this->maskedTextBox5->Mask = L"000.00";
this->maskedTextBox5->Name = L"maskedTextBox5";
this->maskedTextBox5->Size = System::Drawing::Size(100, 20);
this->maskedTextBox5->TabIndex = 10;
//
// maskedTextBox6
//
this->maskedTextBox6->Enabled = false;
this->maskedTextBox6->Location = System::Drawing::Point(158, 340);
this->maskedTextBox6->Mask = L"000.00";
this->maskedTextBox6->Name = L"maskedTextBox6";
this->maskedTextBox6->Size = System::Drawing::Size(100, 20);
this->maskedTextBox6->TabIndex = 11;
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(22, 379);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(44, 13);
this->label7->TabIndex = 12;
this->label7->Text = L"Grocery";
//
// maskedTextBox7
//
this->maskedTextBox7->Enabled = false;
this->maskedTextBox7->Location = System::Drawing::Point(158, 376);
this->maskedTextBox7->Mask = L"000.00";
this->maskedTextBox7->Name = L"maskedTextBox7";
this->maskedTextBox7->Size = System::Drawing::Size(100, 20);
this->maskedTextBox7->TabIndex = 13;
//
// button1
//
this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.BackgroundImage")));
this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
this->button1->FlatAppearance->BorderSize = 0;
this->button1->Location = System::Drawing::Point(127, 373);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(25, 25);
this->button1->TabIndex = 14;
this->button1->UseVisualStyleBackColor = true;
//
// button2
//
this->button2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button2.BackgroundImage")));
this->button2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
this->button2->FlatAppearance->BorderSize = 0;
this->button2->Location = System::Drawing::Point(127, 337);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(25, 25);
this->button2->TabIndex = 15;
this->button2->UseVisualStyleBackColor = true;
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(22, 306);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(61, 13);
this->label8->TabIndex = 16;
this->label8->Text = L"Gas/Travel";
//
// button3
//
this->button3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button3.BackgroundImage")));
this->button3->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
this->button3->FlatAppearance->BorderSize = 0;
this->button3->Location = System::Drawing::Point(127, 300);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(25, 25);
this->button3->TabIndex = 18;
this->button3->UseVisualStyleBackColor = true;
//
// maskedTextBox8
//
this->maskedTextBox8->Enabled = false;
this->maskedTextBox8->Location = System::Drawing::Point(158, 303);
this->maskedTextBox8->Mask = L"000.00";
this->maskedTextBox8->Name = L"maskedTextBox8";
this->maskedTextBox8->Size = System::Drawing::Size(100, 20);
this->maskedTextBox8->TabIndex = 17;
//
// button4
//
this->button4->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button4.BackgroundImage")));
this->button4->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
this->button4->FlatAppearance->BorderSize = 0;
this->button4->Location = System::Drawing::Point(127, 259);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(25, 25);
this->button4->TabIndex = 20;
this->button4->UseVisualStyleBackColor = true;
//
// maskedTextBox9
//
this->maskedTextBox9->Enabled = false;
this->maskedTextBox9->Location = System::Drawing::Point(158, 262);
this->maskedTextBox9->Mask = L"000.00";
this->maskedTextBox9->Name = L"maskedTextBox9";
this->maskedTextBox9->Size = System::Drawing::Size(100, 20);
this->maskedTextBox9->TabIndex = 19;
this->maskedTextBox9->MaskInputRejected += gcnew System::Windows::Forms::MaskInputRejectedEventHandler(this, &ExpensesForm::maskedTextBox9_MaskInputRejected);
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::Point(22, 265);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(64, 13);
this->label9->TabIndex = 21;
this->label9->Text = L"Medications";
//
// label10
//
this->label10->AutoSize = true;
this->label10->Location = System::Drawing::Point(416, 50);
this->label10->Name = L"label10";
this->label10->Size = System::Drawing::Size(80, 13);
this->label10->TabIndex = 22;
this->label10->Text = L"The Run-Down";
//
// label11
//
this->label11->AutoSize = true;
this->label11->Location = System::Drawing::Point(345, 81);
this->label11->Name = L"label11";
this->label11->Size = System::Drawing::Size(228, 351);
this->label11->TabIndex = 23;
this->label11->Text = resources->GetString(L"label11.Text");
//
// button5
//
this->button5->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button5.BackgroundImage")));
this->button5->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
this->button5->FlatAppearance->BorderSize = 0;
this->button5->Location = System::Drawing::Point(127, 408);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(25, 25);
this->button5->TabIndex = 26;
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &ExpensesForm::button5_Click);
//
// misctotaltextbox
//
this->misctotaltextbox->Enabled = false;
this->misctotaltextbox->Location = System::Drawing::Point(158, 411);
this->misctotaltextbox->Mask = L"000.00";
this->misctotaltextbox->Name = L"misctotaltextbox";
this->misctotaltextbox->Size = System::Drawing::Size(100, 20);
this->misctotaltextbox->TabIndex = 25;
//
// label12
//
this->label12->AutoSize = true;
this->label12->Location = System::Drawing::Point(22, 414);
this->label12->Name = L"label12";
this->label12->Size = System::Drawing::Size(32, 13);
this->label12->TabIndex = 24;
this->label12->Text = L"Misc.";
//
// label13
//
this->label13->AutoSize = true;
this->label13->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label13->Location = System::Drawing::Point(263, 12);
this->label13->Name = L"label13";
this->label13->Size = System::Drawing::Size(95, 24);
this->label13->TabIndex = 27;
this->label13->Text = L"Expenses";
//
// ExpensesForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(637, 499);
this->Controls->Add(this->label13);
this->Controls->Add(this->button5);
this->Controls->Add(this->misctotaltextbox);
this->Controls->Add(this->label12);
this->Controls->Add(this->label11);
this->Controls->Add(this->label10);
this->Controls->Add(this->label9);
this->Controls->Add(this->button4);
this->Controls->Add(this->maskedTextBox9);
this->Controls->Add(this->button3);
this->Controls->Add(this->maskedTextBox8);
this->Controls->Add(this->label8);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->maskedTextBox7);
this->Controls->Add(this->label7);
this->Controls->Add(this->maskedTextBox6);
this->Controls->Add(this->maskedTextBox5);
this->Controls->Add(this->maskedTextBox4);
this->Controls->Add(this->maskedTextBox3);
this->Controls->Add(this->maskedTextBox2);
this->Controls->Add(this->maskedTextBox1);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Name = L"ExpensesForm";
this->Text = L"Budget Buddy - Expenses";
this->Load += gcnew System::EventHandler(this, &ExpensesForm::ExpensesForm_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void maskedTextBox9_MaskInputRejected(System::Object^ sender, System::Windows::Forms::MaskInputRejectedEventArgs^ e) {
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
MiscExpensesCalculateForm^ mecf = gcnew MiscExpensesCalculateForm();
mecf->ShowDialog();
}
private: System::Void ExpensesForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}
I found this post and it's exactly what I need to do, but I just don't know where to put the code.
What is usually done (see types like FileDialog) is to put some public properties in the modal form class (here, MiscExpensesCalculateForm) and simply set them before calling ShowDialog and read them afterwards).
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
MiscExpensesCalculateForm^ mecf = gcnew MiscExpensesCalculateForm();
mecf->SomeInputData = blahblah;
DialogResult dr = mecf->ShowDialog();
if(dr == DialogResult.OK) {
textBoxResult->Text = mecf->MyResultData;
textBoxResult->Enabled = true;
}
}
OK, this is a weird problem. I have an abstract control that derives from TextBox called Writer, and two classes that derive from it, StdWriter and LngWriter. The difference between them is one is always multiline and the other is not. That's seriously the only difference between the two.
In the OnHandleCreated function, I set the margins with the Win32 SendMessage function. I do it again in OnPaint because WinForms will "forget" to set the margins if I have more than 1 StdWriter (or any derived textbox type) on the same form (this makes no sense either but at least I have a workaround for it).
Now I have the problem that I can't have both of these textboxes on the same form. If I put a StdWriter and a multiline TextBox or a LngWriter and a standard TextBox on the form, it works. If I put 2 MS textboxes on the form, it also works. but let me put a LngWriter and StdWriter together and the LngWriter won't draw its scrollbar right (the vertical is wrong and it just won't draw the horizontal, period) or accept the Enterkey, despite both MultiLine and AcceptsReturn returning true. I can't even paste newlines in because it totally strips them out.
I don't understand this because TextBox derives from the abstract TextBoxBase and I don't have any problems with dozens of different derived textboxes all over my forms. Is it because I'm inserting a second abstract class in the inheritance chain and Visual Studio doesn't like it or what?
public abstract class RKWRITER : System.Windows.Forms.TextBox
{
protected sealed class RKLAYOUT : System.Windows.Forms.TableLayoutPanel
protected sealed class RKFLIPPER : System.Windows.Forms.CheckBox
protected sealed class RKBITMAP : System.Windows.Forms.PictureBox
protected RKSHARP2.Controls.RKWRITER.RKLAYOUT Control_Secondary = null;
protected RKSHARP2.Controls.RKWRITER.RKBITMAP Control_IconView = null;
protected RKSHARP2.Controls.RKWRITER.RKFLIPPER Control_NullView = null;
public override System.Boolean Multiline
{
get
{
return base.Multiline;
}
set
{
this.SuspendLayout();
base.Multiline = value;
this.RecreateHandle();
this.ResumeLayout();
this.PerformLayout();
this.Invalidate();
}
}
protected static void SetControlBuffer (System.IntPtr Pointer_Control, System.Int32 Integer_West, System.Int32 Integer_East)
{
RKSHARP2.System.Internal.USER32.SendMessage(Pointer_Control, RKSHARP2.System.Internal.USER32.EM_SETMARGINS, new System.IntPtr(RKSHARP2.System.Internal.USER32.EC_LEFTMARGIN|RKSHARP2.System.Internal.USER32.EC_RIGHTMARGIN), new System.IntPtr((0x00010000 * Integer_East) + Integer_West));
}
}
public sealed class RKSTANDARDWRITER : RKSHARP2.Controls.RKWRITER
{
public override System.Boolean Multiline
{
get
{
return false;
}
set
{
this.SuspendLayout();
base.Multiline = false;
this.RecreateHandle();
this.ResumeLayout();
this.PerformLayout();
this.Invalidate();
}
}
public RKSTANDARDWRITER ()
{
this.SuspendLayout();
this.AcceptsReturn = false;
this.AcceptsTab = false;
this.AutoSize = false;
this.DoubleBuffered = true;
this.Margin = new System.Windows.Forms.Padding(0);
this.MaxLength = 24;
this.Multiline = false;
this.Padding = new System.Windows.Forms.Padding(0);
this.PasswordChar = RKSHARP2.Constants.NULLZERO;
this.ResizeRedraw = true;
this.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.Text = null;
this.UseSystemPasswordChar = false;
this.Vertical = 1;
this.Visible = true;
this.WordWrap = false;
this.SetControlProperties(null, false, new System.Drawing.Size(0, 0), null, false, true);
this.ResumeLayout();
this.PerformLayout();
}
#pragma warning disable 1591
protected override void OnHandleCreated (System.EventArgs Object_Arguments)
{
base.OnHandleCreated(Object_Arguments);
this.ClientSize = new System.Drawing.Size(this.ClientSize.Width, System.Math.Max(this.FontHeight, this.Control_Secondary.PreferredSize.Height) * this.Vertical);
RKSHARP2.Controls.RKSTANDARDWRITER.SetControlBuffer(this.Handle, this.Control_Secondary.PreferredSize.Width, 0);
}
protected override void OnPaint (System.Windows.Forms.PaintEventArgs Object_Arguments)
{
//RRK: I have no idea WTF is suddenly wrong here but Windows will not set margins in OnHandleCreated() if multiple controls are present.
base.OnPaint(Object_Arguments);
RKSHARP2.Controls.RKSTANDARDWRITER.SetControlBuffer(this.Handle, this.Control_Secondary.PreferredSize.Width, 0);
}
protected override void WndProc (ref System.Windows.Forms.Message Object_Message)
{
#pragma warning disable 0162
switch (Object_Message.Msg)
{
default:
{
base.WndProc(ref Object_Message);
}
break;
}
#pragma warning restore 0162
}
public override System.Drawing.Size MinimumSize
{
get
{
return RKSHARP2.Windows.WindowSystemController.CompareMaximumSizes(base.MinimumSize, this.SizeFromClientSize(new System.Drawing.Size(this.Control_Secondary.PreferredSize.Width, System.Math.Max(this.FontHeight, this.Control_Secondary.PreferredSize.Height))));
}
set
{
base.MinimumSize = value;
}
}
public override System.Drawing.Size MaximumSize
{
get
{
return base.MaximumSize;
}
set
{
base.MaximumSize = value;
}
}
public override System.Drawing.Size GetPreferredSize (System.Drawing.Size Struct_Proposed)
{
return base.GetPreferredSize(Struct_Proposed);
}
protected void SetControlProperties (System.String String_Startup, System.Boolean Boolean_IconView, System.Drawing.Size Struct_IconSize, System.Drawing.Bitmap Object_Bitmap, System.Boolean Boolean_NullView, System.Boolean Boolean_NullType)
{
this.Control_Secondary = new RKSHARP2.Controls.RKSTANDARDWRITER.RKLAYOUT();
this.Control_Secondary.AutoSize = true;
this.Control_Secondary.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.Control_Secondary.BackColor = System.Drawing.Color.Transparent;
this.Control_Secondary.BackgroundImage = null;
this.Control_Secondary.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.Control_Secondary.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
this.Control_Secondary.ColumnCount = 4;
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.Dock = System.Windows.Forms.DockStyle.Left;
this.Control_Secondary.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
this.Control_Secondary.Margin = new System.Windows.Forms.Padding(0);
this.Control_Secondary.Padding = new System.Windows.Forms.Padding(0);
this.Control_Secondary.RowCount = 3;
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.Size = new System.Drawing.Size(0, 0);
this.Control_Secondary.TabIndex = 0;
this.Control_Secondary.TabStop = false;
this.Control_Secondary.Visible = true;
this.Control_IconView = new RKSHARP2.Controls.RKSTANDARDWRITER.RKBITMAP();
this.Control_IconView.AutoSize = false;
this.Control_IconView.BackColor = System.Drawing.Color.Transparent;
this.Control_IconView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Control_IconView.Cursor = System.Windows.Forms.Cursors.Default;
this.Control_IconView.Dock = System.Windows.Forms.DockStyle.Fill;
this.Control_IconView.Image = Object_Bitmap;
this.Control_IconView.Margin = new System.Windows.Forms.Padding(0);
this.Control_IconView.Padding = new System.Windows.Forms.Padding(0);
this.Control_IconView.Parent = this;
this.Control_IconView.Size = Struct_IconSize;
this.Control_IconView.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Control_IconView.TabIndex = 0;
this.Control_IconView.TabStop = false;
this.Control_IconView.Visible = Boolean_IconView;
this.Control_IconView.VisibleChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.Control_IconView.Parent.Visible=this.IconView||this.NullView;});
this.Control_NullView = new RKSHARP2.Controls.RKSTANDARDWRITER.RKFLIPPER();
this.Control_NullView.AutoSize = true;
this.Control_NullView.BackColor = System.Drawing.Color.Transparent;
this.Control_NullView.Checked = true;
this.Control_NullView.Cursor = System.Windows.Forms.Cursors.Default;
this.Control_NullView.Dock = System.Windows.Forms.DockStyle.Fill;
this.Control_NullView.Enabled = !this.ReadOnly;
this.Control_NullView.Margin = new System.Windows.Forms.Padding(0);
this.Control_NullView.Padding = new System.Windows.Forms.Padding(0);
this.Control_NullView.Parent = this;
this.Control_NullView.Size = new System.Drawing.Size(0, 0);
this.Control_NullView.TabIndex = 0;
this.Control_NullView.TabStop = false;
this.Control_NullView.Text = "";
this.Control_NullView.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.Control_NullView.UseVisualStyleBackColor = true;
this.Control_NullView.Visible = Boolean_NullView;
this.Control_NullView.CheckedChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.ReadOnly=!this.Control_NullView.Checked;});
this.Control_NullView.VisibleChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.Control_NullView.Parent.Visible=this.NullView||this.IconView;});
this.Control_Secondary.SuspendLayout();
this.Control_Secondary.Controls.Add(RKSHARP2.Controls.RKSTANDARDWRITER.ConstructContainer(this.Control_IconView), 1, 1);
this.Control_Secondary.Controls.Add(RKSHARP2.Controls.RKSTANDARDWRITER.ConstructContainer(this.Control_NullView), 2, 1);
this.Control_Secondary.ResumeLayout();
this.Control_Secondary.PerformLayout();
this.Controls.Add(this.Control_Secondary);
}
protected static RKSHARP2.Controls.RKSTANDARDWRITER.RKLAYOUT ConstructContainer (System.Windows.Forms.Control Control_Temporary)
{
RKSHARP2.Controls.RKSTANDARDWRITER.RKLAYOUT Control_Container = new RKSHARP2.Controls.RKSTANDARDWRITER.RKLAYOUT();
Control_Container.SuspendLayout();
Control_Container.AutoSize = true;
Control_Container.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
Control_Container.BackColor = System.Drawing.Color.Transparent;
Control_Container.BackgroundImage = null;
Control_Container.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
Control_Container.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
Control_Container.ColumnCount = 3;
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.Dock = System.Windows.Forms.DockStyle.Fill;
Control_Container.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
Control_Container.Margin = new System.Windows.Forms.Padding(2);
Control_Container.Padding = new System.Windows.Forms.Padding(0);
Control_Container.RowCount = 3;
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 0));
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.Size = new System.Drawing.Size(0, 0);
Control_Container.TabIndex = 0;
Control_Container.TabStop = false;
Control_Container.Visible = Control_Temporary.Visible;
Control_Container.Controls.Add(Control_Temporary, 1, 1);
Control_Container.ResumeLayout();
Control_Container.PerformLayout();
return Control_Container;
}
protected static void SetControlBuffer (System.IntPtr Pointer_Control, System.Int32 Integer_West, System.Int32 Integer_East)
{
RKSHARP2.Controls.RKWRITER.SetControlBuffer(Pointer_Control, Integer_West, Integer_East);
}
#pragma warning restore 1591
}
public sealed class RKQUESTIONWRITER : RKSHARP2.Controls.RKWRITER
{
public override System.Boolean Multiline
{
get
{
return true;
}
set
{
this.SuspendLayout();
base.Multiline = true;
this.RecreateHandle();
this.ResumeLayout();
this.PerformLayout();
this.Invalidate();
}
}
public RKQUESTIONWRITER ()
{
this.SuspendLayout();
this.AcceptsReturn = true;
this.AcceptsTab = true;
this.AutoSize = true;
this.DoubleBuffered = true;
this.Margin = new System.Windows.Forms.Padding(0);
this.MaxLength = 32768;
this.Multiline = true;
this.Padding = new System.Windows.Forms.Padding(0);
this.PasswordChar = RKSHARP2.Constants.NULLZERO;
this.ResizeRedraw = true;
this.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.Text = null;
this.UseSystemPasswordChar = false;
this.Vertical = 8;
this.Visible = true;
this.WordWrap = true;
this.SetControlProperties(null, false, new System.Drawing.Size(0, 0), null, false, true);
this.ResumeLayout();
this.PerformLayout();
}
#pragma warning disable 1591
protected override void OnHandleCreated (System.EventArgs Object_Arguments)
{
base.OnHandleCreated(Object_Arguments);
this.ClientSize = new System.Drawing.Size(this.ClientSize.Width, System.Math.Max(this.FontHeight, this.Control_Secondary.PreferredSize.Height) * this.Vertical);
RKSHARP2.Controls.RKQUESTIONWRITER.SetControlBuffer(this.Handle, this.Control_Secondary.PreferredSize.Width, 0);
}
protected override void OnPaint (System.Windows.Forms.PaintEventArgs Object_Arguments)
{
//RRK: I have no idea WTF is suddenly wrong here but Windows will not set margins in OnHandleCreated() if multiple controls are present.
base.OnPaint(Object_Arguments);
RKSHARP2.Controls.RKQUESTIONWRITER.SetControlBuffer(this.Handle, this.Control_Secondary.PreferredSize.Width, 0);
}
protected override void WndProc (ref System.Windows.Forms.Message Object_Message)
{
#pragma warning disable 0162
switch (Object_Message.Msg)
{
default:
{
base.WndProc(ref Object_Message);
}
break;
}
#pragma warning restore 0162
}
public override System.Drawing.Size MinimumSize
{
get
{
return RKSHARP2.Windows.WindowSystemController.CompareMaximumSizes(base.MinimumSize, this.SizeFromClientSize(new System.Drawing.Size(this.Control_Secondary.PreferredSize.Width, System.Math.Max(this.FontHeight, this.Control_Secondary.PreferredSize.Height))));
}
set
{
base.MinimumSize = value;
}
}
public override System.Drawing.Size MaximumSize
{
get
{
return base.MaximumSize;
}
set
{
base.MaximumSize = value;
}
}
public override System.Drawing.Size GetPreferredSize (System.Drawing.Size Struct_Proposed)
{
return base.GetPreferredSize(Struct_Proposed);
}
protected void SetControlProperties (System.String String_Startup, System.Boolean Boolean_IconView, System.Drawing.Size Struct_IconSize, System.Drawing.Bitmap Object_Bitmap, System.Boolean Boolean_NullView, System.Boolean Boolean_NullType)
{
this.Control_Secondary = new RKSHARP2.Controls.RKQUESTIONWRITER.RKLAYOUT();
this.Control_Secondary.AutoSize = true;
this.Control_Secondary.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.Control_Secondary.BackColor = System.Drawing.Color.Transparent;
this.Control_Secondary.BackgroundImage = null;
this.Control_Secondary.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.Control_Secondary.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
this.Control_Secondary.ColumnCount = 4;
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.Dock = System.Windows.Forms.DockStyle.Left;
this.Control_Secondary.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
this.Control_Secondary.Margin = new System.Windows.Forms.Padding(0);
this.Control_Secondary.Padding = new System.Windows.Forms.Padding(0);
this.Control_Secondary.RowCount = 3;
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 0));
this.Control_Secondary.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
this.Control_Secondary.Size = new System.Drawing.Size(0, 0);
this.Control_Secondary.TabIndex = 0;
this.Control_Secondary.TabStop = false;
this.Control_Secondary.Visible = true;
this.Control_IconView = new RKSHARP2.Controls.RKQUESTIONWRITER.RKBITMAP();
this.Control_IconView.AutoSize = false;
this.Control_IconView.BackColor = System.Drawing.Color.Transparent;
this.Control_IconView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Control_IconView.Cursor = System.Windows.Forms.Cursors.Default;
this.Control_IconView.Dock = System.Windows.Forms.DockStyle.Fill;
this.Control_IconView.Image = Object_Bitmap;
this.Control_IconView.Margin = new System.Windows.Forms.Padding(0);
this.Control_IconView.Padding = new System.Windows.Forms.Padding(0);
this.Control_IconView.Parent = this;
this.Control_IconView.Size = Struct_IconSize;
this.Control_IconView.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Control_IconView.TabIndex = 0;
this.Control_IconView.TabStop = false;
this.Control_IconView.Visible = Boolean_IconView;
this.Control_IconView.VisibleChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.Control_IconView.Parent.Visible=this.IconView||this.NullView;});
this.Control_NullView = new RKSHARP2.Controls.RKQUESTIONWRITER.RKFLIPPER();
this.Control_NullView.AutoSize = true;
this.Control_NullView.BackColor = System.Drawing.Color.Transparent;
this.Control_NullView.Checked = true;
this.Control_NullView.Cursor = System.Windows.Forms.Cursors.Default;
this.Control_NullView.Dock = System.Windows.Forms.DockStyle.Fill;
this.Control_NullView.Enabled = !this.ReadOnly;
this.Control_NullView.Margin = new System.Windows.Forms.Padding(0);
this.Control_NullView.Padding = new System.Windows.Forms.Padding(0);
this.Control_NullView.Parent = this;
this.Control_NullView.Size = new System.Drawing.Size(0, 0);
this.Control_NullView.TabIndex = 0;
this.Control_NullView.TabStop = false;
this.Control_NullView.Text = "";
this.Control_NullView.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.Control_NullView.UseVisualStyleBackColor = true;
this.Control_NullView.Visible = Boolean_NullView;
this.Control_NullView.CheckedChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.ReadOnly=!this.Control_NullView.Checked;});
this.Control_NullView.VisibleChanged += new System.EventHandler(delegate(System.Object Object_Sender, System.EventArgs Object_Arguments){this.Control_NullView.Parent.Visible=this.NullView||this.IconView;});
this.Control_Secondary.SuspendLayout();
this.Control_Secondary.Controls.Add(RKSHARP2.Controls.RKQUESTIONWRITER.ConstructContainer(this.Control_IconView), 1, 1);
this.Control_Secondary.Controls.Add(RKSHARP2.Controls.RKQUESTIONWRITER.ConstructContainer(this.Control_NullView), 2, 1);
this.Control_Secondary.ResumeLayout();
this.Control_Secondary.PerformLayout();
this.Controls.Add(this.Control_Secondary);
}
protected static RKSHARP2.Controls.RKQUESTIONWRITER.RKLAYOUT ConstructContainer (System.Windows.Forms.Control Control_Temporary)
{
RKSHARP2.Controls.RKQUESTIONWRITER.RKLAYOUT Control_Container = new RKSHARP2.Controls.RKQUESTIONWRITER.RKLAYOUT();
Control_Container.SuspendLayout();
Control_Container.AutoSize = true;
Control_Container.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
Control_Container.BackColor = System.Drawing.Color.Transparent;
Control_Container.BackgroundImage = null;
Control_Container.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
Control_Container.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
Control_Container.ColumnCount = 3;
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 0));
Control_Container.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.Dock = System.Windows.Forms.DockStyle.Fill;
Control_Container.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
Control_Container.Margin = new System.Windows.Forms.Padding(2);
Control_Container.Padding = new System.Windows.Forms.Padding(0);
Control_Container.RowCount = 3;
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 0));
Control_Container.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100));
Control_Container.Size = new System.Drawing.Size(0, 0);
Control_Container.TabIndex = 0;
Control_Container.TabStop = false;
Control_Container.Visible = Control_Temporary.Visible;
Control_Container.Controls.Add(Control_Temporary, 1, 1);
Control_Container.ResumeLayout();
Control_Container.PerformLayout();
return Control_Container;
}
protected static void SetControlBuffer (System.IntPtr Pointer_Control, System.Int32 Integer_West, System.Int32 Integer_East)
{
RKSHARP2.Controls.RKWRITER.SetControlBuffer(Pointer_Control, Integer_West, Integer_East);
}
#pragma warning restore 1591
}
I need to draw a point in 3D using WPF. I am using class ScreenSpaceLines3D to draw a line in 3D, but I'm not able to draw point in 3D (while model zooming). Can anybody help me? Some example code would be appreciated. Thanks
Use PointsVisual3D class from helixtoolkit, with it you can add points on viewport with color, size. Even you can apply transforms, too.
A point can't be seen, because it has no surface area. WPF 3d is not a ray tracing engine, unfortunately.
However, someone built a pretty nice ray-tracing starter library. This project is a good starting point if you want to do ray-tracing with WPF: http://raytracer.codeplex.com/.
It is not so complicated task.
Download the Helix3D Library
Find the sphere mesh code in samples
Attach the scphere's radius to zooming realization.
i can create a PointVisual3d Own Class. The code of PointVisual3D is below i think this one is helpful for you...
public class PointVisual3D:ModelVisual3D
{
private readonly GeometryModel3D _model;
private readonly MeshGeometry3D _mesh;
private Matrix3D _visualToScreen;
private Matrix3D _screenToVisual;
public PointVisual3D()
{
_mesh = new MeshGeometry3D();
_model = new GeometryModel3D();
_model.Geometry = _mesh;
SetColor(this.Color);
this.Content = _model;
this.Points = new Point3DCollection();
CompositionTarget.Rendering += OnRender;
}
private void OnRender(object sender, EventArgs e)
{
if (Points.Count == 0 && _mesh.Positions.Count == 0)
{
return;
}
if (UpdateTransforms() && MainWindow.mousedown==false)
{
RebuildGeometry();
}
}
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(Color), typeof(PointVisual3D), new PropertyMetadata(Colors.White, OnColorChanged));
private static void OnColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
((PointVisual3D)sender).SetColor((Color)args.NewValue);
}
private void SetColor(Color color)
{
MaterialGroup unlitMaterial = new MaterialGroup();
unlitMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(Colors.Black)));
unlitMaterial.Children.Add(new EmissiveMaterial(new SolidColorBrush(color)));
unlitMaterial.Freeze();
_model.Material = unlitMaterial;
_model.BackMaterial = unlitMaterial;
}
public Color Color
{
get { return (Color)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
//public static readonly DependencyProperty ThicknessProperty = DependencyProperty.Register("Thickness", typeof(double), typeof(PointVisual3D), new PropertyMetadata(1.0, OnThicknessChanged));
//private static void OnThicknessChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
//{
// ((PointVisual3D)sender).GeometryDirty();
//}
//public double Thickness
//{
// get { return (double)GetValue(ThicknessProperty); }
// set { SetValue(ThicknessProperty, value); }
//}
public static readonly DependencyProperty PointsProperty = DependencyProperty.Register("Points", typeof(Point3DCollection), typeof(PointVisual3D), new PropertyMetadata(null, OnPointsChanged));
private static void OnPointsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
((PointVisual3D)sender).GeometryDirty();
}
public Point3DCollection Points
{
get { return (Point3DCollection)GetValue(PointsProperty); }
set { SetValue(PointsProperty, value); }
}
private void GeometryDirty()
{
_visualToScreen = MathUtils.ZeroMatrix;
}
private void RebuildGeometry()
{
//double halfThickness = Thickness / 2.0;
//int numLines = Points.Count / 2;
//Point3DCollection positions = new Point3DCollection(numLines * 4);
//for (int i = 0; i < numLines; i++)
//{
// int startIndex = i * 2;
// Point3D startPoint = Points[startIndex];
// Point3D endPoint = Points[startIndex + 1];
// AddSegment(positions, startPoint, endPoint, halfThickness);
//}
//positions.Freeze();
//_mesh.Positions = positions;
Int32Collection indices = new Int32Collection(Points.Count * 6);
for (int i = 0; i < Points.Count; i++)
{
indices.Add(i * 4 + 2);
indices.Add(i * 4 + 1);
indices.Add(i * 4 + 0);
indices.Add(i * 4 + 2);
indices.Add(i * 4 + 3);
indices.Add(i * 4 + 1);
}
indices.Freeze();
_mesh.TriangleIndices = indices;
_mesh.Positions = CreatePositions(this.Points, this.Size, 0.0);
}
public Point3DCollection CreatePositions(IList<Point3D> points, double size = 1.0, double depthOffset = 0.0)
{
double halfSize = size / 2.0;
int numPoints = points.Count;
var outline = new[]
{
new Vector(-halfSize, halfSize), new Vector(-halfSize, -halfSize), new Vector(halfSize, halfSize),
new Vector(halfSize, -halfSize)
};
var positions = new Point3DCollection(numPoints * 4);
for (int i = 0; i < numPoints; i++)
{
var screenPoint = (Point4D)points[i] * this._visualToScreen;
double spx = screenPoint.X;
double spy = screenPoint.Y;
double spz = screenPoint.Z;
double spw = screenPoint.W;
if (!depthOffset.Equals(0))
{
spz -= depthOffset * spw;
}
var p0 = new Point4D(spx, spy, spz, spw) * this._screenToVisual;
double pwinverse = 1 / p0.W;
foreach (var v in outline)
{
var p = new Point4D(spx + v.X * spw, spy + v.Y * spw, spz, spw) * this._screenToVisual;
positions.Add(new Point3D(p.X * pwinverse, p.Y * pwinverse, p.Z * pwinverse));
}
}
positions.Freeze();
return positions;
}
/// <summary>
/// Identifies the <see cref="Size"/> dependency property.
/// </summary>
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(
"Size", typeof(double), typeof(PointVisual3D), new UIPropertyMetadata(1.0, GeometryChanged));
protected static void GeometryChanged(object sender, DependencyPropertyChangedEventArgs e)
{
((PointVisual3D)sender).GeometryDirty();
}
public double Size
{
get
{
return (double)this.GetValue(SizeProperty);
}
set
{
this.SetValue(SizeProperty, value);
}
}
//private void AddSegment(Point3DCollection positions, Point3D startPoint, Point3D endPoint, double halfThickness)
//{
// Vector3D lineDirection = endPoint * _visualToScreen - startPoint * _visualToScreen;
// lineDirection.Z = 0;
// lineDirection.Normalize();
// Vector delta = new Vector(-lineDirection.Y, lineDirection.X);
// delta *= halfThickness;
// Point3D pOut1, pOut2;
// Widen(startPoint, delta, out pOut1, out pOut2);
// positions.Add(pOut1);
// positions.Add(pOut2);
// Widen(endPoint, delta, out pOut1, out pOut2);
// positions.Add(pOut1);
// positions.Add(pOut2);
//}
//private void Widen(Point3D pIn, Vector delta, out Point3D pOut1, out Point3D pOut2)
//{
// Point4D pIn4 = (Point4D)pIn;
// Point4D pOut41 = pIn4 * _visualToScreen;
// Point4D pOut42 = pOut41;
// pOut41.X += delta.X * pOut41.W;
// pOut41.Y += delta.Y * pOut41.W;
// pOut42.X -= delta.X * pOut42.W;
// pOut42.Y -= delta.Y * pOut42.W;
// pOut41 *= _screenToVisual;
// pOut42 *= _screenToVisual;
// pOut1 = new Point3D(pOut41.X / pOut41.W, pOut41.Y / pOut41.W, pOut41.Z / pOut41.W);
// pOut2 = new Point3D(pOut42.X / pOut42.W, pOut42.Y / pOut42.W, pOut42.Z / pOut42.W);
//}
private bool UpdateTransforms()
{
Viewport3DVisual viewport;
bool success;
Matrix3D visualToScreen = MathUtils.TryTransformTo2DAncestor(this, out viewport, out success);
if (!success || !visualToScreen.HasInverse)
{
_mesh.Positions = null;
return false;
}
if (visualToScreen == _visualToScreen)
{
return false;
}
_visualToScreen = _screenToVisual = visualToScreen;
_screenToVisual.Invert();
return true;
}
}