Beispiel #1
0
        public MarqueeLabel setTextProperty(TextProperty attr, object o)
        {
            Subtitle sub = Prop as Subtitle;

            Console.WriteLine("set " + attr.ToString() + " => " + o);
            Font f = Mlabel.Font;

            switch (attr)
            {
            case TextProperty.FontName:
                sub.fontname = (string)o;

                //System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
                //string fn = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ttf", sub.fontname);
                //Console.WriteLine("font ==> " + fn );
                //privateFonts.AddFontFile(fn );
                //System.Drawing.Font font = new Font(privateFonts.Families[0], 12);

                Mlabel.Font = new Font(FontEx.getFontFamily(sub.fontname), f.Size, f.Style);
                break;

            case TextProperty.FontSize:
                sub.fontsize = (int)(o);
                Mlabel.Font  = new Font(f.Name, sub.fontsize / 2, f.Style | FontStyle.Regular);
                break;

            case TextProperty.Bold:
                sub.bold = (bool)o;
                if (sub.bold)
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style | FontStyle.Bold);
                }
                else
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style & ~FontStyle.Bold);
                }
                break;

            case TextProperty.Italic:
                sub.italic = (bool)o;
                if (sub.italic)
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style | FontStyle.Italic);
                }
                else
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style & ~FontStyle.Italic);
                }
                break;

            case TextProperty.Underline:
                sub.underline = (bool)o;
                if (sub.underline)
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style | FontStyle.Underline);
                }
                else
                {
                    Mlabel.Font = new Font(f.FontFamily, f.Size, f.Style & ~FontStyle.Underline);
                }
                break;

            case TextProperty.Direction:
                lastDirection    = sub.direction = (Direction)o;
                Mlabel.direction = sub.direction;
                break;

            case TextProperty.Speed:
                sub.speed    = (int)o;
                Mlabel.Speed = sub.speed;
                if (sub.speed == 0)
                {
                    sub.direction    = Direction.Static;
                    Mlabel.direction = sub.direction;
                }
                else
                {
                    setTextProperty(TextProperty.Direction, lastDirection);
                }
                break;

            case TextProperty.Text:
                sub.text    = (string)o;
                Mlabel.Text = sub.text;
                break;

            case TextProperty.FontColor:
                Mlabel.ForeColor = (Color)o;
                sub.fontcolor    = ColorEx.ColorToHex(Mlabel.ForeColor);
                break;

            case TextProperty.BackColor:
                Mlabel.BackColor = (Color)o;
                sub.backcolor    = ColorEx.ColorToHex(Mlabel.BackColor);
                sub.transparent  = false;
                if (Mlabel.BackColor == Color.Transparent)
                {
                    sub.transparent = true;
                    sub.backcolor   = "#null";
                }
                break;

            default:
                break;
            }

            //sub.BackColor = ColorTranslator.FromHtml(txtAttr.Bgcolor);
            //sub.ForeColor = ColorTranslator.FromHtml(txtAttr.Color);
            //mlabel.BackColor = Color.Transparent;
            // mlabel.Text = "谁的手机发斯里兰卡哗啦哗啦就好了";
            //sub.Direction = txtAttr.Direction;
            //sub.Speed = txtAttr.Speed;
            //int x = ToFormX(txtAttr.X);
            //int y = ToFormY(txtAttr.Y);
            //sub.Location = new Point(x, y);
            // mlabel.Width = (int)base.Path.GetBounds().Width;
            // mlabel.Height = (int)base.Path.GetBounds().Height;
            //sub.X = txtAttr.X;
            //sub.Y = txtAttr.Y;
            //sub.W = txtAttr.W;
            //sub.H = txtAttr.H;
            //sub.fontname = txtAttr.Fontname;
            //sub.fontsize = txtAttr.Fontsize;
            //sub.transparent = txtAttr.Transparent;
            //sub.Font = new Font("宋体", float.Parse(txtAttr.Fontsize), FontStyle.Regular);
            // mlabel.Location = new Point((int)(base.Path.GetBounds().Location.X), (int)(base.Path.GetBounds().Location.Y));

            return(Mlabel);
        }