예제 #1
0
 /// <summary>
 /// 构建提示框
 /// </summary>
 public void Build()
 {
     if (!MatchUtils.IsEmpty(this.tips) && !MatchUtils.IsEmpty(this.tips.Target) && !MatchUtils.IsEmpty(this.tips.Target.Netmap) && this.tips.Target.Enable && this.tips.Enable)
     {
         // 提示光标
         this.Cursor = this.tips.Mouse;
         {
             // 提示标题
             this.TipsTitle.Content = this.tips.Title;
             // 提示透明
             this.tips.Facade.Opacity = this.tips.Alpha / 100.0;
             // 提示色彩
             this.TipsTitle.Foreground = new SolidColorBrush(this.tips.Color);
             // 提示字体
             if (MatchUtils.IsEmpty(this.tips.Fonts))
             {
                 this.TipsTitle.FontSize   = 14;
                 this.TipsTitle.FontStyle  = FontStyles.Normal;
                 this.TipsTitle.FontWeight = FontWeights.Bold;
             }
             else
             {
                 this.TipsTitle.FontSize   = this.tips.Fonts.Size;
                 this.TipsTitle.FontStyle  = this.tips.Fonts.Ital ? FontStyles.Italic : FontStyles.Normal;
                 this.TipsTitle.FontWeight = this.tips.Fonts.Bold ? FontWeights.Bold : FontWeights.Normal;
             }
             // 提示内容
             this.TipsBody.Children.Clear();
             {
                 FrameworkElement component = new FrameworkElement();
                 if (!MatchUtils.IsEmpty(this.tips.Quote))
                 {
                     if (this.tips.Quote is String)
                     {
                         string ctx = this.tips.Quote as String;
                         if (MatchUtils.IsUrl(ctx))
                         {
                             // 添加浏览器控件
                             WebBrowser webBrowser = new WebBrowser();
                             try
                             {
                                 webBrowser.Source = new Uri(ctx, UriKind.RelativeOrAbsolute);
                             }
                             catch
                             {
                                 webBrowser = null;
                             }
                             finally
                             {
                                 if (webBrowser != null)
                                 {
                                     component = webBrowser;
                                 }
                             }
                         }
                         else
                         {
                             // 添加文本内容
                             TextBox textBox = new TextBox();
                             try
                             {
                                 textBox.Text                   = ctx;
                                 textBox.FontSize               = 12;
                                 textBox.IsReadOnly             = true;
                                 textBox.IsHitTestVisible       = false;
                                 textBox.IsReadOnlyCaretVisible = false;
                                 textBox.FontStyle              = FontStyles.Normal;
                                 textBox.FontWeight             = FontWeights.Normal;
                                 textBox.TextWrapping           = TextWrapping.Wrap;
                                 textBox.FontFamily             = new FontFamily("SimSun");
                                 textBox.BorderThickness        = (
                                     textBox.Padding = new Thickness(0, 0, 0, 0)
                                     );
                                 textBox.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                                 textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                             }
                             catch
                             {
                                 textBox = null;
                             }
                             finally
                             {
                                 if (textBox != null)
                                 {
                                     component = textBox;
                                 }
                             }
                         }
                     }
                     else
                     {
                         if (this.tips.Quote is FrameworkElement)
                         {
                             // 初始控件绑定
                             DependencyObject depend = (this.tips.Quote as FrameworkElement).Parent;
                             if (!MatchUtils.IsEmpty(depend))
                             {
                                 depend.SetValue(ContentProperty, null);
                                 {
                                     depend = null;
                                 }
                             }
                             // 添加控件内容
                             ScrollViewer scrollViewer = new ScrollViewer();
                             {
                                 scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                                 scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                             }
                             try
                             {
                                 scrollViewer.Content = this.tips.Quote as FrameworkElement;
                             }
                             catch
                             {
                                 scrollViewer = null;
                             }
                             finally
                             {
                                 if (scrollViewer != null)
                                 {
                                     component = scrollViewer;
                                 }
                             }
                         }
                     }
                 }
                 // 设置尺寸
                 {
                     if (MatchUtils.IsEmpty(this.tips.Gauge))
                     {
                         component.Width  = 135.0;
                         component.Height = 35.0;
                     }
                     else
                     {
                         component.Width  = this.tips.Gauge.W;
                         component.Height = this.tips.Gauge.H;
                     }
                     component.Margin = new Thickness(8, 5, 8, 5);
                 }
                 this.TipsBody.Children.Add(component);
             }
         }
         // 强制绘制
         this.Adjust();
     }
 }