private void add_firework_menu_Click(object sender, EventArgs e) { firework_page page = new firework_page(click_sound); firework_tab.TabPages.Add(page.firework_tab.SelectedTab); firework_tab.SelectedIndex = firework_tab.TabPages.Count - 1; firework_tab.SelectedTab.Text = "第" + firework_tab.TabPages.Count + "个"; CheckedListBox color_box = firework_tab.SelectedTab.Controls.Find("color_box", true)[0] as CheckedListBox; color_box.MouseDown += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; CurrentPos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); panel.Location = new Point(CurrentPos.X + this_obj.Location.X + 30, CurrentPos.Y); panel.Visible = true; }; color_box.MouseMove += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; if (color_box.SelectedIndex >= 0 && color_box.SelectedIndex <= (color_box.Items.Count - 1)) { CurrentPos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); panel.BackColor = ColorList[color_box.SelectedIndex]; panel.Location = new Point(CurrentPos.X + this_obj.Location.X + 30, CurrentPos.Y); panel.BringToFront(); } }; color_box.MouseUp += (a, b) => { panel.Visible = false; }; }
private void OnListMouseMove(object sender, MouseEventArgs e) { if (m_LastScreenMouseMove != Cursor.Position) { int itemHit = m_ListBox.IndexFromPoint(e.Location); if (itemHit != -1) { m_ListBox.SelectedIndex = itemHit; } m_LastScreenMouseMove = m_ListBox.PointToScreen(e.Location); } }
private void Add_sentence_title_menu_Click(object sender, EventArgs e) { sentence sen = new sentence(); TabControl sentence_tc = page_tab.SelectedTab.Controls.Find("sentence_page", true)[0] as TabControl; #region 动态显示文本效果 sen.font_property_box.MouseDown += (a, b) => { //更新预览文本 TextBox current_text_box = page_tab.SelectedTab.Controls.Find("sentence_content", true)[0] as TextBox; display_txt.Text = current_text_box.Text.Trim() == "" ? "Minecraft" : Regex.Match(current_text_box.Text, @"(.*)").ToString(); CheckedListBox this_obj = a as CheckedListBox; MousePos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); color_panel.Location = new Point(MousePos.X + this_obj.Location.X + 30, MousePos.Y + 30); color_panel.AutoSize = true; color_panel.Height = 30; if (display_txt.Parent != color_panel) { color_panel.Controls.Add(display_txt); } display_txt.Font = new Font(Font, FontStyle.Bold | FontStyle.Italic); color_panel.BringToFront(); color_panel.Visible = true; }; sen.font_property_box.MouseUp += (a, b) => { color_panel.Visible = false; }; sen.font_property_box.MouseMove += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; CheckedListBox color_box = this_obj.Parent.Controls.Find("font_color_box", true)[0] as CheckedListBox; MousePos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); color_panel.Location = new Point(MousePos.X + this_obj.Location.X + 30, MousePos.Y + 30); FontStyle display_style = FontStyle.Regular; foreach (string item in this_obj.CheckedItems) { if (item == "bold") { display_style |= FontStyle.Bold; } if (item == "italic") { display_style |= FontStyle.Italic; } if (item == "underlined") { display_style |= FontStyle.Underline; } if (item == "strikethrough") { display_style |= FontStyle.Strikeout; } } if (color_box.SelectedIndex >= 0 && color_box.SelectedIndex < (color_box.Items.Count - 1)) { display_txt.ForeColor = Colors[color_box.SelectedIndex]; } display_txt.Font = new Font(Font, display_style); color_panel.BackColor = Color.Empty; color_panel.BringToFront(); }; #endregion #region 动态显示颜色 sen.font_color_box.MouseMove += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; MousePos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); color_panel.Location = new Point(MousePos.X + this_obj.Location.X + 30, MousePos.Y); if (this_obj.SelectedIndex >= 0 && this_obj.SelectedIndex < this_obj.Items.Count) { color_panel.BackColor = Colors[this_obj.SelectedIndex]; } }; sen.font_color_box.MouseUp += (a, b) => { color_panel.Visible = false; }; sen.font_color_box.MouseDown += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; MousePos = this_obj.PointToClient(this_obj.PointToScreen(b.Location)); color_panel.Location = new Point(MousePos.X + this_obj.Location.X + 30, MousePos.Y); if (this_obj.SelectedIndex >= 0 && this_obj.SelectedIndex < this_obj.Items.Count) { color_panel.BackColor = Colors[this_obj.SelectedIndex]; } color_panel.Size = new Size(50, 50); color_panel.Visible = true; color_panel.BringToFront(); }; sen.font_color_box.SelectedIndexChanged += (a, b) => { CheckedListBox this_obj = a as CheckedListBox; color_panel.Controls.Clear(); this_obj.Parent.Parent.Controls.Add(color_panel); if (this_obj.SelectedIndex >= 0 && this_obj.SelectedIndex < this_obj.Items.Count) { color_panel.BackColor = Colors[this_obj.SelectedIndex]; } }; #endregion sentence_tc.TabPages.Add(sen.sentence_page.SelectedTab); sentence_tc.SelectedIndex++; sentence_tc.SelectedTab.Text = "第" + sentence_tc.TabPages.Count + "句"; }