VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 473|回复: 0

求助 外部组件发生异常。

[复制链接]
38_avatar_middle
最佳答案
0 
在线会员 发表于 2022-8-3 00:08:00 | 显示全部楼层 |阅读模式
求助    外部组件发生异常。



System.Runtime.InteropServices.SEHException”类型的未经处理的异常出现在 NumberGame.exe 中。

其他信息: 外部组件发生异常。


  1. #pragma once

  2. struct POINT
  3. {
  4.         int _X;
  5.         int _Y;
  6. };
  7. struct UNIT
  8. {
  9.         POINT Zero;
  10.         int Wide;
  11.         int Number;
  12. };
  13. struct MyStruct
  14. {
  15.         POINT inPoint;
  16.         int width, height;
  17.         int fontSize;
  18. };
  19. namespace NumberGame {

  20.         using namespace System;
  21.         using namespace System::ComponentModel;
  22.         using namespace System::Collections;
  23.         using namespace System::Windows::Forms;
  24.         using namespace System::Data;
  25.         using namespace System::Drawing;

  26.         /// <summary>
  27.         /// Form1 摘要
  28.         /// </summary>
  29.         public ref class Form1 : public System::Windows::Forms::Form
  30.         {
  31.         public:
  32.                 Form1(void)
  33.                 {
  34.                         InitializeComponent();
  35.                         //
  36.                         //TODO: 在此处添加构造函数代码
  37.                         //
  38.                 }
  39.         protected:
  40.                 /// <summary>
  41.                 /// 清理所有正在使用的资源。
  42.                 /// </summary>

  43.                 ~Form1()
  44.                 {
  45.                         if (components)
  46.                         {
  47.                                 delete components;
  48.                         }
  49.                 }
  50.         private: System::Windows::Forms::TableLayoutPanel^  tableLayoutPanel1;
  51.         protected:
  52.         private: System::Windows::Forms::PictureBox^  pictureBox1;
  53.         private: System::Windows::Forms::PictureBox^  pictureBox2;

  54.         private:
  55.                 /// <summary>
  56.                 /// 必需的设计器变量。
  57.                 /// </summary>
  58.                 System::ComponentModel::Container ^components;

  59. #pragma region Windows Form Designer generated code
  60.                 /// <summary>
  61.                 /// 设计器支持所需的方法 - 不要
  62.                 /// 使用代码编辑器修改此方法的内容。
  63.                 /// </summary>
  64.                 void InitializeComponent(void)
  65.                 {
  66.                         this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
  67.                         this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
  68.                         this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
  69.                         this->tableLayoutPanel1->SuspendLayout();
  70.                         (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
  71.                         (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->BeginInit();
  72.                         this->SuspendLayout();
  73.                         //
  74.                         // tableLayoutPanel1
  75.                         //
  76.                         this->tableLayoutPanel1->ColumnCount = 2;
  77.                         this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
  78.                                 66.66666F)));
  79.                         this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
  80.                                 33.33333F)));
  81.                         this->tableLayoutPanel1->Controls->Add(this->pictureBox1, 0, 0);
  82.                         this->tableLayoutPanel1->Controls->Add(this->pictureBox2, 1, 0);
  83.                         this->tableLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Fill;
  84.                         this->tableLayoutPanel1->Location = System::Drawing::Point(0, 0);
  85.                         this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
  86.                         this->tableLayoutPanel1->RowCount = 1;
  87.                         this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 100)));
  88.                         this->tableLayoutPanel1->Size = System::Drawing::Size(784, 522);
  89.                         this->tableLayoutPanel1->TabIndex = 0;
  90.                         //
  91.                         // pictureBox1
  92.                         //
  93.                         this->pictureBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(192)), static_cast<System::Int32>(static_cast<System::Byte>(255)),
  94.                                 static_cast<System::Int32>(static_cast<System::Byte>(192)));
  95.                         this->pictureBox1->Dock = System::Windows::Forms::DockStyle::Fill;
  96.                         this->pictureBox1->Location = System::Drawing::Point(3, 3);
  97.                         this->pictureBox1->Name = L"pictureBox1";
  98.                         this->pictureBox1->Size = System::Drawing::Size(516, 516);
  99.                         this->pictureBox1->TabIndex = 0;
  100.                         this->pictureBox1->TabStop = false;
  101.                         //
  102.                         // pictureBox2
  103.                         //
  104.                         this->pictureBox2->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(192)),
  105.                                 static_cast<System::Int32>(static_cast<System::Byte>(192)));
  106.                         this->pictureBox2->Dock = System::Windows::Forms::DockStyle::Fill;
  107.                         this->pictureBox2->Location = System::Drawing::Point(525, 3);
  108.                         this->pictureBox2->Name = L"pictureBox2";
  109.                         this->pictureBox2->Size = System::Drawing::Size(256, 516);
  110.                         this->pictureBox2->TabIndex = 1;
  111.                         this->pictureBox2->TabStop = false;
  112.                         //
  113.                         // Form1
  114.                         //
  115.                         this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
  116.                         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  117.                         this->ClientSize = System::Drawing::Size(784, 522);
  118.                         this->Controls->Add(this->tableLayoutPanel1);
  119.                         this->Name = L"Form1";
  120.                         this->Text = L"Form1";
  121.                         this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  122.                         this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Resize);
  123.                         this->tableLayoutPanel1->ResumeLayout(false);
  124.                         (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
  125.                         (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->EndInit();
  126.                         this->ResumeLayout(false);

  127.                 }
  128. #pragma endregion
  129.         private: static int barrier = 3;
  130.         private: static int P2row = 0;
  131.         private: static int P2col = 0;
  132.         private: static int P2left = 0;
  133.         private: static int P2top = 0;
  134.         private: static int P2wide = 0;

  135.         private: UNIT** Array1;
  136.         private: UNIT** Array2;

  137.         private: void Array1Init()
  138.                          {
  139.                           //------Array1初始化-------------
  140.                                  Array1 = new UNIT*[barrier];
  141.                                  for(int i=0; i<barrier; i++)
  142.                                  {
  143.                                           Array1[i] = new UNIT;
  144.                                          // Array1[i]->fontSize = i;  
  145.                                  }
  146.                                  int wide = (this->pictureBox1->Width-12)/barrier;
  147.                                  for(int i=0; i<barrier; i++)
  148.                                          for(int j=0; j<barrier; j++)
  149.                                          {
  150.                                                  Array1[i][j].Wide = wide;
  151.                                                  //Array1[i][j].Number = 0;
  152.                                                  Array1[i][j].Number = i*barrier+j+1;
  153.                                                  Array1[i][j].Zero._X = j*wide + 6;
  154.                                                  Array1[i][j].Zero._Y = i*wide + 6;
  155.                                          }
  156.                          }
  157.         private: void Array2Init()
  158.                          {
  159.                                  //------Array2初始化-------------
  160.                                  Array2 = new UNIT*[P2row];
  161.                                  for(int i=0; i<P2col; i++)
  162.                                  {
  163.                                           Array2[i] = new UNIT;
  164.                                          // Array2[i]->fontSize = i;  
  165.                                  }
  166.                                  int wide = (this->pictureBox2->Width-2*P2left)/P2col;
  167.                          }
  168.         private: MyStruct get_format(Point^ inpoint, int wide, int num)
  169.         {

  170.                 int imgWide = (wide * 3) / 2;
  171.                 int fontsize = 0;// wide / len;

  172.                 System::Drawing::Font^ drawFont;

  173.                 SizeF layoutSize = SizeF(wide, wide);

  174.                 Graphics^ g = CreateGraphics();

  175.                 StringFormat^ sformat = gcnew StringFormat();
  176.                 sformat->Alignment = StringAlignment::Center;
  177.                 sformat->LineAlignment = StringAlignment::Center;
  178.                 sformat->FormatFlags = StringFormatFlags(0);

  179.                 SizeF sizeF(0, 0);
  180.                 while (sizeF.Width < wide)
  181.                 {
  182.                         fontsize++;
  183.                         drawFont = gcnew System::Drawing::Font("宋体", fontsize);
  184.                         sizeF = g->MeasureString(num.ToString(), drawFont, *inpoint, sformat);

  185.                         delete drawFont;
  186.                 }

  187.                 MyStruct _format;
  188.                 _format.fontSize = fontsize;
  189.                 _format.inPoint._X = inpoint->X + (wide - sizeF.Width) / 2;
  190.                 _format.inPoint._Y = inpoint->Y + (wide - sizeF.Height) / 2 + 5;
  191.                 _format.height = sizeF.Height;
  192.                 _format.width = sizeF.Width;

  193.                 delete sformat;
  194.                 delete g;

  195.                 return _format;

  196.         }
  197.         private: void draw_p1_num(Point^ inpoint, int wide, int num)
  198.         {
  199.                 Bitmap^ drawimg = gcnew Bitmap(this->pictureBox1->Image);
  200.                 Graphics^ g = Graphics::FromImage(drawimg);
  201.                 SolidBrush^ MyBrush = gcnew SolidBrush(this->pictureBox1->BackColor);
  202.                 g->FillRectangle(MyBrush, Rectangle(inpoint->X + wide / 20, inpoint->Y + wide / 20, (wide * 9) / 10, (wide * 9) / 10));
  203.                 MyBrush->Color = Color::Black;

  204.                 inpoint->X += wide / 10;
  205.                 inpoint->Y += wide / 10;
  206.                 int d = (wide * 4) / 5;
  207.                 Rectangle rectEllip = Rectangle(inpoint->X, inpoint->Y, d, d);
  208.                 g->FillEllipse(MyBrush, rectEllip);

  209.                 MyStruct drawformat = get_format(inpoint, rectEllip.Width, num);
  210.                 System::Drawing::Font^ drawFont = gcnew System::Drawing::Font("宋体", drawformat.fontSize);

  211.                 Rectangle rectFont = Rectangle(drawformat.inPoint._X, drawformat.inPoint._Y, drawformat.width, drawformat.height);

  212.                 MyBrush->Color = this->pictureBox1->BackColor;
  213.                 g->DrawString(num.ToString(), drawFont, MyBrush, Point(drawformat.inPoint._X, drawformat.inPoint._Y));

  214.                 this->pictureBox1->Image = (Image^)drawimg->Clone();
  215.                 delete drawFont;
  216.                 delete g;
  217.                 delete drawimg;
  218.         }
  219.         private: void p1_all_out()
  220.                          {
  221.                                  for(int i=0; i<barrier; i++)
  222.                                         for(int j=0; j<barrier; j++)
  223.                                         {
  224.                                                 draw_p1_num(Point(Array1[i][j].Zero._X, Array1[i][j].Zero._Y), Array1[i][j].Wide, Array1[i][j].Number);
  225.                                         }
  226.                          }
  227.         private: void SetMaxSize()
  228.                          {
  229.                                 int maxwidth = Screen::PrimaryScreen->WorkingArea.Width;
  230.                                 int maxheight = Screen::PrimaryScreen->WorkingArea.Height;
  231.                                 if(maxwidth > ((maxheight - 39)*3)/2+16)
  232.                                         maxwidth = ((maxheight - 39)*3)/2+16;
  233.                                 else if(maxheight> ((maxwidth-16)*2)/3+39)
  234.                                         maxheight = ((maxwidth-16)*2)/3+39;
  235.                                 //this->MaximumSize.Width = maxwidth;
  236.                                 //this->MaximumSize.Height = maxheight;
  237.                                 this->MaximumSize = System::Drawing::Size( maxwidth, maxheight);
  238.                          }
  239.         private: void DrawChart2(int num)
  240.         {
  241.                 int Swidth = (this->pictureBox2->Width - 12) / num;
  242.                 int totality = ((this->pictureBox2->Width - 12) / Swidth) * ((this->pictureBox2->Height - 12) / Swidth);
  243.                 while (totality >= num * num)
  244.                 {
  245.                         Swidth++;
  246.                         totality = ((this->pictureBox2->Width - 12) / Swidth) * ((this->pictureBox2->Height - 12) / Swidth);
  247.                 }
  248.                 Swidth--;
  249.                
  250.                 int col = (this->pictureBox2->Width - 12) / Swidth;
  251.                 int row = (barrier * barrier) % col == 0 ? (barrier * barrier) / col : (barrier * barrier) / col + 1;
  252.                 int left = (this->pictureBox2->Width - col * Swidth) / 2;
  253.                 int        top = (this->pictureBox2->Height - row * Swidth) / 2;
  254.                 P2col = col;
  255.                 P2row = row;
  256.                 P2left = left;
  257.                 P2top = top;
  258.                 P2wide = Swidth;

  259.                 Bitmap^ drawimg = gcnew Bitmap(this->pictureBox2->Width, this->pictureBox2->Height);
  260.                 Graphics^ g = Graphics::FromImage(drawimg);
  261.                 Pen^ mypen = gcnew Pen(Color::Green, 1);

  262.                 for (int i = 0; i <= row; i++)
  263.                         g->DrawLine(mypen, Point(left, i * Swidth + top), Point(col * Swidth + left, i * Swidth + top));
  264.                 for (int i = 0; i <= col; i++)
  265.                         g->DrawLine(mypen, Point(i * Swidth + left, top), Point(i * Swidth + left, row * Swidth + top));

  266.                 this->pictureBox2->Image = (Image^)drawimg->Clone();
  267.                 delete g;
  268.                 delete drawimg;
  269.         }
  270.         private: void DrawChart(int num)
  271.         {

  272.                 Bitmap^ drawimg = gcnew Bitmap(pictureBox1->Width, pictureBox1->Height);
  273.                 Graphics^ g = Graphics::FromImage(drawimg);

  274.                 Pen^ mypen = gcnew Pen(Color::Red, 1);
  275.                 int Swidth = (pictureBox1->Width - 12) / num;
  276.                 for (int i = 0; i <= num; i++)
  277.                         g->DrawLine(mypen, Point(6, i * Swidth + 6), Point(num * Swidth + 6, i * Swidth + 6));
  278.                 for (int i = 0; i <= num; i++)
  279.                         g->DrawLine(mypen, Point(i * Swidth + 6, 6), Point(i * Swidth + 6, num * Swidth + 6));

  280.                 this->pictureBox1->Image = (Image^)drawimg->Clone();

  281.                 delete g;
  282.                 delete drawimg;
  283.         }
  284.         private: void calc_point()
  285.                          {
  286.                                  int wide = (this->pictureBox1->Width-12)/barrier;
  287.                                  for(int i=0; i<barrier; i++)
  288.                                          for(int j=0; j<barrier; j++)
  289.                                          {
  290.                                                  Array1[i][j].Wide = wide;
  291.                                                  //Array1[i][j].Number = 0;
  292.                                                  //Array1[i][j].Number = i*barrier+j+1;
  293.                                                  Array1[i][j].Zero._X = j*wide + 6;
  294.                                                  Array1[i][j].Zero._Y = i*wide + 6;
  295.                                          }
  296.                          }
  297.         private: System::Void Form1_Resize(System::Object^  sender, System::EventArgs^  e)
  298.                          {
  299.                                  Control^ control = dynamic_cast<Control^>(sender);

  300.                                  //拖动窗口比例缩放,确保pictureBox1 Size 为正方形.
  301.                                  int swidth = control->Size.Width;
  302.                                  int sheight = control->Size.Height;


  303.                                  if(sheight > 28) //sheight > 28 窗口不是最小化。
  304.                                  {
  305.                                          int maxwidth = Screen::PrimaryScreen->WorkingArea.Width;
  306.                                          int maxheight = Screen::PrimaryScreen->WorkingArea.Height;

  307.                                          if(swidth > maxwidth)
  308.                                                 swidth = maxwidth;

  309.                                          sheight = ((swidth-16)*2)/3+39;

  310.                                          if(sheight>maxheight)
  311.                                          {
  312.                                                  sheight = maxheight;
  313.                                                  swidth = ((sheight - 39)*3)/2+16;
  314.                                          }
  315.                                          
  316.                                          control->Size = System::Drawing::Size(swidth, sheight);

  317.                                          //this->pictureBox1->Image=nullptr;
  318.                                          //this->pictureBox2->Image=nullptr;
  319.                                          DrawChart(barrier);
  320.                                          DrawChart2(barrier);
  321.                                          calc_point();
  322.                                          p1_all_out();
  323.                                  }
  324.                          }
  325.         private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)
  326.                          {
  327.                                  SetMaxSize();                        //设置窗口最大尺寸
  328.                                  DrawChart(barrier);        //绘制图片框1,的表格
  329.                                  DrawChart2(barrier);        //绘制图片框2,的表格
  330.                                  Array1Init();                        //Array1数组初始化
  331.                                  Array2Init();                        //Array2数组初始化

  332.                                  p1_all_out();                        //输出图片框1全部单元格。
  333.                          }
  334. };
  335. }

复制代码


求助    外部组件发生异常。 Form1.rar (3.15 KB, 下载次数: 0)




上一篇:我用了这个代码,咋实现不了鼠标穿越窗体呢?
下一篇:关于MFC ListCtr控件的问题
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-12-3 18:26

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表