如何编写简单的程序来重新排列代码

时间:2019-05-03 05:37:30

标签: c# winforms

我想更改某些代码在非常旧的源代码中的位置(由我的朋友在VS 2008中创建,所以它的发生次数约为数千,大约有500种形式,所以我希望我不必手动进行操作)。因此,示例如下所示:

point = new Point(0x3f, 0x26);
this.txtName.Location = point;

喜欢这样

this.txtName.Location = new Point(0x3f, 0x26);

如果不进行更改,将会导致错误,我也不知道为什么(我是C#的新手)。因此,基本上,如果我找到一个为位置或大小分配了值的代码,则需要从上一行剪切该值,将该值粘贴到属性值分配中等号的右边,然后删除上一行。我该如何用C#编写一个简单的应用程序,以对文件夹中的所有CS文件执行此操作?

更新

正如谜一样,这是其中的一些代码。

private void InitializeComponent()
    {
        ComponentResourceManager manager = new ComponentResourceManager(typeof(fedit_area));
        this.txtID = new TextEdit();
        this.txtName = new TextEdit();
        this.LabelControl1 = new LabelControl();
        this.LabelControl2 = new LabelControl();
        this.btnCancel = new SimpleButton();
        this.btnSave = new SimpleButton();
        this.txtID.Properties.BeginInit();
        this.txtName.Properties.BeginInit();
        this.SuspendLayout();
        this.txtID.EnterMoveNextControl = true;
        Point point = new Point(0x3f, 12);
        this.txtID.Location = point;
        this.txtID.Name = "txtID";
        this.txtID.Properties.Appearance.ForeColor = Color.Blue;
        this.txtID.Properties.Appearance.Options.UseForeColor = true;
        this.txtID.Properties.AppearanceFocused.BackColor = Color.FromArgb(0xff, 0xff, 0xc0);
        this.txtID.Properties.AppearanceFocused.Options.UseBackColor = true;
        this.txtID.Properties.CharacterCasing = CharacterCasing.Upper;
        this.txtID.Properties.MaxLength = 100;
        Size size = new Size(0xd4, 20);
        this.txtID.Size = size;
        this.txtID.TabIndex = 1;
        this.txtName.EnterMoveNextControl = true;
        point = new Point(0x3f, 0x26);
        this.txtName.Location = point;
        this.txtName.Name = "txtName";
        this.txtName.Properties.Appearance.ForeColor = Color.Blue;
        this.txtName.Properties.Appearance.Options.UseForeColor = true;
        this.txtName.Properties.AppearanceFocused.BackColor = Color.FromArgb(0xff, 0xff, 0xc0);
        this.txtName.Properties.AppearanceFocused.Options.UseBackColor = true;
        this.txtName.Properties.MaxLength = 0xff;
        size = new Size(0xd4, 20);
        this.txtName.Size = size;
        this.txtName.TabIndex = 3;
        point = new Point(12, 15);
        this.LabelControl1.Location = point;
        this.LabelControl1.Name = "LabelControl1";
        size = new Size(0x18, 13);
        this.LabelControl1.Size = size;
        this.LabelControl1.TabIndex = 0;
        this.LabelControl1.Text = "&Kode";
        point = new Point(12, 0x29);
        this.LabelControl2.Location = point;
        this.LabelControl2.Name = "LabelControl2";
        size = new Size(0x1b, 13);
        this.LabelControl2.Size = size;
        this.LabelControl2.TabIndex = 2;
        this.LabelControl2.Text = "&Nama";
        this.btnCancel.DialogResult = DialogResult.Cancel;
        this.btnCancel.Image = WindowsApplication1.My.Resources.Resources.cancel;
        point = new Point(0xc1, 0x41);
        this.btnCancel.Location = point;
        this.btnCancel.Name = "btnCancel";
        size = new Size(0x52, 0x17);
        this.btnCancel.Size = size;
        this.btnCancel.TabIndex = 5;
        this.btnCancel.Text = "&Batal";
        this.btnSave.Image = WindowsApplication1.My.Resources.Resources.ok;
        point = new Point(0x69, 0x41);
        this.btnSave.Location = point;
        this.btnSave.Name = "btnSave";
        size = new Size(0x52, 0x17);
        this.btnSave.Size = size;
        this.btnSave.TabIndex = 4;
        this.btnSave.Text = "&Simpan";
        SizeF ef = new SizeF(6f, 13f);
        this.AutoScaleDimensions = ef;
        this.AutoScaleMode = AutoScaleMode.Font;
        this.CancelButton = this.btnCancel;
        size = new Size(0x11f, 100);
        this.ClientSize = size;
        this.Controls.Add(this.btnCancel);
        this.Controls.Add(this.LabelControl2);
        this.Controls.Add(this.LabelControl1);
        this.Controls.Add(this.btnSave);
        this.Controls.Add(this.txtName);
        this.Controls.Add(this.txtID);
        this.Icon = (Icon) manager.GetObject("$this.Icon");
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "fedit_area";
        this.ShowInTaskbar = false;
        this.StartPosition = FormStartPosition.CenterParent;
        this.Text = "Area Pelanggan";
        this.txtID.Properties.EndInit();
        this.txtName.Properties.EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();
    }

其中大多数位于InitializeComponent中。从逻辑上讲,代码应该可以工作,但是会导致错误:

Duplicate declaration of member 'point'

Duplicate declaration of member 'size'

像这样重新排序后

private void InitializeComponent()
    {
        this.txtID = new DevExpress.XtraEditors.TextEdit();
        this.txtName = new DevExpress.XtraEditors.TextEdit();
        this.LabelControl1 = new DevExpress.XtraEditors.LabelControl();
        this.LabelControl2 = new DevExpress.XtraEditors.LabelControl();
        this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
        this.btnSave = new DevExpress.XtraEditors.SimpleButton();
        ((System.ComponentModel.ISupportInitialize)(this.txtID.Properties)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.txtName.Properties)).BeginInit();
        this.SuspendLayout();
        // 
        // txtID
        // 
        this.txtID.EnterMoveNextControl = true;
        this.txtID.Location = new System.Drawing.Point(63, 12);
        this.txtID.Name = "txtID";
        this.txtID.Properties.Appearance.ForeColor = System.Drawing.Color.Blue;
        this.txtID.Properties.Appearance.Options.UseForeColor = true;
        this.txtID.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
        this.txtID.Properties.AppearanceFocused.Options.UseBackColor = true;
        this.txtID.Properties.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
        this.txtID.Properties.MaxLength = 100;
        this.txtID.Size = new System.Drawing.Size(212, 20);
        this.txtID.TabIndex = 1;
        // 
        // txtName
        // 
        this.txtName.EnterMoveNextControl = true;
        this.txtName.Location = new System.Drawing.Point(63, 38);
        this.txtName.Name = "txtName";
        this.txtName.Properties.Appearance.ForeColor = System.Drawing.Color.Blue;
        this.txtName.Properties.Appearance.Options.UseForeColor = true;
        this.txtName.Properties.AppearanceFocused.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
        this.txtName.Properties.AppearanceFocused.Options.UseBackColor = true;
        this.txtName.Properties.MaxLength = 255;
        this.txtName.Size = new System.Drawing.Size(212, 20);
        this.txtName.TabIndex = 3;
        // 
        // LabelControl1
        // 
        this.LabelControl1.Location = new System.Drawing.Point(12, 15);
        this.LabelControl1.Name = "LabelControl1";
        this.LabelControl1.Size = new System.Drawing.Size(11, 13);
        this.LabelControl1.TabIndex = 0;
        this.LabelControl1.Text = "&ID";
        // 
        // LabelControl2
        // 
        this.LabelControl2.Location = new System.Drawing.Point(12, 41);
        this.LabelControl2.Name = "LabelControl2";
        this.LabelControl2.Size = new System.Drawing.Size(27, 13);
        this.LabelControl2.TabIndex = 2;
        this.LabelControl2.Text = "&Name";
        // 
        // btnCancel
        // 
        this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        this.btnCancel.Location = new System.Drawing.Point(193, 65);
        this.btnCancel.Name = "btnCancel";
        this.btnCancel.Size = new System.Drawing.Size(82, 23);
        this.btnCancel.TabIndex = 5;
        this.btnCancel.Text = "&Cancel";
        // 
        // btnSave
        // 
        this.btnSave.Location = new System.Drawing.Point(12, 65);
        this.btnSave.Name = "btnSave";
        this.btnSave.Size = new System.Drawing.Size(82, 23);
        this.btnSave.TabIndex = 4;
        this.btnSave.Text = "&Save";
        // 
        // fedit_area
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.CancelButton = this.btnCancel;
        this.ClientSize = new System.Drawing.Size(287, 100);
        this.Controls.Add(this.btnCancel);
        this.Controls.Add(this.LabelControl2);
        this.Controls.Add(this.LabelControl1);
        this.Controls.Add(this.btnSave);
        this.Controls.Add(this.txtName);
        this.Controls.Add(this.txtID);
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "fedit_area";
        this.ShowInTaskbar = false;
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
        this.Text = "Area";
        ((System.ComponentModel.ISupportInitialize)(this.txtID.Properties)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this.txtName.Properties)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

然后就没有错误了。

The form show without errors

无论是使用正则表达式还是编写简单的程序,如何一次对所有文件进行处理?

0 个答案:

没有答案