views:

278

answers:

1

I'm dabbling in C#,and I'm rather inexperienced with it. I have a button with text and an image on it. When I run the program and press the button, the button gets pushed in, along with the text, but the Image stays static.

Does anyone know a workaround?

*EDIT:

    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  A: 

.NET doesn't do this for you automatically because it doesn't know what you expect to happen to the image on button click. Do you expect it to be smaller, moved right, moved left...etc. Perhaps you could implement the MouseDown and MouseUp events? On MouseDown you could have it change the image to what you expect to see for the "pushed in" and change it back on MouseUp. Of course this involves you essentially having 2 images, a "clicking" and an "normal" version.

KrisTrip
that'll be resource-hell to maintain though... I'd opt for an imagehandler if you really would want that (like: MouseDown = imageclone + 1px margin or something)
riffnl
I don't buy this answer; what I'd expect seems pretty obvious, do the same thing with the image as with text: move r/d. I'd guess .NET doesn't do this because they didn't bother/notice.
Conrad Albrecht
I guess I should have said something more like .NET "probably" doesn't do this because...I'm not claiming to have any inside knowledge of Microsoft. The point of the answer was to suggest a way to get the same functionality. Another option is to use WPF instead of WinForms which allows you to perform transforms.
KrisTrip
having two separate icons contributes to bloat, so I'm not too much in favour of it. However the WPF idea is interesting and I'll try implementing it.