private void CreateWords(Element[] Elements)
        {
            var bbuff = new GDISurface(1, 1, this, false);

            _HasImageError = false;
            foreach (Element Element in Elements)
            {
                if (Element.TagName == "img")
                {
                    Element.words = new Word[1];

                    Element.words[0] = new Word();

                    Image img = null;

                    try
                    {
                        string SRC = GetAttrib("img", Element.Tag).ToLowerInvariant();
                        if (IsIndex(SRC))
                        {
                            int index = int.Parse(SRC);
                            img = ImageList.Images[index];
                        }
                        else if (SRC.StartsWith("http://")) //from url
                        {}
                        else if (SRC.StartsWith("file://")) // from file
                        {
                            img = Image.FromFile(SRC.Substring(7));
                        }
                        else //from file
                        {
                            img = Image.FromFile(SRC);
                        }
                    }
                    catch
                    {
                        img = new Bitmap(20, 20);
                        _HasImageError = true;
                    }

                    Element.words[0].Image = img;


                    Element.words[0].Element = Element;


                    if (img != null)
                    {
                        Element.words[0].Height = img.Height;
                        Element.words[0].Width = img.Width;
                        Element.words[0].ScreenArea.Width = img.Width;
                        Element.words[0].ScreenArea.Height = img.Height;
                    }
                }
                else
                {
                    string[] words = Element.Text.Split(' ');
                    Element.words = new Word[words.Length];
                    int i = 0;
                    foreach (string word in words)
                    {
                        Element.words[i] = new Word();
                        string tmp ;
                        Element.words[i].Element = Element;
                        if (i == words.Length - 1)
                        {
                            Element.words[i].Text = word;
                            tmp = word;
                        }
                        else
                        {
                            Element.words[i].Text = word + " ";
                            tmp = word + " "; //last space cant be measured , lets measure an "," instead
                        }
                        //SizeF size=g.MeasureString (tmp,Element.Font);
                        bbuff.Font = GetFont(Element.Font);
                        Size s = bbuff.MeasureTabbedString(tmp, 0);
                        Element.words[i].Height = s.Height;
                        Element.words[i].Width = s.Width - 0;
                        Element.words[i].ScreenArea.Width = Element.words[i].Width;
                        Element.words[i].ScreenArea.Height = Element.words[i].Height;
                        //	Element.words[i].Link =Element.Link ;

                        i++;
                    }
                }
            }

            bbuff.Dispose();
        }
        private Element[] CreateElements()
        {
            string text = Text.Replace("\n", "");
            text = text.Replace("\r", "");
            string[] parts = text.Split('<');
            var elements = new List<Element>();
            int i = 0;
            foreach (string part in parts)
            {
                var cmd = new Element();

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


                    cmd.Text = TagTextPair[1];


                    if (cmd.TagName == "img")
                    {
                        var img = new Element
                                  {
                                      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++;
            }

            var res = new Element[elements.Count];
            elements.CopyTo(res);
            return res;
        }
        private void ApplyFormat(Element[] Elements)
        {
            var bold = new Stack();
            var italic = new Stack();
            var underline = new Stack();
            var forecolor = new Stack();
            var backcolor = new Stack();
            var fontsize = new Stack();
            var fontname = new Stack();
            var link = new Stack();
            var effectcolor = new Stack();
            var effect = new Stack();

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


            foreach (Element 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) (Font.Size*1.4));
                            bold.Push(true);
                            Element.NewLine = true;
                            break;
                        }
                    case "h4":
                        {
                            fontsize.Push((int) (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;
                        }
                }


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

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

                var font = new Font(FontName, FontSize, fs);
                Element.Font = font;
                Element.BackColor = BackColor;
                Element.ForeColor = ForeColor1;
                Element.Link = Link;
                Element.Effect = Effect;
                Element.EffectColor = EffectColor;
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            int y = e.Y;
            int x = e.X;

            int index = 0;
            bool Link = false;
            //this.Cursor =Cursors.Arrow;
            _ActiveElement = null;
            if (_Rows != null)
            {
                foreach (Row r in _Rows)
                {
                    if (y >= r.Top && y <= r.Top + r.Height)
                    {
                        foreach (Word w in r.Words)
                        {
                            if (y >= w.ScreenArea.Top && y <= w.ScreenArea.Bottom)
                            {
                                if (x >= w.ScreenArea.Left && x <= w.ScreenArea.Right)
                                {
                                    if (w.Element.Link != null)
                                    {
                                        Link = true;
                                        _ActiveElement = w.Element.Link;
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    }
                    index++;
                }
            }
            if (Link)
            {
                Cursor = Cursors.Hand;
                Invalidate();
            }
            else
            {
                Cursor = Cursors.Arrow;
                Invalidate();
            }
            base.OnMouseMove(e);
        }