在进行开发简易串口助手时,在看视频照着开发时,回头发现vs中的控件全部消失隐藏不见了,再拖入新的控件后发现之前的控件并未消失,只是看不见了,翻了一下CSDN,发现很多简略得几句话带过来,于是自己观察代码,发现了因为几行代码的消失引起的控件消失,将自己的大概解决过程通过此篇文章分享一下,如有不对请多指教。
具体问题出在画红线这个文件中
然后我经过跟控件未消失代码进行比对会发现画圈代码消失了,上方的画圈代码直接进行补全即可,下方的补全几行即可
this.components = new System.ComponentModel.Container();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.serialPort1 = new System.IO.Ports.SerialPort(this.components);
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
/*这个按照自己所缺失的控件进行补全即可*/
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(3, 13);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(58, 19);
this.radioButton1.TabIndex = 0;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "数值";
this.radioButton1.UseVisualStyleBackColor = true;
/* 不用全部补全,仅补全几行运行之后控件便会重新回来*/
在代码最后几行再将这些Add上去,像如图
第一张图片下方画圈的代码具体跟控件的属性什么的有关,而且不同的控件也并不相同,很难自己去独立补全这些,但是只补全几行后Add之后,重新进行编译运行,便可以发现winform控件重新出现(但有可能没有什么颜色,跟补全的属性什么有关大概),需要在窗体各个地方点一下,便会发现,再点回这个文件发现没补全的几行代码也会重新出现。
具体为什么winform控件会突然消失这一问题并不是很清楚,希望有大佬能说明一下。