PC Review


Reply
Thread Tools Rate Thread

convert code written without editor to editor compatible?

 
 
Billy Greening
Guest
Posts: n/a
 
      7th Jun 2004
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;
}
}



 
Reply With Quote
 
 
 
 
Mickey Williams
Guest
Posts: n/a
 
      7th Jun 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
> }
> }
>
>
>



 
Reply With Quote
 
 
 
 
Greg Miller
Guest
Posts: n/a
 
      8th Jun 2004
On Mon, 7 Jun 2004 12:25:38 -0400, "Billy Greening"
<(E-Mail Removed)> wrote:

>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.
 
Reply With Quote
 
Billy Greening
Guest
Posts: n/a
 
      8th Jun 2004

Thanks, thats what I was afraid of.


"Mickey Williams" <my first name at servergeek.com> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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;
>> }
>> }
>>
>>
>>

>
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      8th Jun 2004
Billy Greening <(E-Mail Removed)> wrote:
> 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...

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when writing out a file from .net, when is the file created? after the bytes are all written to the hard drive or before the bytes are written to the hard drive? Daniel Microsoft Dot NET 1 8th Sep 2005 10:01 AM
when writing out a file from .net, when is the file created? after the bytes are all written to the hard drive or before the bytes are written to the hard drive? Daniel Microsoft Dot NET Framework 1 7th Sep 2005 01:48 PM
Debugging COM written for .Net called by application written for Win32 Konrad Kataneksza Microsoft C# .NET 1 13th Apr 2005 06:27 PM
Text written in Word-Pad and written to a CD lose it's format =?Utf-8?B?QmlsbCBDdXJ0aXM=?= Windows XP Help 1 7th Feb 2004 02:56 AM
Re: Can a usercontrol written in C# be used in Web Forms that is written in VB.Net? Steve C. Orr, MCSD Microsoft ASP .NET 1 24th Aug 2003 01:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:02 PM.