昔、デスクトップに検索ボックスを表示するアプリがあった気がして、同じようなものを作りはじめてみたが、どうも使わなそうなので中止。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
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; namespace 検索ボックス { public partial class Form1 : Form { private Point mouse_point; public Form1() { InitializeComponent(); load_xml(); NotifyIcon ic = new NotifyIcon(); ic.Visible = true; ic.Icon = Icon; ic.MouseDoubleClick += new MouseEventHandler((object sender, MouseEventArgs e) => { this.Close(); }); this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.TransparencyKey = this.BackColor; this.comboBox1.AutoCompleteMode = AutoCompleteMode.Append; this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; this.comboBox1.MouseDown += new MouseEventHandler((object sender, MouseEventArgs e)=> { if(e.Button == MouseButtons.Left) { mouse_point = new Point(e.X, e.Y); } }); this.comboBox1.MouseMove += new MouseEventHandler((object sender, MouseEventArgs e)=> { if(e.Button == MouseButtons.Left) { this.Left += e.X - mouse_point.X; this.Top += e.Y - mouse_point.Y; } }); this.comboBox1.KeyDown += new KeyEventHandler((object sender, KeyEventArgs e) => { if(e.KeyCode == Keys.Enter) { string tmp = Uri.EscapeDataString(comboBox1.Text); System.Diagnostics.Process.Start(@"https://www.google.co.jp/search?q=" + tmp); comboBox1.Items.Add(comboBox1.Text); save_xml(); } }); } private void load_xml() { if (!System.IO.File.Exists(Application.StartupPath + @"\dat.xml")) return; System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(string[])); System.IO.StreamReader sr = new System.IO.StreamReader(Application.StartupPath + @"\dat.xml", new UTF8Encoding(false)); string[] items = (string[])xs.Deserialize(sr); comboBox1.Items.AddRange(items); sr.Close(); } private void save_xml() { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(string[])); System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\dat.xml", false, new UTF8Encoding(false)); List<string> items = comboBox1.Items.Cast<string>().ToList(); xs.Serialize(sw, items.ToArray()); sw.Close(); } } } |