调整大小ToolStripButtons适合完整的背景图片 [英] Resizing ToolStripButtons to fit complete BackGround image

查看:1365
本文介绍了调整大小ToolStripButtons适合完整的背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在toolStripButton和toolStripDropDownButton完全契合的形象。

My goal is totally fit image in toolStripButton and toolStripDropDownButton.

如果在按钮设置图像属性中的形象,我不能完全适合按钮的图像。因为空白,边框,什么按钮的。(我不知道到底)。

If a image in the button set with image property, I can not totally fit the image in the button. Because of margin, border, or something of the button.(I don't know exactly).

所以我尝试设置图像与BackgroudImage属性的按钮。之后,我调整了部分物业(如自动调整大小,大小等...),我可以在按钮适合的形象。

So I try to set the image in the button with BackgroudImage property. After I adjust some property(like AutoSize, Size and so on...), I can fit image in button.

但在这种情况下,也看不出背景图像。它消失,当鼠标光标位于按钮。

but in this case, I can not see background image. It is disappear, when the mouse cursor is located in the button.

我该如何解决这个问题?

How can I solve this problem??

图片属性。我不能删除图像之间的差距。

Image Property. I can not remove the gap between images.

BackgroundImage属性。我看不到图像,当鼠标光标在图像上。

BackgroundImage Property. I can not see the image, when mouse cursor is on the image.

推荐答案

好了,你发现它为什么留下周围的图像属性的空间。可以通过分配ToolStrip.Renderer属性定制按钮的呈现。这可能是这个样子:

Well, you found out why it leaves a space around the Image property. You can customize the rendering of the button by assigning the ToolStrip.Renderer property. That could look something like this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        toolStrip1.Renderer = new MyRenderer();
    }
    private class MyRenderer : ToolStripProfessionalRenderer {
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) {
            if (e.Item.BackgroundImage == null) base.OnRenderButtonBackground(e);
            else {
                Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
                e.Graphics.DrawImage(e.Item.BackgroundImage, bounds);
                if (e.Item.Pressed) {
                    // Something...
                }
                else if (e.Item.Selected) {
                    // Something...
                }
                using (Pen pen = new Pen(Color.Black)) {
                    e.Graphics.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                }
            }
        }
    }

}

您将必须填写// ...东西线和做一些图纸,使得它明显,按钮pssed或选择$ P $用户。也许画了厚厚的钢笔一个矩形,它是由你。

You'll have to fill in the // Something... lines and do some kind of drawing that makes it obvious to the user that the button is pressed or selected. Maybe draw a rectangle with a thick Pen, it is up to you.

这篇关于调整大小ToolStripButtons适合完整的背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆