Example #1
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();
		}