Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

VS C# Housekeeping

I was just cleaning up some class libraries I have developed for an external application and I realized it would nice if when the application fires up any of the class libraries if there was a hot key I could set to tell me which class library has fired and perhaps where in the class library the current code is running. Most these libraries has multiple sections and once you put the code down for a few months it is tough to remember where you were for each section. What is best practice for identifying which code is running but also where in the code you are?
Avatar of kaufmed
kaufmed
Flag of United States of America image

Are you essentially trying to remove "dead code" (i.e. code that is never used)?
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwheeler23

ASKER

No, in my case there have been several class libraries created for the external applications. Many of the screens look very similar. Aside from putting text on the form I would prefer to embed a hot key or some other mechanism so I can get a message saying "This code is in ths.dll" when the hot key is hit.  This would aid in pinpointing which set of source code needs to be examined.

Example: program1.dll, program2.dll, program3.dll
Suppose the form I am currently viewing on the screen is located in program2.dll
I hit the hot key and a messagebox appears saying "You are in Program2".

In others words, can I create a hotkey that will executed within a class library regradless of where in the class library the user currently resides?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In my first attempt at this, I added a key_down event to fire when CTRL-W is pressed. Unfortunately when I press and hold CTRL-W the message box does not appear. I want this key down event to be associated with the form.  What am I missing here?
 
public partial class frmBOAImportMainForm : DexUIForm
    {
        // Set references to the GL Account Screen and to the Vendor Screen and the transaction integration screens
        static frmGLAccounts GLAccountsForm;
        static frmVendors VendorsForm;
        static frmIntegratePayables IntegratePayables;
        [DllImport("user32.dll")]
        private static extern short GetAsyncKeyState(Keys vKey);

        public frmBOAImportMainForm()
        {
            InitializeComponent();
            this.KeyDown += new KeyEventHandler(frmBOAImportMainForm_KeyDown);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
        }

        private void btnGLAccounts_Click(object sender, EventArgs e)
        {
            if (GLAccountsForm == null || GLAccountsForm.Created == false)
            {
                GLAccountsForm = new frmGLAccounts();
            }

            GLAccountsForm.Show();
            GLAccountsForm.Activate();
            GLAccountsForm.Focus();
        }

        private void btnVendors_Click(object sender, EventArgs e)
        {
            if (VendorsForm == null || VendorsForm.Created == false)
            {
                VendorsForm = new frmVendors();
            }

            VendorsForm.Show();
            VendorsForm.Activate();
            VendorsForm.Focus();
        }

        private void btnIntegrate_Click(object sender, EventArgs e)
        {
            if (IntegratePayables == null || IntegratePayables.Created == false)
            {
                IntegratePayables = new frmIntegratePayables();
            }

            IntegratePayables.Show();
            IntegratePayables.Activate();
            IntegratePayables.Focus();
        }

        private void frmBOAImportMainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && KeyIsDown(Keys.W))
            {
                Console.WriteLine("Ctrl+W");
                MessageBox.Show("Here I am lost again!");
            }
        }
        private bool KeyIsDown(Keys key)
        {
            return (GetAsyncKeyState(key) < 0);
        }