Monday 13 January 2014

c# eventlog calendar defaultbutton formclose mdicontainer



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Form2 frm = new Form2();
            frm.MdiParent = this;
            frm.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           /* string s = "";
            IPAddress[] addresslist = Dns.GetHostEntry(Dns.GetHostName()).AddressList;

            for (int i = 0; i < addresslist.Length; i++)
            {
                s += addresslist[i].ToString() + "\n";
            }

            richTextBox1.Text = s;*/

            /* if (SystemInformation.Network)
            {
                MessageBox.Show("connected");
            }
            else
            {
                MessageBox.Show("disconnected");
            }*/

           /* this.AcceptButton = button1;
            this.CancelButton = button1;*/


        }

        private void button1_Click(object sender, EventArgs e)
        {
          /*  this.eventLog1.Log = "Application"; //System, Security, 
            EventLogEntryCollection collection = eventLog1.Entries;
            int count = collection.Count;
            string info = "#" + count.ToString() + " events";
            foreach (EventLogEntry entry in collection)
            {
                info += "\n type: " + entry.EntryType.ToString();
                info += "\n date: " + entry.TimeGenerated.ToLongDateString();
                info += "\n time: " + entry.TimeGenerated.ToLongTimeString();
                info += "\n source: " + entry.Source;
                info += "\n event: " + entry.InstanceId.ToString();
                info += "\n user: " + entry.UserName;
                info += "\n computer: " + entry.MachineName;
            }
            this.richTextBox1.Text = info;*/

          /* if (!EventLog.SourceExists(textBox1.Text))
            {
                EventLog.CreateEventSource(textBox3.Text, textBox1.Text);
            }
            
            EventLog log = new EventLog();
            log.WriteEntry(textBox2.Text);*/

            myear = monthCalendar1.SelectionRange.Start.Year;
            mmonth = monthCalendar1.SelectionRange.Start.Month;
            mday = monthCalendar1.SelectionRange.Start.Day;           

            SystemTime t = new SystemTime();

            t.wYear = (ushort)myear;
            t.wMonth = (ushort)mmonth;

            textBox1.Text = t.wYear.ToString();
            textBox2.Text = t.wMonth.ToString();

            SetSystemTime(ref t);
          
        }

        private int myear, mday, mmonth;

        [DllImport("Kernel32.dll")]
        public static extern bool SetSystemTime(ref SystemTime sysTime);

        [DllImport("Kernel32.dll")]
        public static extern void GetSystemTime(ref SystemTime sysTime);

        [DllImport("Kernel32.dll")]
        public static extern bool SetLocalTime(ref SystemTime sysTime);

        [DllImport("Kernel32.dll")]
        public static extern void GetLocalTime(ref SystemTime sysTime);


        public struct SystemTime
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort wHour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMiliseconds;
        }  

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
           /* myear = e.Start.Year;
            mmonth = e.Start.Month;
            mday = e.Start.Day; */
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("close?", "inquiry", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}


No comments:

Post a Comment