📄 form1.h
字号:
#pragma once
#include "LottoLimitsDialog.h"
#include "EuroLimitsDialog.h"
#include "UserValueDialog.h"
namespace Ex21_01 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
: lottoValuesCount(6),
euroValuesCount(5), euroStarsCount(2),
lottoLowerLimit(1),lottoUpperLimit(49),
lottoUserMinimum(lottoLowerLimit),lottoUserMaximum(lottoUpperLimit),
euroLowerLimit(1), euroUpperLimit(50),
euroStarsLowerLimit(1),euroStarsUpperLimit(9),
euroUserMinimum(euroLowerLimit),euroUserMaximum(euroUpperLimit),
euroStarsUserMinimum(euroStarsLowerLimit),euroStarsUserMaximum(euroStarsUpperLimit)
{
InitializeComponent();
//
random = gcnew Random;
lottoLimitsDialog = gcnew LottoLimitsDialog;
lottoLimitsDialog->SetLowerLimitsList(1, lottoUpperLimit-lottoValuesCount+1,
lottoUserMinimum);
lottoLimitsDialog->SetUpperLimitsList(lottoValuesCount, lottoUpperLimit,
lottoUserMaximum);
euroLimitsDialog = gcnew EuroLimitsDialog;
euroLimitsDialog->LowerStarsLimit = euroStarsLowerLimit;
euroLimitsDialog->UpperStarsLimit = euroStarsUpperLimit;
userValueDialog = gcnew UserValueDialog;
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ playMenuItem;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ limitsToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ upperMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ lowerMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ resetMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ aboutMenuItem;
private: System::Windows::Forms::TabControl^ tabControl1;
private: System::Windows::Forms::TabPage^ lottoTab;
private: System::Windows::Forms::TabPage^ euroTab;
private: System::Windows::Forms::TabPage^ webTab;
private: System::Windows::Forms::GroupBox^ lottoValues;
private: System::Windows::Forms::SplitContainer^ euroEntry;
private: System::Windows::Forms::GroupBox^ euroValues;
private: System::Windows::Forms::GroupBox^ euroStars;
private: System::Windows::Forms::Button^ euroValue5;
private: System::Windows::Forms::Button^ euroValue4;
private: System::Windows::Forms::Button^ euroValue3;
private: System::Windows::Forms::Button^ euroValue2;
private: System::Windows::Forms::Button^ euroValue1;
private: System::Windows::Forms::Button^ euroStar2;
private: LottoLimitsDialog^ lottoLimitsDialog;
private: System::Windows::Forms::Button^ euroStar1;
private: System::Windows::Forms::Button^ lottoValue6;
private: System::Windows::Forms::Button^ lottoValue5;
private: System::Windows::Forms::Button^ lottoValue4;
private: System::Windows::Forms::Button^ lottoValue3;
private: System::Windows::Forms::Button^ lottoValue2;
private: System::Windows::Forms::Button^ lottoValue1;
private: System::Windows::Forms::WebBrowser^ webBrowser;
private: System::Windows::Forms::ContextMenuStrip^ buttonContextMenu;
private: System::Windows::Forms::ToolStripMenuItem^ chooseValue;
private: System::ComponentModel::IContainer^ components;
private:
int lottoValuesCount; // Number of values in Lotto entry
int euroValuesCount; // Number of values in Euromillions entry
int euroStarsCount; // Number of stars in Euromillions entry
int lottoLowerLimit; // Minimum value allowed in Lotto
int lottoUpperLimit; // Maximum value allowed in Lotto
int lottoUserMinimum; // Lower lotto range limit from user
int lottoUserMaximum; // Upper lotto range limit from user
int euroLowerLimit; // Minimum value allowed in Euromillions
int euroUpperLimit; // Maximum value allowed in Euromillions
int euroStarsLowerLimit; // Minimum stars value allowed in Euromillions
int euroStarsUpperLimit; // Maximum stars value allowed in Euromillions
int euroUserMinimum; // Lower euro range limit from user
int euroUserMaximum; // Upper euro range limit from user
int euroStarsUserMinimum; // Lower euro stars range limit from user
int euroStarsUserMaximum; // Upper euro stars range limit from user
Random^ random; // Generates pseudo-random numbers
private:
EuroLimitsDialog^ euroLimitsDialog; // Dialog to set Euromillions limits
private:
Button^ contextButton; // Button that was right-clicked for context menu
private: UserValueDialog^ userValueDialog;
private:
void GetValues(array<int>^ values, int min, int max)
{
values[0] = random->Next(min, max); // Generate first random value
// Generate remaining random values
for(int i = 1 ; i<values->Length ; i++)
{
for(;;) // Loop until a valid value is found
{
// Generate random integer from min to max
values[i] = random->Next(min, max);
// Check that its different from previous values
if(IsValid(values[i], values, i)) // Check against previous values...
break; // ...it is different so end loop
}
}
}
// Check whether number is different from values array elements
// at index positions less than indexLimit
bool IsValid(int number, array<int>^ values, int indexLimit)
{
for(int i = 0 ; i< indexLimit ; i++)
{
if(number == values[i])
return false;
}
return true;
}
// Set values as text on buttons in a GroupBox control
void SetValues(array<int>^ values, GroupBox^ groupBox)
{
Array::Sort(values); // Sort values in ascending sequence
int count = values->Length - 1;
for(int i = 0 ; i<groupBox->Controls->Count ; i++)
safe_cast<Button^>(groupBox->Controls[i])->Text = values[count-i].ToString();
}
// Generates a new value for button different from current button values
void SetNewValue(Button^ button, array<Button^>^ buttons,
int lowerLimit, int upperLimit)
{
int index = 0; // Index of button in buttons
// Array to store button values
array<int>^ values = gcnew array<int>(buttons->Length);
// Get values from buttons and find index for button
for(int i = 0 ; i < values->Length ; i++)
{
values[i] = Int32::Parse(buttons[i]->Text); // Get current button value
// If current handle is same as button, save the index value
if(button == buttons[i])
index = i;
}
int newValue = 0; // Store the new button value
// Check if it is different from the other button values
for(;;) // Loop until we get a good one
{
newValue = random->Next(lowerLimit, upperLimit); // Generate a value
if(IsValid(newValue, values, values->Length)) // If it's OK...
break; // ...end the loop
}
values[index] = newValue; // Store the new value at index
Array::Sort(values); // Sort the value
for(int i = 0 ; i < values->Length ; i++) // and set the values
buttons[i]->Text = values[i].ToString(); // as text on the buttons
}
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->components = (gcnew System::ComponentModel::Container());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->playMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->limitsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->upperMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->lowerMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->resetMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->aboutMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
this->buttonContextMenu = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->chooseValue = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->lottoTab = (gcnew System::Windows::Forms::TabPage());
this->lottoValues = (gcnew System::Windows::Forms::GroupBox());
this->lottoValue6 = (gcnew System::Windows::Forms::Button());
this->lottoValue5 = (gcnew System::Windows::Forms::Button());
this->lottoValue4 = (gcnew System::Windows::Forms::Button());
this->lottoValue3 = (gcnew System::Windows::Forms::Button());
this->lottoValue2 = (gcnew System::Windows::Forms::Button());
this->lottoValue1 = (gcnew System::Windows::Forms::Button());
this->euroTab = (gcnew System::Windows::Forms::TabPage());
this->euroEntry = (gcnew System::Windows::Forms::SplitContainer());
this->euroValues = (gcnew System::Windows::Forms::GroupBox());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -