private void TweetTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && (e.Modifiers & Keys.Shift) == Keys.Shift) // Shift+Enterで送信 { if (TweetTextBox.Text != "") { try { string tweet = TweetTextBox.Text; // URL短縮を行う場合は、ツイート本文からURLを探して短縮する try { if (this.config.UseBitLy) { /* * 参考: http://d.hatena.ne.jp/seto-san/20090123/1232679235 */ Regex regex = new Regex(@"https?(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)"); Match m = regex.Match(tweet); if (m.Success) { string apiUrl = @"http://api.bit.ly/v3/shorten?login={0}&apiKey={1}&longUrl={2}&format=txt"; if (this.config.BitLyUseJmp) { apiUrl += @"&domain=j.mp"; } string url = string.Format(apiUrl, this.config.BitLyUserID, this.config.BitLyAPIKey, m.Value); string result = new WebClient().DownloadString(url); result = result.TrimEnd(); tweet = tweet.Replace(m.Value, result); } } } catch { // エラーが発生した場合は、URL短縮せずに通常通りステータス更新 } UpdateStatus(tweet); } catch { KumaHodaiToolStripStatusLabel.Text = "エラー: ステータスの更新に失敗しました。"; } finally { TweetTextBox.Text = ""; KumaHodaiToolStripStatusLabel.Text = ""; inReplyToStatusId = -1; TweetTextBox.Enabled = false; this.KeyPreview = true; } } e.SuppressKeyPress = true; TimelineListView.Focus(); // 注意: TextBoxからFocusを外しておかないと、beepが鳴ることがある } else if (e.KeyCode == Keys.Escape) { TweetTextBox.Text = ""; TweetTextBox.Enabled = false; KumaHodaiToolStripStatusLabel.Text = ""; inReplyToStatusId = -1; this.KeyPreview = true; e.SuppressKeyPress = true; TimelineListView.Focus(); // 注意: TextBoxからFocusを外しておかないと、beepが鳴ることがある } }