示例#1
0
        private void updateSuggestions()
        {
            if (suggestions.Count != 0)
            {
                lastSuggested = suggestions[suggIndex];
            }

            suggIndex = 0;
            suggestions.Clear();
            int      i         = 0;
            Graphics temp      = Graphics.FromHwndInternal(Handle);
            float    xPosition = 0;

            string[] recents = Recents.GetRecents();
            Array.Sort(programList, new comparer(text, recents));

            while (xPosition < ClientRectangle.Width * 0.9F && i < programList.Length)
            {
                string element = programList[i];
                if (element.ToLower().Contains(text.ToLower()))
                {
                    suggestions.Add(element);
                    xPosition += temp.MeasureString(element, Font).Width + 2;
                }
                i++;
            }

            temp.Dispose();

            Invalidate();
        }
示例#2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Close();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                if (suggestions.Count > 0 || text.StartsWith(lastSuggested,
                                                             StringComparison.OrdinalIgnoreCase))
                {
                    TcpClient clientSocket;
                    string    data;
                    string    name;
                    if (suggestions.Count > 0)
                    {
                        data = "run" + suggestions[suggIndex];
                        name = suggestions[suggIndex];
                    }
                    else
                    {
                        data = "run" + lastSuggested + "|" +
                               text.Substring(lastSuggested.Length + 1);
                        name = lastSuggested;
                    }
                    clientSocket = new TcpClient();

                    try { clientSocket.Connect(System.Net.IPAddress.Loopback, 12321); }
                    catch
                    {
                        MessageBox.Show("Server unreachable.");
                        return;
                    }

                    NetworkStream serverStream = clientSocket.GetStream();
                    byte[]        outStream    = Encoding.Unicode.GetBytes(data);
                    byte[]        messageSize  = new byte[] {
                        (byte)(outStream.Length / 256),
                        (byte)(outStream.Length % 256)
                    };

                    serverStream.Write(messageSize, 0, 2);
                    serverStream.Write(outStream, 0, outStream.Length);

                    clientSocket.Close();

                    Recents.MakeMostRecent(name);
                }
                Close();
            }
            else if (e.KeyCode == Keys.Back)
            {
                if (text.Length == 0)
                {
                    return;
                }
                text = text.Substring(0, text.Length - 1);
                updateSuggestions();
            }
            else if (e.KeyCode == Keys.Left)
            {
                if (suggIndex > 0)
                {
                    suggIndex--;
                    Invalidate();
                }
            }
            else if (e.KeyCode == Keys.Right)
            {
                if (suggIndex < suggestions.Count - 1)
                {
                    suggIndex++;
                    Invalidate();
                }
            }
            else if (e.KeyCode == Keys.Tab)
            {
                text = suggestions[suggIndex];
                updateSuggestions();
            }
            else
            {
                string input = KeyboardConverter.KeyCodeToUnicode(e.KeyCode);
                if (input != "")
                {
                    text += input;
                    updateSuggestions();
                }
            }
        }