// project created on 2004/04/18 at 23:04 using System; using System.Windows.Forms; // //以下の名前空間を追加 // using System.Xml.Serialization; using System.IO; using System.Diagnostics; namespace MyFormProject { // //フォーム情報を格納するXMLファイル用構造体 // public class XmlInfo { public int position_x; public int position_y; public bool titlebar_flag; } class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.MenuItem menuItemClose; private System.Windows.Forms.MonthCalendar monthCalendar; private System.Windows.Forms.MenuItem menuItemToday; private System.Windows.Forms.MenuItem menuItemBar; private System.Windows.Forms.ContextMenu contextMenu; public MainForm() { InitializeComponent(); } // THIS METHOD IS MAINTAINED BY THE FORM DESIGNER // DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm)); this.contextMenu = new System.Windows.Forms.ContextMenu(); this.menuItemBar = new System.Windows.Forms.MenuItem(); this.menuItemToday = new System.Windows.Forms.MenuItem(); this.monthCalendar = new System.Windows.Forms.MonthCalendar(); this.menuItemClose = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // contextMenu // this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItemBar, this.menuItemToday, this.menuItemClose}); // // menuItemBar // this.menuItemBar.Checked = true; this.menuItemBar.Index = 0; this.menuItemBar.Text = "タイトルバーを表示"; this.menuItemBar.Click += new System.EventHandler(this.MenuItemBarClick); // // menuItemToday // this.menuItemToday.Index = 1; this.menuItemToday.Text = "今日へ移動"; this.menuItemToday.Click += new System.EventHandler(this.MenuItemTodayClick); // // monthCalendar // this.monthCalendar.ContextMenu = this.contextMenu; this.monthCalendar.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.monthCalendar.Location = new System.Drawing.Point(0, 0); this.monthCalendar.Name = "monthCalendar"; this.monthCalendar.TabIndex = 0; // // menuItemClose // this.menuItemClose.Index = 2; this.menuItemClose.Text = "終了"; this.menuItemClose.Click += new System.EventHandler(this.MenuItemCloseClick); // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 12); this.ClientSize = new System.Drawing.Size(168, 151); this.ContextMenu = this.contextMenu; this.Controls.Add(this.monthCalendar); this.Font = new System.Drawing.Font("MS ゴシック", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "MainForm"; this.Text = "Calendar"; this.Load += new System.EventHandler(this.MainFormLoad); this.Closed += new System.EventHandler(this.MainFormClosed); this.ResumeLayout(false); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } // //メインフォームがロードされたときの処理 // void MainFormLoad(object sender, System.EventArgs e) { //二重起動をチェックする if(Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { Application.Exit(); } //フォームの位置・タイトルバー表示/非表示情報をXMLファイルから読み込む if(File.Exists("config.xml") == true) { using(FileStream fs = new FileStream("config.xml", FileMode.Open)) { try { XmlSerializer serializer = new XmlSerializer(typeof(XmlInfo)); XmlInfo xmlinfo = (XmlInfo)serializer.Deserialize(fs); //読み込んだ情報を設定する this.Location = new System.Drawing.Point(xmlinfo.position_x, xmlinfo.position_y); if(xmlinfo.titlebar_flag == false) { menuItemBar.Checked = false; this.FormBorderStyle = FormBorderStyle.None; } } catch { //逆シリアライズで例外が発生したらここに飛ぶ } } } //フォームの大きさをカレンダに合わせる this.ClientSize = monthCalendar.Size; } // //メインフォームがクローズされたときの処理 // void MainFormClosed(object sender, System.EventArgs e) { //フォームの位置・タイトルバー表示/非表示情報を構造体にセットする XmlInfo xmlinfo = new XmlInfo(); xmlinfo.position_x = this.Location.X; xmlinfo.position_y = this.Location.Y; xmlinfo.titlebar_flag = menuItemBar.Checked; //セットした情報をXMLファイルに書き込む using(FileStream fs = new FileStream("config.xml", FileMode.Create)) { try { XmlSerializer serializer = new XmlSerializer(typeof(XmlInfo)); serializer.Serialize(fs, xmlinfo); } catch { //シリアライズで例外が発生したらここに飛ぶ } } } // //「タイトルバーを表示」メニューが選択されたときの処理 // void MenuItemBarClick(object sender, System.EventArgs e) { menuItemBar.Checked = !menuItemBar.Checked; if(menuItemBar.Checked == true) { this.FormBorderStyle = FormBorderStyle.FixedSingle; } else { this.FormBorderStyle = FormBorderStyle.None; } } // //「今日へ移動」メニューが選択されたときの処理 // void MenuItemTodayClick(object sender, System.EventArgs e) { monthCalendar.SetDate(System.DateTime.Today); } // //「終了」メニューが選択されたときの処理 // void MenuItemCloseClick(object sender, System.EventArgs e) { this.Close(); } } }