Tuesday, 15 July 2014

How to hide Close (x) button for Windows Forms?


Method 1
 
this.ControlBox=false;


Method 2

private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
    get
    {
       CreateParams myCp = base.CreateParams;
       myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
       return myCp;
    }
}

Tuesday, 1 April 2014

Configure Internet Explorer to open Ms Office (Word,Excel,Power Point Etc)documents

Method 1



Open My Computer and On the Tools menu click Folder Options.







Click the File Types tab.In the Registered file types list, click the specific Office document type (for example, Excel), and then click Advanced .









In the Edit File Type dialog box, click  the Browse in same window check box .and click clear other check box


Click OK 2 times.


private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.Navigate(@"C:\sample.xls");
}

Friday, 21 March 2014

textbox password Rebuild

if (cshowPassword.Checked != true)
{
      txtPassword.PasswordChar = '*';
}
else
{
     txtPassword.PasswordChar = char.Parse("\0");
}

Thursday, 20 March 2014

Unexpected Error creating debug information file ***.PDB



Answers (This worked for me:)
  1. Shut down VS.NET
  2. Browse to the project in Windows Explorer   
  3. Delete the /obj/ folder.
  4. Delete the project outputs (.dll and .pdb) from /bin (not sure if this step is necessary)
  5. Can't hurt but might help: delete the project outputs from any other project /bin folders in the solution that is having issues (wasn't necessary for me)
  6. Restart VS.NET
  7. Rebuild
       
       
       
       
      

Tuesday, 26 November 2013

Run a program automatically when Windows starts short cut display 'Windows startup' and add 'system tray'


 







using IWshRuntimeLibrary;
using Microsoft.Win32;
using System.IO;


namespace Sample
{
        public partial class Form1 : Form
        {
                    RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows \\CurrentVersion\\Run", true) // check windows is run     
                    private NotifyIcon tryIcon; //add icon in 'System Tray'
                   private ContextMenu trayMenu;  // create menu
            
               public Form1()
             {
                      // if windows is run my app (setup1) is run
                      reg.SetValue("MyApp", Application.ExecutablePath);
                      MessageBox.Show("Test");
           

                       //create Menu Item
                       trayMenu = new ContextMenu ();

            //Menu Item (Show, Hide, Exit) ==> menu Function (OnShow, OnHide, OnExit) in #region System Tray Menu
            trayMenu.MenuItems.Add("Show", OnShow);
            trayMenu.MenuItems.Add("Hide", OnHide);
            trayMenu.MenuItems.Add("Exit", OnExit);

            // Display icon in "System Tray" (refer image first) 

            tryIcon = new NotifyIcon(); // set Systen tray icon
            tryIcon.Text = "Setup1"; // set system tray text
            // how to add resources  -> click 'Properties' -> open the 'Resources.resx' -> change to string to icon  -> click 'Add Resource' - select 'Add Existing file' and select icon
            tryIcon.Icon = Properties.Resources.ftprush_install; // add icon in 'System Tray'
           tryIcon.ContextMenu = trayMenu; // add menu at "System try"
            tryIcon.Visible = true; // Icon visible true
           
            InitializeComponent();
        }
        void CreateStartupShortcut()  // Display "Windows Startup" (refer image 2)
        {           
            string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            WshShell shell = new WshShell();
            string shortcutAddress = startupFolder + @"\MYApp.lnk";
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer,   LaunchOnStartup.exe will not launch on Windows Startup"; // set the description of the shortcut
            shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
            shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
            // optionally, you can set the arguments in shortcut.Arguments
            // For example, shortcut.Arguments = "/a 1";

            shortcut.Save();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Opacity = 0; // form not display (this is hide)
            this.ShowInTaskbar = false; // display hide in Task bar
            //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; // in       Design mode:
        }

        #region System Tray Menu
        private void OnExit(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void OnShow(object sender, EventArgs e)
        {
            this.Opacity =1;  // form  display (this is show)
            this.ShowInTaskbar = true // display  in Task bar           
        }

        private void OnHide(object sender, EventArgs e)
        {
            this.Opacity = 0;  // form not display (this is hide)
            this.ShowInTaskbar = false// display hide in Task bar
        }
        #endregion System Tray Menu

         }
}

Download  Sample Coding (LaunchOnStartUp.rar)

Download  Interop.IWshRuntimeLibrary.dll

Wednesday, 20 November 2013

How to get Listview subitems index

if (listview1.SelectedItems.Count > 0)
{
                int icolcount = 0; string  sID = "";
                foreach (ColumnHeader header in listview1.Columns)
                {  
                    if (header.Text.ToLower().Trim() == "id")
                    {
                        sID= listview1.SelectedItems[0].SubItems[icolcount].Text;
                        break;
                    }
                    icolcount ++;
                }
}