Showing posts with label window. Show all posts
Showing posts with label window. Show all posts

Monday, 2 December 2013

HOw to Add break-point when Debug Window Service in C#.net

Service1.cs file code:

Timer timer;
        public Service1()
        {
            InitializeComponent();
        }

        public void OnDebug()
        {
            OnStart(null);
        }

        protected override void OnStart(string[] args)
        {
            // get today's date at 00:01 AM  
            DateTime time = DateTime.Today.AddMinutes(1);

            // if 00:01 AM has passed, get tomorrow at 00:01 AM  
            if (DateTime.Now > time)
                time = time.AddDays(1);

            // calculate milliseconds until the next 00:01 AM.  
            int timeToFirstExecution = (int)time.Subtract(DateTime.Now).TotalMilliseconds;

            // calculate the number of milliseconds in 24 hours.   
            int timeBetweenCalls = (int)new TimeSpan(24, 0, 0).TotalMilliseconds;

            // set the method to execute when the timer executes.   
            TimerCallback methodToExecute = Brijeshmethod;

            // start the timer.  The timer will execute "Brijeshmethod" when the number of seconds between now and   
            // the next 00:01 AM elapse.  After that, it will execute every 24 hours.   
            timer = new System.Threading.Timer(methodToExecute, null, timeToFirstExecution, timeBetweenCalls);
  
        }

        private void Brijeshmethod(object source)
        {
            //write your code here
        }

        protected override void OnStop()
        {
            Thread.Sleep(Timeout.Infinite);

        }



Program file:

/// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            #if DEBUG
            Service1 myService = new Service1();
            myService.OnDebug();
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            #else
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
            #endif


        }

Wednesday, 23 October 2013

Open New Window as Popup with defined size on Button Click using C#

Use this Code on button click event:

ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'popup.aspx', null, 'height=500,width=560,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);

Saturday, 3 August 2013

Find window forms attached by MDI Parent in C#

Try this code to close perticular open form or all open form.......

foreach (Form form in Application.OpenForms)
                            {
                                if (form.Name == "Login")
                                {
                                    form.Close();
                                }
                             // /* to close all open form */
                             //  form .Close();
                            }

Friday, 19 July 2013

Prevent Window form to Open when Same form Open Already

Try this code on Window(Form) Open Events it will close open form and open new form/window........

var form1 = new Formname();
                var openedForm = Application.OpenForms[form1.Name];
                if (openedForm != null)
                {
                    openedForm.WindowState = FormWindowState.Normal;
                    openedForm.BringToFront();
                    openedForm.Activate();
                }
                else
                {
                    // If required.
                    form1.MdiParent = this;
                    form1.Show();
                }