Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created October 8, 2013 14:43
Show Gist options
  • Save mohemohe/6885841 to your computer and use it in GitHub Desktop.
Save mohemohe/6885841 to your computer and use it in GitHub Desktop.
だって検索したいじゃん
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ImFeelingLucky
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Google_Click(object sender, RoutedEventArgs e)
{
DoSearch(1);
}
private void ImFeelingLucky_Click(object sender, RoutedEventArgs e)
{
DoSearch(2);
}
private void Yahoo_Click(object sender, RoutedEventArgs e)
{
DoSearch(3);
}
private void Bing_Click(object sender, RoutedEventArgs e)
{
DoSearch(4);
}
void DoSearch(int i)
{
string SearchText = Uri.EscapeUriString(SearchBox.Text);
switch (i)
{
case 1:
Process.Start("https://www.google.co.jp/search?q=" + SearchText);
break;
case 2:
Process.Start("https://www.google.co.jp/search?btnI=I%27m+Feeling+Lucky&q=" + SearchText);
break;
case 3:
Process.Start("http://search.yahoo.co.jp/search?p=" + SearchText);
break;
case 4:
Process.Start("http://www.bing.com/search?q=" + SearchText);
break;
}
SearchBox.Text = null;
}
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
DoSearch(2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment