C # button with image doesn't get “pressed” when pressed

I do C # and I'm pretty inexperienced. I have a button with text and an image on it. When I run the program and press the button, the button turns on with the text, but the image remains 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); 
+4
source share
1 answer

.NET does not do this automatically because it does not know what you expect from the image when a button is clicked. Do you expect it to be smaller, moving right, moving left ... etc. Perhaps you could implement MouseDown and MouseUp events? On MouseDown, you can change the image to what you expect to see for "clicked", and change it to MouseUp. Of course, this is because you essentially have 2 images, a “click” and a “normal” version.

+1
source

Source: https://habr.com/ru/post/1307566/


All Articles