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


C# Button.DrawToBitmap方法代码示例

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


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

示例1: GetUacShieldIcon

        // Technique from http://www.vb-helper.com/howto_2008_uac_shield.html
        private Bitmap GetUacShieldIcon()
        {
            const int width = 50;
            const int height = 50;
            const int margin = 4;
            Bitmap shieldImage;
            Button button = new Button()
            {
                Text = " ",
                Size = new Size(width, height),
                FlatStyle = FlatStyle.System
            };

            button.SetShieldIcon(true);

            Bitmap buttonImage = new Bitmap(width, height);

            button.Refresh();
            button.DrawToBitmap(buttonImage, new Rectangle(0, 0, width, height));

            int minX = width;
            int maxX = 0;
            int minY = width;
            int maxY = 0;

            for (int y = margin; y < height - margin; y++)
            {
                var targetColor = buttonImage.GetPixel(margin, y);

                for (int x = margin; x < width - margin; x++)
                {
                    if (buttonImage.GetPixel(x, y).Equals(targetColor))
                    {
                        buttonImage.SetPixel(x, y, Color.Transparent);
                    }
                    else
                    {
                        if (minY > y) minY = y;
                        if (minX > x) minX = x;
                        if (maxY < y) maxY = y;
                        if (maxX < x) maxX = x;
                    }
                }
            }

            int shieldWidth = maxX - minX + 1;
            int shieldHeight = maxY - minY + 1;

            shieldImage = new Bitmap(shieldWidth, shieldHeight);

            using (Graphics g = Graphics.FromImage(shieldImage))
                g.DrawImage(buttonImage, 0, 0, new Rectangle(minX, minY, shieldWidth, shieldHeight), GraphicsUnit.Pixel);

            buttonImage.Dispose();

            return shieldImage;
        }
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:58,代码来源:HackerWindow.cs

示例2: ReloadDecorTab


//.........这里部分代码省略.........
                                Size = new Size(40, 35),
                                Name = name,
                                Tag = newL.Number
                            };
                            packControlsWhenChangeMode.Add(comboBoxDecor, diff);
                            if (isAtrName)
                                cb.Tag = new KeyValuePair<Label, ComboBox>(((KeyValuePair<Label, ComboBox>)cb.Tag).Key, comboBoxDecor);

                            #region Новая кнопка

                            Button btnAllMod = null;
                            Button btnFitDecor = null;
                            var mdoc = newL.Component.IGetModelDoc();
                            if (mdoc != null &&
                                mdoc.get_CustomInfo2("", "Accessories") != "Yes")
                            {
                                var toolTip1 = new ToolTip();
                                btnAllMod = new Button
                                {
                                    Location =
                                        new Point(
                                        comboBoxDecor.Location.X +
                                        comboBoxDecor.Size.Width + 5,
                                        comboBoxDecor.Location.Y),
                                    Tag = comboBoxDecor.Name,
                                    Name = newL.Number.ToString(),
                                    BackgroundImage = bitmap,
                                    BackgroundImageLayout = ImageLayout.Stretch
                                    //Image = bitmap
                                };
                                packControlsWhenChangeMode.Add(btnAllMod, diff);
                                btnAllMod.Size = new Size(21, 21);//new Size(30, btnAllMod.Size.Height);
                                var r = new Rectangle(btnAllMod.Location, btnAllMod.Size);
                                btnAllMod.DrawToBitmap(bitmap, r);
                                toolTip1.SetToolTip(btnAllMod,
                                                    "присвоить цвет всем деталям данного типа");
                                btnAllMod.Click += BtnAllModClick;
                                _tabDec.Controls.Add(btnAllMod);

                                var toolTip2 = new ToolTip();
                                Image image = imageList1.Images[3];
                                btnFitDecor = new Button
                                {
                                    Location =
                                        new Point(
                                        comboBoxDecor.Location.X +
                                        comboBoxDecor.Size.Width + 5 + 25,
                                        comboBoxDecor.Location.Y),
                                    Tag = comboBoxDecor.Name,
                                    Name = newL.Number.ToString() + "ex",
                                    BackgroundImage = image,
                                    BackgroundImageLayout = ImageLayout.Stretch,
                                    //ImageKey = @"expand.ico",
                                    ImageList = imageList1
                                };
                                packControlsWhenChangeMode.Add(btnFitDecor, diff);
                                toolTip2.SetToolTip(btnFitDecor, "растянуть декор по ширине и высоте");
                                btnFitDecor.Size = new Size(21, 21);//new Size(24, btnFitDecor.Size.Height);
                                btnFitDecor.Tag = comboBoxDecor.Name;
                                btnFitDecor.Click += BtnFitDecorClick;
                                _tabDec.Controls.Add(btnFitDecor);
                            }

                            #endregion

                            groupBox1.Location = new Point(groupBox1.Location.X,
开发者ID:digger1985,项目名称:MyCode,代码行数:67,代码来源:frmSetParameters.cs


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