【发布时间】:2015-03-27 10:48:37
【问题描述】:
为了轻松合并 *.Designer.vb 文件中的更改(*.Designer.cs 文件也是如此),我需要在 Designer 生成的文件中对某些代码部分的内容进行排序,因为 Visual Studio is sometimes reordering them randomly .我可以在重新排列之前看到 16 个合并冲突,之后有 0 个 冲突。
我对排序声明等毫无疑问。但我怀疑ResumeLayout(false) 和PerformLayout() 在InitializeComponent() 方法结束时调用。尽管进行了一些学习,但我还没有完全了解它们是如何工作的 (practical details found here),因此我正在寻求一个答案,重新排列它们被调用的对象的顺序是否安全.到目前为止,使用 Designer 进行的测试没有显示出问题,但我想确定一下。
Form1.Designer.vb中的原始顺序
Private Sub InitializeComponent()
'...initializations of controls are left out
'
'Form1
'
Me.ClientSize = New System.Drawing.Size(784, 562)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form1"
Me.Text = "Form1 Title"
'original order created by Designer
CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
Me.TableLayoutPanel1.ResumeLayout(False)
Me.TableLayoutPanel1.PerformLayout()
Me.page2.ResumeLayout(False)
Me.page2.PerformLayout()
Me.page1.ResumeLayout(False)
Me.TableLayoutPanel2.ResumeLayout(False)
Me.TableLayoutPanel2.PerformLayout()
Me.TabCtl1.ResumeLayout(False)
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
'end of section in question
Me.ResumeLayout(False)
End Sub
Form1.Designer.vb 中的修改顺序
Private Sub InitializeComponent()
'...initializations of controls are left out
'
'Form1
'
Me.ClientSize = New System.Drawing.Size(784, 562)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form1"
Me.Text = "Form1 Title"
'the following lines (or pairs) were arranged alphabetically - is it OK?
CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.page1.ResumeLayout(False)
Me.page2.ResumeLayout(False)
Me.page2.PerformLayout()
Me.TabCtl1.ResumeLayout(False)
Me.TableLayoutPanel1.ResumeLayout(False)
Me.TableLayoutPanel1.PerformLayout()
Me.TableLayoutPanel2.ResumeLayout(False)
Me.TableLayoutPanel2.PerformLayout()
'end of sorted groups
Me.ResumeLayout(False)
End Sub
这样的改变总是安全的吗?还是应该根据控件的树层次结构(首先列出父级)而不是按字母顺序排列命令?
编辑:一些进一步的研究表明,表单设计师将祖先放在首位,但不强制执行其他特定顺序。控件的顺序仅由Control.Add() 调用的顺序决定。也许我可以改进排序方法来反映这一点,我应该是安全的。
【问题讨论】:
标签: .net vb.net winforms visual-studio designer