当前位置: 首页>>代码示例>>C#>>正文


C# Label.Measure方法代码示例

本文整理汇总了C#中System.Windows.Controls.Label.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# Label.Measure方法的具体用法?C# Label.Measure怎么用?C# Label.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Label的用法示例。


在下文中一共展示了Label.Measure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawText

        // Position a label at the indicated point.
        public void DrawText(Canvas can, string text, Point location, double angle, double font_size, HorizontalAlignment halign, VerticalAlignment valign)
        {
            // Make the label.
            Label label = new Label();
            label.Content = text;
            label.FontSize = font_size;
            label.FontWeight = FontWeights.Bold;
            can.Children.Add(label);

            // Rotate if desired.
            if (angle != 0)
                label.LayoutTransform = new RotateTransform(angle);

            // Position the label.
            label.Measure(new Size(double.MaxValue, double.MaxValue));

            double x = location.X;
            if (halign == HorizontalAlignment.Center)
                x -= label.DesiredSize.Width / 2;
            else if (halign == HorizontalAlignment.Right)
                x -= label.DesiredSize.Width;
            Canvas.SetLeft(label, x);

            double y = location.Y;
            if (valign == VerticalAlignment.Center)
                y -= label.DesiredSize.Height / 2;
            else if (valign == VerticalAlignment.Bottom)
                y -= label.DesiredSize.Height;
            Canvas.SetTop(label, y);
        }
开发者ID:narkia,项目名称:dental_cabinet_application,代码行数:31,代码来源:Statistics.cs

示例2: SparkleEventLog

        public SparkleEventLog()
        {
            Title                 = "Recent Changes";
            Height                = 640;
            Width                 = 480;
            ResizeMode            = ResizeMode.NoResize;
            Background            = new SolidColorBrush (Color.FromRgb (240, 240, 240));
            AllowsTransparency    = false;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            WriteOutImages ();

            Label size_label = new Label () {
                Content    = "Size:",
                FontWeight = FontWeights.Bold
            };

            this.size_label_value = new Label () {
                Content = Controller.Size
            };

            size_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect size_label_rect = new Rect (size_label.DesiredSize);

            Label history_label = new Label () {
                Content    = "History:",
                FontWeight = FontWeights.Bold
            };

            this.history_label_value = new Label () {
                Content = Controller.HistorySize,
            };

            history_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect history_label_rect = new Rect (history_label.DesiredSize);

            Shapes.Rectangle line = new Shapes.Rectangle () {
                Width  = Width,
                Height = 1,
                Fill   = new SolidColorBrush (Color.FromRgb (223, 223, 223))
            };

            Shapes.Rectangle background = new Shapes.Rectangle () {
                Width  = Width,
                Height = Height,
                Fill   = new SolidColorBrush (Color.FromRgb (250, 250, 250))
            };

            this.web_browser = new WebBrowser () {
                Width  = Width - 6,
                Height = Height - 36 - 11
            };

            this.web_browser.ObjectForScripting = new SparkleScriptingObject ();

            spinner = new SparkleSpinner (22);

            // Disable annoying IE clicking sound
            CoInternetSetFeatureEnabled (21, 0x00000002, true);

            this.canvas = new Canvas ();
            Content     = this.canvas;

            this.canvas.Children.Add (size_label);
            Canvas.SetLeft (size_label, 24);
            Canvas.SetTop (size_label, 4);

            this.canvas.Children.Add (this.size_label_value);
            Canvas.SetLeft (this.size_label_value, 22 + size_label_rect.Width);
            Canvas.SetTop (this.size_label_value, 4);

            this.canvas.Children.Add (history_label);
            Canvas.SetLeft (history_label, 130);
            Canvas.SetTop (history_label, 4);

            this.canvas.Children.Add (this.history_label_value);
            Canvas.SetLeft (this.history_label_value, 130 + history_label_rect.Width);
            Canvas.SetTop (this.history_label_value, 4);

            this.canvas.Children.Add (background);
            Canvas.SetLeft (background, 0);
            Canvas.SetTop (background, 36);

            this.canvas.Children.Add (spinner);
            Canvas.SetLeft (spinner, (Width / 2) - 15);
            Canvas.SetTop (spinner, (Height / 2) - 22);

            this.canvas.Children.Add (line);
            Canvas.SetLeft (line, 0);
            Canvas.SetTop (line, 35);

            Closing += Close;

            Controller.ShowWindowEvent += delegate {
               Dispatcher.Invoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();

                    UpdateContent (null);
//.........这里部分代码省略.........
开发者ID:kozze89,项目名称:SparkleShare,代码行数:101,代码来源:SparkleEventLog.cs

示例3: RedrawAll

        /// <summary>
        /// Redraws the whole barcode
        /// </summary>
        public override void RedrawAll()
        {
            Children.Clear();

            double actualWidth = ActualWidth;
            double actualHeight = ActualHeight;
            if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) actualWidth = Width;
            if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) actualHeight = Height;
            if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) return;
            if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) return;

            Rect rectClient = new Rect(0, 0, actualWidth, actualHeight);

            if (Value == null) return;

            string text = InlineHasValue.FormatValue(Value, Format);
            if (String.IsNullOrEmpty(text)) return;

            List<BarcodeCharInfo> charInfo;
            List<int> codeSequence = GenerateCodeSequence(text, out charInfo);
            if (codeSequence.Count <= 0) return;

            // override shown text
            if ((Text != null) && (!String.IsNullOrEmpty(Text))) text = Text;

            int checkSum = 0;
            double left = 0;

            // measure barcode first
            double startCharWidth = 0;
            for (int i = 0; i < codeSequence.Count; i++)
            {
                double charWidth = DrawCharByIndex(null, left, 0, 1, codeSequence[i]);
                if (i == 0) startCharWidth = charWidth;
                left += charWidth;

                if (i == 0) checkSum = codeSequence[0]; else checkSum += codeSequence[i] * i;
            }
            double barcodeDataWidth = left - startCharWidth;

            // draw check sum
            left += DrawCharByIndex(null, left, 0, 1, (checkSum % 103)); // Check Sum

            // draw stop char
            left += DrawCharByIndex(null, left, 0, 1, 106); // Stop

            double barcodeWidth = left;

            Canvas canvas = new Canvas();

            // show barcode text
            Label labelText = null;
            double textHeight = 0;
            decimal labelScale = 1;
            TransformGroup tgl = null;
            if (ShowText)
            {
                labelText = new Label();
                labelText.Content = text;
                labelText.Padding = new Thickness(0.25); // HACK: something is not right here
                labelText.FontFamily = FontFamily;
                labelText.FontStretch = FontStretch;
                labelText.FontStyle = FontStyle;
                labelText.FontWeight = FontWeight;
                labelText.FontSize = 1;
                labelText.Measure(new Size(actualWidth, actualHeight));

                labelScale = (decimal)rectClient.Width / (decimal)barcodeWidth * (decimal)barcodeDataWidth / (decimal)labelText.DesiredSize.Width;
                textHeight = labelText.DesiredSize.Height * (double)labelScale;

                // set new size of barcode text
                tgl = new TransformGroup();
                tgl.Children.Add(new ScaleTransform((double)labelScale, (double)labelScale));
                labelText.RenderTransform = tgl;
            }

            // draw barcode now
            left = 0;
            for (int i = 0; i < codeSequence.Count; i++)
            {
                double lineHeight = 1;
                double th = 0;
                if (labelText != null) th = labelText.DesiredSize.Height;
                if ((ShowText) && (i > 0)) lineHeight = (rectClient.Height - (double)labelScale * th / 2) / rectClient.Height;

                double charWidth = DrawCharByIndex(canvas, left, 0, lineHeight, codeSequence[i]);
                left += charWidth;
            }

            // draw check sum
            left += DrawCharByIndex(canvas, left, 0, 1, (checkSum % 103)); // Check Sum

            // draw stop char
            left += DrawCharByIndex(canvas, left, 0, 1, 106); // Stop

            // move text to right place
            if ((ShowText) && (labelText != null))
//.........这里部分代码省略.........
开发者ID:pusp,项目名称:o2platform,代码行数:101,代码来源:BarcodeC128.cs

示例4: PryanetEventLog

        public PryanetEventLog()
        {
            Title              = "Recent Changes";
            Height             = 640;
            Width              = 480;
            ResizeMode         = ResizeMode.NoResize; // TODO
            Background         = new SolidColorBrush (Color.FromRgb (240, 240, 240));
            AllowsTransparency = false;
            Icon               = PryanetUIHelpers.GetImageSource ("pryanetshare-app", "ico");

            int x = (int) (SystemParameters.PrimaryScreenWidth * 0.61);
            int y = (int) (SystemParameters.PrimaryScreenHeight * 0.5 - (Height * 0.5));

            WindowStartupLocation = WindowStartupLocation.Manual;
            Left = x;
            Top = y;

            WriteOutImages ();

            Label size_label = new Label () {
                Content    = "Size:",
                FontWeight = FontWeights.Bold
            };

            this.size_label_value = new Label () {
                Content = Controller.Size
            };

            size_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect size_label_rect = new Rect (size_label.DesiredSize);

            Label history_label = new Label () {
                Content    = "History:",
                FontWeight = FontWeights.Bold
            };

            this.history_label_value = new Label () {
                Content = Controller.HistorySize,
            };

            history_label.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
            Rect history_label_rect = new Rect (history_label.DesiredSize);

            Shapes.Rectangle line = new Shapes.Rectangle () {
                Width  = Width,
                Height = 1,
                Fill   = new SolidColorBrush (Color.FromRgb (223, 223, 223))
            };

            Shapes.Rectangle background = new Shapes.Rectangle () {
                Width  = Width,
                Height = Height,
                Fill   = new SolidColorBrush (Color.FromRgb (250, 250, 250))
            };

            this.web_browser = new WebBrowser () {
                Width  = Width - 6,
                Height = Height - 64
            };

            this.web_browser.ObjectForScripting = new PryanetScriptingObject ();

            spinner = new PryanetSpinner (22);

            // Disable annoying IE clicking sound
            CoInternetSetFeatureEnabled (21, 0x00000002, true);

            this.canvas = new Canvas ();
            Content     = this.canvas;

            this.canvas.Children.Add (size_label);
            Canvas.SetLeft (size_label, 24);
            Canvas.SetTop (size_label, 4);

            this.canvas.Children.Add (this.size_label_value);
            Canvas.SetLeft (this.size_label_value, 22 + size_label_rect.Width);
            Canvas.SetTop (this.size_label_value, 4);

            this.canvas.Children.Add (history_label);
            Canvas.SetLeft (history_label, 130);
            Canvas.SetTop (history_label, 4);

            this.canvas.Children.Add (this.history_label_value);
            Canvas.SetLeft (this.history_label_value, 130 + history_label_rect.Width);
            Canvas.SetTop (this.history_label_value, 4);

            this.canvas.Children.Add (background);
            Canvas.SetLeft (background, 0);
            Canvas.SetTop (background, 36);

            this.canvas.Children.Add (spinner);
            Canvas.SetLeft (spinner, (Width / 2) - 15);
            Canvas.SetTop (spinner, (Height / 2) - 22);

            this.canvas.Children.Add (line);
            Canvas.SetLeft (line, 0);
            Canvas.SetTop (line, 35);

            Closing += Close;

//.........这里部分代码省略.........
开发者ID:pryanet,项目名称:PryanetShare,代码行数:101,代码来源:PryanetEventLog.cs

示例5: AssertValid

    CreateHeaderOrFooterLabel
    (
        String sLabelText,
        Double dLabelWidth,
        System.Drawing.Font oLabelFont,
        out Label oLabel,
        out Double dLabelHeight
    )
    {
        Debug.Assert(dLabelWidth > 0);
        Debug.Assert(oLabelFont != null);
        AssertValid();

        if (sLabelText == null)
        {
            oLabel = null;
            dLabelHeight = 0;
            return;
        }

        // Use a TextBlock to provide wrapping.

        TextBlock oTextBlock = new TextBlock();
        oTextBlock.Text = sLabelText;
        oTextBlock.TextWrapping = TextWrapping.Wrap;
        WpfGraphicsUtil.SetTextBlockFont(oTextBlock, oLabelFont);

        oLabel = new Label();
        oLabel.Background = HeaderFooterBackgroundBrush;
        oLabel.MaxWidth = dLabelWidth;
        oLabel.Content = oTextBlock;

        // Determine the height of the control.  This will likely be a floating
        // point number.

        oLabel.Measure( new Size(dLabelWidth, Double.PositiveInfinity) );

        // The label height must be an integer.  If it's not an integer, any
        // Image controls contained in the parent StackPanel will be distorted
        // because they don't fall on a pixel boundary.

        oLabel.Height = Math.Ceiling(oLabel.DesiredSize.Height);
        oLabel.Measure( new Size(dLabelWidth, Double.PositiveInfinity) );

        dLabelHeight = oLabel.DesiredSize.Height;
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:46,代码来源:GraphImageCompositor.cs

示例6: createNewConcept

        public void createNewConcept(double x, double y, String type, String name, String attributs, String methods)
        {
            if (classes == null)
                classes = new List<Classe>();

            Label nam, var, fun;
            var = new Label
            {
                Content = attributs == "" ? "attributs" : attributs,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0),
            };

            fun = new Label
            {
                Content = methods == "" ? "methodes" : methods,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0)
            };

            nam = new Label
            {
                Content = name == "" ? "classe : " + classes.Count : name,
                FontSize = 16,
                Margin = new Thickness(x, y, 0, 0)
            };

            nam.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            nam.Arrange(new Rect(nam.DesiredSize));

            double myWidth = nam.ActualWidth;
            double myHeight = nam.ActualHeight + LABEL_SPACE;

            Classe clas = new Classe();
            double i = 0;

            if (type.Contains("classe"))
                i = 0.5;
            else
                i = 4;

            clas.Cadres = new List<Rectangle>();
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE*2, myHeight, x - LABEL_SPACE, y, i));
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y + myHeight + 4, i));
            clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y + myHeight * 2 + 8, i));
            clas.Cadres.Add(generateMyRect(LABEL_SPACE * 4, LABEL_SPACE * 4, x - LABEL_SPACE, y - LABEL_SPACE * 4, 0.5));
            clas.Cadres.Add(generateMyRect(LABEL_SPACE * 4, LABEL_SPACE * 4, x + LABEL_SPACE*3, y - LABEL_SPACE * 4, 0.5));
            //clas.Cadres.Add(generateMyRect(myWidth + LABEL_SPACE * 2, myHeight, x - LABEL_SPACE, y, i));

            clas.Cadres[3].Fill = new SolidColorBrush(Colors.Red);
            clas.Cadres[4].Fill = new SolidColorBrush(Colors.Blue);

            clas.Nom = nam;
            var.Margin = clas.Cadres[1].Margin;
            clas.Variables = var;
            fun.Margin = clas.Cadres[2].Margin;
            clas.Fonctions = fun;

            clas.Type = type;

            clas.Nom_tb = generateTextBox(myWidth + LABEL_SPACE * 2
                                        , myHeight
                                        , clas.Cadres[0].Margin
                                        , clas.Nom.Content.ToString());

            clas.Variables_tb = generateRichTextBox(myWidth + LABEL_SPACE * 2
                                                    , myHeight
                                                    , clas.Cadres[1].Margin);

            clas.Fonctions_tb = generateRichTextBox(myWidth + LABEL_SPACE * 2
                                                    , myHeight
                                                    , clas.Cadres[2].Margin);

            classes.Add(clas);

            back.Children.Add(clas.Cadres[0]);
            back.Children.Add(clas.Cadres[1]);
            back.Children.Add(clas.Cadres[2]);
            back.Children.Add(clas.Cadres[3]);
            back.Children.Add(clas.Cadres[4]);
            back.Children.Add(clas.Nom);
            back.Children.Add(clas.Nom_tb);
            back.Children.Add(clas.Variables);
            back.Children.Add(clas.Variables_tb);
            back.Children.Add(clas.Fonctions);
            back.Children.Add(clas.Fonctions_tb);
        }
开发者ID:ITbob,项目名称:UML2,代码行数:87,代码来源:MainWindow.xaml.cs

示例7: DrawText

        protected void DrawText(string text, Point sp, Point ep, double font_size)
        {
            Label label = new Label();
            label.Content = text;
            label.FontSize = font_size;
            mCanvas.Children.Add(label);

            Point location = new Point((sp.X + ep.X) / 2, (sp.Y + ep.Y) / 2);

            double angle = (Math.Atan2(sp.Y - ep.Y, sp.X - ep.X) + Math.PI) * 180 / Math.PI;

            if (angle != 0)
                label.LayoutTransform = new RotateTransform(angle);
            label.Measure(new Size(double.MaxValue, double.MaxValue));

            double x = location.X;
            x -= label.DesiredSize.Width / 2;
            Canvas.SetLeft(label, x);

            double y = location.Y;
            y -= label.DesiredSize.Height / 2;
            Canvas.SetTop(label, y);
        }
开发者ID:chijianfeng,项目名称:PNManager,代码行数:23,代码来源:BaseAction.cs


注:本文中的System.Windows.Controls.Label.Measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。