示例#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);
        }
示例#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;
            }
        }
示例#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);
        }
示例#4
0
		private void CreateWords(FormatLabelElement[] Elements)
		{
			GDISurface bbuff = new GDISurface(1, 1, this, false);

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

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

					Image img = null;

					try
					{
						string SRC = GetAttrib("img", Element.Tag).ToLower();
						if (IsIndex(SRC))
						{
							int index = int.Parse(SRC);
							img = this.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 = new Rectangle(Element.words[0].ScreenArea.Location,
                            new Size(img.Width, img.Height));
					}
				}
				else
				{
					string[] words = Element.Text.Split(' ');
					Element.words = new FormatLabelWord[words.Length];
					int i = 0;
					foreach (string word in words)
					{
						Element.words[i] = new FormatLabelWord();
						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 = new Rectangle(Element.words[i].ScreenArea.Location, 
                            new Size(Element.words[i].Width, Element.words[i].Height));
						//	Element.words[i].Link =Element.Link ;

						i++;
					}
				}
			}

			bbuff.Dispose();
		}
示例#5
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;
			}
		}
示例#6
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;
		}
示例#7
0
		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 (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();
			}
			else
			{
				this.Cursor = Cursors.Arrow;
				this.Invalidate();
			}
			base.OnMouseMove(e);
		}