This repository has been archived on 2022-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
bookmark-manager/FindForm.cs
2020-08-28 23:25:49 +01:00

96 lines
2.3 KiB
C#

using System;
using System.Windows.Forms;
namespace bzit.bomg
{
public partial class FindForm : Form
{
private MainForm parentForm = null;
private bool findNextNew = false;
public FindForm(MainForm form)
{
InitializeComponent();
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
parentForm = form;
}
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
if (findNextNew)
{
button2_Click(sender, null);
}
else
{
button1_Click(sender, null);
}
break;
case Keys.Escape:
this.Close();
break;
default: break;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (parentForm == null)
{
return;
}
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
return;
}
if (parentForm.treeView1.Nodes.Count <= 0)
{
return;
}
findNextNew = false;
parentForm.treeView1.FindTextNode(parentForm.treeView1.Nodes[0], textBox1.Text?.Trim());
}
private void button2_Click(object sender, EventArgs e)
{
if (parentForm == null)
{
return;
}
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
return;
}
if (parentForm.treeView1.Nodes.Count <= 0)
{
return;
}
if (parentForm.treeView1.SelectedNode == null)
{
parentForm.treeView1.SelectedNode = parentForm.treeView1.Nodes[0];
}
findNextNew = false;
bool rv = parentForm.treeView1.SNode.FindTextNode(textBox1.Text?.Trim());
if (!rv)
{
findNextNew = true;
}
}
}
}