convert code written without editor to editor compatible?

  • Thread starter Thread starter Billy Greening
  • Start date Start date
B

Billy Greening

I have an application in C# that was written as a bunch of individual CS
files. I would like to combine these all into single solution that can be
editied with the Visual Studio 2003 editor. Does anyone have any tips on
how to quickly bring this code into the VS2003 environment? Below is a
sample of the code for an about box: For this example, it wouldn't be all
that difficult to just create a new form and set all the properties to match
this code through the designer, but there are 20 other much more complex
forms I would need to do the same thing for.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace ActiveNotes
{
public class AboutBox: Form
{

private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnOK;
/*
*
public static void Main()
{
AboutBox dlg = new AboutBox();
DialogResult dr = dlg.ShowDialog();
Console.WriteLine("Dialog box terminated with " + dr);
}
*/
public AboutBox()
{
Text = "About ActiveNotes";
StartPosition = FormStartPosition.CenterScreen;

pictureBox1 = new System.Windows.Forms.PictureBox();
label1 = new System.Windows.Forms.Label();
labelVersion = new System.Windows.Forms.Label();
btnOK = new System.Windows.Forms.Button();

//Standard style for dialog boxes
FormBorderStyle = FormBorderStyle.FixedDialog;
//To allow cancel without buttons.
//ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;


//
// pictureBox1
//
this.pictureBox1.Image =
Image.FromFile(Path.GetDirectoryName(Application.ExecutablePath)+"\\art\\splash2.jpg");
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(376, 296);
this.pictureBox1.TabIndex = 7;
this.pictureBox1.TabStop = false;

//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 312);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(376, 23);
this.label1.TabIndex = 1;
this.label1.Text = "ActiveNotes 3.0 - Copyright 2003 ActiveGroup
Ventures, Inc.";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;




//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(296, 360);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.OnOKClick);

this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.labelVersion,
this.btnOK,
this.linkLabel1,
this.label1,
this.pictureBox1});

ClientSize = new Size(392, 397);
this.Load += new System.EventHandler(this.AboutBox_Load);



}

void OnOKClick(object obj, EventArgs ea)
{
DialogResult = DialogResult.OK;
}

protected override void OnPaint(PaintEventArgs pea)
{
Graphics g = pea.Graphics;

}


private void AboutBox_Load(object sender, System.EventArgs e)
{
this.ActiveControl = this.btnOK;
}
}
 
Assuming you want the properties that you're setting during construction to
be reflected in the design-time experience and have design-time changes
automatically round-tripped, it's quite difficult to migrate this code
without manually creating a form in Visual Studio. The reason is that the
form designer serializes its state into your source code in a specific
format, and it's unlikely that you'll accidently stumble across it.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com/blogs/mickey



Billy Greening said:
I have an application in C# that was written as a bunch of individual CS
files. I would like to combine these all into single solution that can be
editied with the Visual Studio 2003 editor. Does anyone have any tips on
how to quickly bring this code into the VS2003 environment? Below is a
sample of the code for an about box: For this example, it wouldn't be all
that difficult to just create a new form and set all the properties to match
this code through the designer, but there are 20 other much more complex
forms I would need to do the same thing for.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace ActiveNotes
{
public class AboutBox: Form
{

private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnOK;
/*
*
public static void Main()
{
AboutBox dlg = new AboutBox();
DialogResult dr = dlg.ShowDialog();
Console.WriteLine("Dialog box terminated with " + dr);
}
*/
public AboutBox()
{
Text = "About ActiveNotes";
StartPosition = FormStartPosition.CenterScreen;

pictureBox1 = new System.Windows.Forms.PictureBox();
label1 = new System.Windows.Forms.Label();
labelVersion = new System.Windows.Forms.Label();
btnOK = new System.Windows.Forms.Button();

//Standard style for dialog boxes
FormBorderStyle = FormBorderStyle.FixedDialog;
//To allow cancel without buttons.
//ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;


//
// pictureBox1
//
this.pictureBox1.Image =
Image.FromFile(Path.GetDirectoryName(Application.ExecutablePath)+"\\art\\spl
ash2.jpg");
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(376, 296);
this.pictureBox1.TabIndex = 7;
this.pictureBox1.TabStop = false;

//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 312);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(376, 23);
this.label1.TabIndex = 1;
this.label1.Text = "ActiveNotes 3.0 - Copyright 2003 ActiveGroup
Ventures, Inc.";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;




//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(296, 360);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.OnOKClick);

this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.labelVersion,
this.btnOK,
this.linkLabel1,
this.label1,
this.pictureBox1});

ClientSize = new Size(392, 397);
this.Load += new System.EventHandler(this.AboutBox_Load);



}

void OnOKClick(object obj, EventArgs ea)
{
DialogResult = DialogResult.OK;
}

protected override void OnPaint(PaintEventArgs pea)
{
Graphics g = pea.Graphics;

}


private void AboutBox_Load(object sender, System.EventArgs e)
{
this.ActiveControl = this.btnOK;
}
}
 
I have an application in C# that was written as a bunch of individual CS
files. I would like to combine these all into single solution that can be
editied with the Visual Studio 2003 editor. Does anyone have any tips on
how to quickly bring this code into the VS2003 environment? Below is a
sample of the code for an about box: For this example, it wouldn't be all
that difficult to just create a new form and set all the properties to match
this code through the designer, but there are 20 other much more complex
forms I would need to do the same thing for.

That's a drawback of Microsoft's designers, you either have to
always use them, or never use them. There's very little latitude for
switching back and forth.
 
Thanks, thats what I was afraid of.


Mickey Williams said:
Assuming you want the properties that you're setting during construction
to
be reflected in the design-time experience and have design-time changes
automatically round-tripped, it's quite difficult to migrate this code
without manually creating a form in Visual Studio. The reason is that the
form designer serializes its state into your source code in a specific
format, and it's unlikely that you'll accidently stumble across it.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com/blogs/mickey



Billy Greening said:
I have an application in C# that was written as a bunch of individual CS
files. I would like to combine these all into single solution that can
be
editied with the Visual Studio 2003 editor. Does anyone have any tips on
how to quickly bring this code into the VS2003 environment? Below is a
sample of the code for an about box: For this example, it wouldn't be
all
that difficult to just create a new form and set all the properties to match
this code through the designer, but there are 20 other much more complex
forms I would need to do the same thing for.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace ActiveNotes
{
public class AboutBox: Form
{

private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnOK;
/*
*
public static void Main()
{
AboutBox dlg = new AboutBox();
DialogResult dr = dlg.ShowDialog();
Console.WriteLine("Dialog box terminated with " + dr);
}
*/
public AboutBox()
{
Text = "About ActiveNotes";
StartPosition = FormStartPosition.CenterScreen;

pictureBox1 = new System.Windows.Forms.PictureBox();
label1 = new System.Windows.Forms.Label();
labelVersion = new System.Windows.Forms.Label();
btnOK = new System.Windows.Forms.Button();

//Standard style for dialog boxes
FormBorderStyle = FormBorderStyle.FixedDialog;
//To allow cancel without buttons.
//ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;


//
// pictureBox1
//
this.pictureBox1.Image =
Image.FromFile(Path.GetDirectoryName(Application.ExecutablePath)+"\\art\\spl
ash2.jpg");
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(376, 296);
this.pictureBox1.TabIndex = 7;
this.pictureBox1.TabStop = false;

//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 312);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(376, 23);
this.label1.TabIndex = 1;
this.label1.Text = "ActiveNotes 3.0 - Copyright 2003 ActiveGroup
Ventures, Inc.";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;




//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(296, 360);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.OnOKClick);

this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.labelVersion,
this.btnOK,
this.linkLabel1,
this.label1,
this.pictureBox1});

ClientSize = new Size(392, 397);
this.Load += new System.EventHandler(this.AboutBox_Load);



}

void OnOKClick(object obj, EventArgs ea)
{
DialogResult = DialogResult.OK;
}

protected override void OnPaint(PaintEventArgs pea)
{
Graphics g = pea.Graphics;

}


private void AboutBox_Load(object sender, System.EventArgs e)
{
this.ActiveControl = this.btnOK;
}
}
 
Billy Greening said:
Thanks, thats what I was afraid of.

Look on the bright side though - things should get much nicer in this
respect with Avalon. Shame about the wait before Longhorn gets
released, for course...
 
Back
Top