private void onFormat_Hyperlink(object sender, RoutedEventArgs e) { TextPointer tp1 = this._textArea.Selection.Start; TextPointer tp2 = this._textArea.Selection.End; TextRange tr = new TextRange(tp1, tp2); //Run r = tr.Start.Parent as Run; //if (r.NextInline is Hyperlink) //{ // //MessageBox.Show("This is a link"); // TextPointer hrefStart = r.NextInline.ContentStart; // TextPointer hrefEnd = r.NextInline.ContentEnd; // TextRange hrefTr = new TextRange(hrefStart, hrefEnd); // FontFamily ffamily = (FontFamily)hrefTr.GetPropertyValue(TextElement.FontFamilyProperty); // double fsize = (double)hrefTr.GetPropertyValue(TextElement.FontSizeProperty); // Run deFormated = new Run(hrefTr.Text, hrefTr.Start); // return; //} //First we need to check if the user has selected a previously added Hyperlink. Windows.ReportUrlInputWindow uriIw = new Windows.ReportUrlInputWindow(tr.Text, ""); uriIw.Closing += delegate(object s, System.ComponentModel.CancelEventArgs e2) { if (uriIw.Cancelled == false) { if (tr.Text.Length != 0) { try { tr.Text = uriIw.Explanation; Hyperlink h = new Hyperlink(tp1, tp2); h.ToolTip = new Label() { Content = "コントロールボタン+クリックでリンク先を表示します" }; h.NavigateUri = new Uri(uriIw.Url); h.Foreground = Brushes.Blue; h.RequestNavigate += new RequestNavigateEventHandler(h_Click); } catch (Exception ex) { SiliconStudio.DebugManagers.DebugReporter.Report( SiliconStudio.DebugManagers.MessageType.Error, "EjpControls - Report Editor", "Failed to insert Hyperlink" + "\nReport ID: " + this._reportObject.Id.ToString() + "\nError: " + ex.Message); MessageBox.Show("リンクを作成する際に失敗しました。\nUrlを正しく入力したかどうかを確かめた上もう一度試してみてください。", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { try { Hyperlink h = new Hyperlink(new Run(uriIw.Explanation), this._textArea.CaretPosition); h.NavigateUri = new Uri(uriIw.Url); h.Foreground = Brushes.Blue; h.RequestNavigate += new RequestNavigateEventHandler(h_Click); } catch (Exception ex) { SiliconStudio.DebugManagers.DebugReporter.Report( SiliconStudio.DebugManagers.MessageType.Error, "EjpControls - Report Editor", "Failed to insert Hyperlink" + "\nReport ID: " + this._reportObject.Id.ToString() + "\nError: " + ex.Message); MessageBox.Show("リンクを作成する際に失敗しました。\nUrlを正しく入力したかどうかを確かめた上もう一度試してみてください。", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } tr.Select(tp1, tp2); } }; uriIw.ShowDialog(); }
private void onFormat_Hyperlink(object sender, RoutedEventArgs e) { TextPointer tp1 = this._textArea.Selection.Start; TextPointer tp2 = this._textArea.Selection.End; TextRange tr = new TextRange(tp1, tp2); //Run r = tr.Start.Parent as Run; //if (r.NextInline is Hyperlink) //{ // //MessageBox.Show("This is a link"); // TextPointer hrefStart = r.NextInline.ContentStart; // TextPointer hrefEnd = r.NextInline.ContentEnd; // TextRange hrefTr = new TextRange(hrefStart, hrefEnd); // FontFamily ffamily = (FontFamily)hrefTr.GetPropertyValue(TextElement.FontFamilyProperty); // double fsize = (double)hrefTr.GetPropertyValue(TextElement.FontSizeProperty); // Run deFormated = new Run(hrefTr.Text, hrefTr.Start); // return; //} //First we need to check if the user has selected a previously added Hyperlink. Windows.ReportUrlInputWindow uriIw = new Windows.ReportUrlInputWindow(tr.Text, ""); uriIw.Closing += delegate(object s, System.ComponentModel.CancelEventArgs e2) { if (uriIw.Cancelled == false) { if (tr.Text.Length != 0) { try { tr.Text = uriIw.Explanation; Hyperlink h = new Hyperlink(tp1, tp2); h.ToolTip = new Label() { Content = Application.Current.Resources["Str_ToolTip_ReportUrl"] as string }; h.NavigateUri = new Uri(uriIw.Url); h.Foreground = Brushes.Blue; h.RequestNavigate += new RequestNavigateEventHandler(h_Click); } catch (Exception) { MessageBox.Show(Application.Current.Resources["EX_ReportAddUrlFailed"] as string, Application.Current.Resources["Str_ErrorDlgTitle"] as string, MessageBoxButton.OK, MessageBoxImage.Error); } } else { try { Hyperlink h = new Hyperlink(new Run(uriIw.Explanation), this._textArea.CaretPosition); h.NavigateUri = new Uri(uriIw.Url); h.Foreground = Brushes.Blue; h.RequestNavigate += new RequestNavigateEventHandler(h_Click); } catch (Exception) { MessageBox.Show(Application.Current.Resources["EX_ReportAddUrlFailed"] as string, Application.Current.Resources["Str_ErrorDlgTitle"] as string, MessageBoxButton.OK, MessageBoxImage.Error); } } tr.Select(tp1, tp2); } }; uriIw.ShowDialog(); }