单击时,带有图像的C#按钮不会被“推入”

时间:2010-04-21 16:11:27

标签: c# winforms image button

我正在涉足C#,而我对它缺乏经验。我有一个带有文字和图像的按钮。当我运行程序并按下按钮时,按钮与文本一起被推入,但图像保持静止。

有没有人知道解决方法?

*编辑:

    this.btnRename.AllowDrop = true;
    this.btnRename.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Right)));
    this.btnRename.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
    this.btnRename.Image = ((System.Drawing.Image)(resources.GetObject("btnRename.Image")));
    this.btnRename.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
    this.btnRename.Location = new System.Drawing.Point(675, 3);
    this.btnRename.Margin = new System.Windows.Forms.Padding(0);
    this.btnRename.Name = "btnRename";
    this.btnRename.Size = new System.Drawing.Size(55, 48);
    this.btnRename.TabIndex = 7;
    this.btnRename.Text = "&Rename";
    this.btnRename.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
    this.btnRename.UseVisualStyleBackColor = false;
    this.btnRename.Click += new System.EventHandler(this.btnRename_Click);

1 个答案:

答案 0 :(得分:1)

.NET不会自动为您执行此操作,因为它不知道您希望在按钮单击时图像发生什么。你期望它更小,向右移动,向左移动......等等。也许您可以实现MouseDown和MouseUp事件?在MouseDown上,您可以将图像更改为您希望在“推入”中看到的内容,并在MouseUp上将其更改回来。当然,这涉及到你基本上有两个图像,一个“点击”和一个“正常”版本。