Ejemplo n.º 1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            int y = e.Y;
            int x = e.X;

            int  index = 0;
            bool Link  = false;

            //this.Cursor =Cursors.Arrow;
            _ActiveElement = null;
            if (this._Rows != null)
            {
                foreach (FormatLabelRow r in this._Rows)
                {
                    if (y >= r.Top && y <= r.Top + r.Height)
                    {
                        foreach (FormatLabelWord w in r.Words)
                        {
                            if (y >= w.ScreenArea.Top && y <= w.ScreenArea.Bottom)
                            {
                                if (x >= w.ScreenArea.Left && x <= w.ScreenArea.Right)
                                {
                                    //MessageBox.Show (w.Text);
                                    if (w.Element.Link != null)
                                    {
                                        Link           = true;
                                        _ActiveElement = w.Element.Link;
                                        break;
                                    }
                                    //this.Cursor =Cursors.Hand;
                                }
                            }
                        }
                        break;
                    }
                    index++;
                }
            }
            if (Link)
            {
                this.Cursor = Cursors.Hand;
                this.Invalidate();
                OnClickLink(GetAttrib("href", _ActiveElement.Tag));
            }
            else
            {
                this.Cursor = Cursors.Arrow;
                this.Invalidate();
            }


            base.OnMouseUp(e);
        }
Ejemplo n.º 2
0
        private void ApplyFormat(FormatLabelElement[] Elements)
        {
            Stack bold        = new Stack();
            Stack italic      = new Stack();
            Stack underline   = new Stack();
            Stack forecolor   = new Stack();
            Stack backcolor   = new Stack();
            Stack fontsize    = new Stack();
            Stack fontname    = new Stack();
            Stack link        = new Stack();
            Stack effectcolor = new Stack();
            Stack effect      = new Stack();

            bold.Push(this.Font.Bold);
            italic.Push(this.Font.Italic);
            underline.Push(this.Font.Underline);
            forecolor.Push(this.ForeColor);
            backcolor.Push(Color.Transparent);
            fontsize.Push((int)(this.Font.Size * 1.3));
            fontname.Push(this.Font.Name);
            effect.Push(TextEffect.None);
            effectcolor.Push(Color.Black);
            link.Push(null);


            foreach (FormatLabelElement Element in Elements)
            {
                switch (Element.TagName)
                {
                case "b":
                {
                    bold.Push(true);
                    break;
                }

                case "a":
                {
                    //underline.Push (true);
                    //forecolor.Push (_l);
                    link.Push(Element);
                    break;
                }

                case "i":
                case "em":
                {
                    italic.Push(true);
                    break;
                }

                case "u":
                {
                    underline.Push(true);
                    break;
                }

                case "font":
                {
                    string _fontname    = GetAttrib("face", Element.Tag);
                    string _size        = GetAttrib("size", Element.Tag);
                    string _color       = GetAttrib("color", Element.Tag);
                    string _effectcolor = GetAttrib("effectcolor", Element.Tag);
                    string _effect      = GetAttrib("effect", Element.Tag);


                    if (_size == "")
                    {
                        fontsize.Push(fontsize.Peek());
                    }
                    else
                    {
                        fontsize.Push(int.Parse(_size));
                    }

                    if (_fontname == "")
                    {
                        fontname.Push(fontname.Peek());
                    }
                    else
                    {
                        fontname.Push(_fontname);
                    }

                    if (_color == "")
                    {
                        forecolor.Push(forecolor.Peek());
                    }
                    else
                    {
                        forecolor.Push(Color.FromName(_color));
                    }

                    if (_effectcolor == "")
                    {
                        effectcolor.Push(effectcolor.Peek());
                    }
                    else
                    {
                        effectcolor.Push(Color.FromName(_effectcolor));
                    }

                    if (_effect == "")
                    {
                        effect.Push(effect.Peek());
                    }
                    else
                    {
                        effect.Push(Enum.Parse(typeof(TextEffect), _effect, true));
                    }

                    break;
                }

                case "br":
                {
                    Element.NewLine = true;
                    break;
                }

                case "hr":
                {
                    Element.NewLine = true;
                    break;
                }

                case "h3":
                {
                    fontsize.Push((int)(this.Font.Size * 1.4));
                    bold.Push(true);
                    Element.NewLine = true;
                    break;
                }

                case "h4":
                {
                    fontsize.Push((int)(this.Font.Size * 1.2));
                    bold.Push(true);
                    Element.NewLine = true;
                    break;
                }

                case "/b":
                {
                    bold.Pop();
                    break;
                }

                case "/a":
                {
                    //underline.Pop ();
                    //forecolor.Pop ();
                    link.Pop();
                    break;
                }

                case "/i":
                case "/em":
                {
                    italic.Pop();
                    break;
                }

                case "/u":
                {
                    underline.Pop();
                    break;
                }

                case "/font":
                {
                    fontname.Pop();
                    fontsize.Pop();
                    forecolor.Pop();
                    effect.Pop();
                    effectcolor.Pop();
                    break;
                }

                case "/h3":
                {
                    fontsize.Pop();
                    bold.Pop();
                    Element.NewLine = true;
                    break;
                }

                case "/h4":
                {
                    fontsize.Pop();
                    bold.Pop();
                    Element.NewLine = true;
                    break;
                }

                default:
                {
                    break;
                }
                }


                //---------------------------------------------------------------------
                bool Bold                   = (bool)bold.Peek();
                bool Italic                 = (bool)italic.Peek();
                bool Underline              = (bool)underline.Peek();
                FormatLabelElement Link     = (FormatLabelElement)link.Peek();
                string             FontName = (string)fontname.Peek();
                int        FontSize         = (int)fontsize.Peek();
                Color      BackColor        = (Color)backcolor.Peek();
                Color      ForeColor        = (Color)forecolor.Peek();
                TextEffect Effect           = (TextEffect)effect.Peek();
                Color      EffectColor      = (Color)effectcolor.Peek();

                FontStyle fs = 0;
                if (Bold)
                {
                    fs |= FontStyle.Bold;
                }
                if (Italic)
                {
                    fs |= FontStyle.Italic;
                }
                if (Underline)
                {
                    fs |= FontStyle.Underline;
                }

                Font font = new Font(FontName, FontSize, fs);
                Element.Font        = font;
                Element.BackColor   = BackColor;
                Element.ForeColor   = ForeColor;
                Element.Link        = Link;
                Element.Effect      = Effect;
                Element.EffectColor = EffectColor;
            }
        }
Ejemplo n.º 3
0
        private FormatLabelElement[] CreateElements()
        {
            string text = this.Text.Replace("\n", "");

            text = text.Replace("\r", "");
            string[]  parts    = text.Split('<');
            ArrayList Elements = new ArrayList();
            int       i        = 0;

            foreach (string part in parts)
            {
                FormatLabelElement cmd = new FormatLabelElement();

                if (i == 0)
                {
                    cmd.Text = part;
                }
                else
                {
                    string[] TagTextPair = part.Split('>');
                    cmd.Tag = TagTextPair[0].ToLower();
                    if (cmd.Tag.IndexOfAny(" \t".ToCharArray()) >= 0)
                    {
                        int    ws = cmd.Tag.IndexOfAny(" \t".ToCharArray());
                        string s1 = TagTextPair[0].Substring(0, ws).ToLower();
                        string s2 = TagTextPair[0].Substring(ws + 1);
                        cmd.Tag = s1 + " " + s2;
                    }


                    cmd.Text = TagTextPair[1];


                    if (cmd.TagName == "img")
                    {
                        FormatLabelElement img = new FormatLabelElement();
                        img.Tag = cmd.Tag;
                        Elements.Add(img);
                        cmd.Tag = "";
                        //	Elements.Add (cmd);
                    }
//
//					if (cmd.TagName == "hr")
//					{
//						Element hr=new Element();
//						hr.Tag = cmd.Tag;
//						Elements.Add (hr);
//						cmd.Tag ="";
//						cmd.Text ="a";
//						//	Elements.Add (cmd);
//					}

                    cmd.Text = cmd.Text.Replace("\t", "     ");
                    cmd.Text = cmd.Text.Replace("&#145;", "'");
                    cmd.Text = cmd.Text.Replace("&#146;", "'");


                    cmd.Text = cmd.Text.Replace(" ", ((char)1).ToString());
                    cmd.Text = HttpUtility.HtmlDecode(cmd.Text);
                    //	cmd.Text =cmd.Text.Replace (" ","*");
                    cmd.Text = cmd.Text.Replace(((char)1).ToString(), " ");
                }


                Elements.Add(cmd);
                i++;
            }

            FormatLabelElement[] res = new FormatLabelElement[Elements.Count];
            Elements.CopyTo(res);
            return(res);
        }