private void 今の位置を保存ToolStripMenuItem_Click(object sender, EventArgs e) { var inputForm = new InputSaveSliderName(); if (inputForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel || string.IsNullOrEmpty(inputForm.InputText) == true) { return; } var setting = new SliderLocationSetting(); setting.Key = inputForm.InputText + DateTime.Now.Ticks; setting.Text = inputForm.InputText; slider_Horizontally.GetSliderLocation(out setting.HorizontallyStart, out setting.HorizontallyEnd); slider_Vertically.GetSliderLocation(out setting.VerticallyStart, out setting.VerticallyEnd); AddSliderSettingContextMenu(setting); }
private void AddSliderSettingContextMenu(SliderLocationSetting setting) { DataHouse.SliderLocation.Add(setting.Key, setting); var newItem = new ToolStripMenuItem(); newItem.Text = string.Format("{0}({1:HH:mm})", setting.Text, DateTime.Now); newItem.Tag = setting.Key; var 復元 = new ToolStripMenuItem() { Text = "復元", Tag = setting.Key }; 復元.Click += (s, ea) => { var key = (s as ToolStripMenuItem).Tag as string; var csetting = DataHouse.SliderLocation[key]; slider_Horizontally.SetSliderLocation(csetting.HorizontallyStart.ToPoint(), csetting.HorizontallyEnd.ToPoint()); slider_Vertically.SetSliderLocation(csetting.VerticallyStart.ToPoint(), csetting.VerticallyEnd.ToPoint()); }; var 書き = new ToolStripMenuItem() { Text = "ここに上書き", Tag = setting.Key }; 書き.Click += (s, ea) => { var key = (s as ToolStripMenuItem).Tag as string; var setting2 = new SliderLocationSetting(); slider_Horizontally.GetSliderLocation(out setting2.HorizontallyStart, out setting2.HorizontallyEnd); slider_Vertically.GetSliderLocation(out setting2.VerticallyStart, out setting2.VerticallyEnd); DataHouse.SliderLocation[key] = setting2; }; var 削除 = new ToolStripMenuItem() { Text = "削除", Tag = setting.Key }; 削除.Click += (s, ea) => { var key = (s as ToolStripMenuItem).Tag as string; var count = slider_contextMenuStrip.Items.Count; for (int index = 0; index < count; index++) { var item = slider_contextMenuStrip.Items[index] as ToolStripMenuItem; if ((item.Tag is string) && (item.Tag as string) == key) { DataHouse.SliderLocation.Remove(key); slider_contextMenuStrip.Items.RemoveAt(index); break; } } }; newItem.DropDownItems.AddRange(new ToolStripItem[] { 復元, 書き, new ToolStripSeparator(), 削除 }); slider_contextMenuStrip.Items.Insert(slider_contextMenuStrip.Items.Count - 2, newItem); }