Author Topic: Convert from .dll to .exe  (Read 2707 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Convert from .dll to .exe
« on: January 26, 2010, 03:02:01 PM »
Hi,
I have a small assembly (.dll) that displays a listview created from the contents of an excel file.

I really don't need AutoCAD for this and was wondering is there an easy way to compile it to an .exe windows form stand alone.

The only place that I reference AutoCAD is in the command method section:
Code: [Select]
using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

public class Initialization : Autodesk.AutoCAD.Runtime.IExtensionApplication
{
    public void Initialize()
    {
        Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage(" OBMSRef --- Loaded\r");
    }
    public void Terminate()
    {       
    }
}

namespace OBMSRef
{
    /// <summary>
    /// Summary description for main class.
    /// </summary>
    public class PartMonitor1
    {
       
        [CommandMethod("OBMSRef")]
        public static void ShowModelessDialog()
        {
            Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(OBMSRef.Instance);
        }       
    }

}

The form section only references the system:
Code: [Select]
using System;
using System.Text;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;

namespace OBMSRef
{
    /// <summary>
    /// Summary description for PartMonitor.
    /// </summary>
    public class OBMSRef : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components = null;
        private Button button2;
        private RichTextBox OldNumSearch;
        private ImageList ImgLst = new ImageList();
        private Button button1;
        private RichTextBox OBMSSearch;
        private ListView listView1;
        private Button button3;
        private ColumnHeader OBMSNumber;
        private ColumnHeader AS400Number;
        private ColumnHeader Description;
        private Label label1;

        private static OBMSRef instance = null;

        public static OBMSRef Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new OBMSRef();
                }
                return instance;
            }
        }
        /// <summary>
        /// Required designer variable.
        /// </summary>

        public OBMSRef()
        {
            //
            // Required for Windows Form Designer support
            //           
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            //
            //
        }


        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ///

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }


        #region Windows Form Designer generated code
        #endregion
        [STAThread]
        static void Main(string[] args)
        {
            System.Windows.Forms.Application.Run(new OBMSRef());
        }
        ///
        ///
        ///
        #region all form overrides
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            e.Cancel = true;
            Visible = false;
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);           
            FillListView();
           
        }

        #endregion



        #region All form Buttons section
        /// <summary>
        /// Button section
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>


        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SearchForOBMS();
            }
            catch (Exception ex)
            {
                MessageBox.Show("SearchOBMS: " + ex.StackTrace);
            }
           
        }     


        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                SearchForPart();
            }
            catch (Exception ex)
            {
                MessageBox.Show("SearchPart: " + ex.StackTrace);
            }
        }

        private void button3_Click(object sender, System.EventArgs e)  //Exit button
        {
            Hide();
        }

        #endregion

        public void SearchForOBMS()
        {
            try
            {
                string obmsNum = OBMSSearch.Text;
                ListViewItem item = listView1.FindItemWithText(obmsNum, true, 0, false);

                if (item != null)
                {
                    listView1.Items[item.Index].EnsureVisible();
                    listView1.Items[item.Index].Selected = true;
                    OBMSSearch.Text = item.SubItems[0].Text;
                    OldNumSearch.Text = item.SubItems[1].Text;
                    label1.Text = "";
                }
                else
                {
                    OldNumSearch.Text = "";
                    label1.Text = "Not Found: ";
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("SearchForOBMS failed: " + ex.StackTrace);
            }
        }

        public void SearchForPart()
        {
            try
            {
                string partNum = OldNumSearch.Text;
               
                ListViewItem item = listView1.FindItemWithText(partNum, true, 0, false);

                if (item != null)
                {
                    listView1.Items[item.Index].EnsureVisible();
                    listView1.Items[item.Index].Selected = true;
                    OBMSSearch.Text = item.SubItems[0].Text;
                    OldNumSearch.Text = item.SubItems[1].Text;
                    label1.Text = "";
                }
                else
                {
                    OBMSSearch.Text = "";
                    label1.Text = "Not Found: ";
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("SearchForPart failed: " + ex.StackTrace);
            }
        }

        public void FillListView()
        {
            try
            {
                GetXLFileList gxl = new GetXLFileList();
                List<string> strings = gxl.ListXLFile();
               
                string str;
                int indx;

                listView1.BeginUpdate();
                listView1.Items.Clear();

                for (int x = 0; x < strings.Count; x++)
                {
                    ListViewItem item = new ListViewItem();
                    str = strings[x];                   
                    item.Text = str.Substring(0, 7);
                    str = str.Substring(8);
                    indx = str.IndexOf(" ", 0);
                    item.SubItems.Add(str.Substring(0, indx));
                    str = str.Substring(indx);
                    item.SubItems.Add(str);

                    listView1.Items.Add(item);
                }

                listView1.EndUpdate();
                listView1.Refresh();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("FillListView failed: " + ex.StackTrace);
            }
        }

        private void OldNumSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SearchForPart();
            }
        }

        private void OBMSSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SearchForOBMS();
            }
        }

    }
}

 




Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert from .dll to .exe
« Reply #1 on: January 26, 2010, 03:43:38 PM »

Yep,
Just build a new WindowsFormsApplication Project
Copy the Form.cs and Form.Designer.cs to the Project Folder
Add them to the Project in the Solution Explorer
Check the References
Compile.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

BillZndl

  • Guest
Re: Convert from .dll to .exe
« Reply #2 on: January 26, 2010, 04:35:00 PM »
Worked great!

Thank you Kerry!






Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert from .dll to .exe
« Reply #3 on: January 26, 2010, 11:10:18 PM »

Glad I could be of help Bill.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.