0

Is there any method to hide a button text behind button image like bring to front or send to back option?

I only need to hide or show button image only as I have a code that coverts the original text CloseButton.text = "&Close"; to CloseButton.Text = "&Cancel"; to perform another command so I can't use CloseButton.Text = "";.

Tried this link - WinForms button with image and text but my button size is too small that it would only show the text and not the image no matter how I mix and match TextAlign and ImageAlign.

Any help is much appreciated. Thanks in advance.

Sample Button Size below:

See image & text overlapping

P. Pat
  • 488
  • 4
  • 13
  • 1
    You tried to explain, but it's still unclear to me why you need to use the `Text` property if you don't want it displayed. – Rotem Mar 12 '18 at 09:06
  • @Rotem Like I said in my post, I have a code behind that requires me to use text as I am trying to make it work that way and if there's no way around it then need to find another way. – P. Pat Mar 12 '18 at 09:10
  • 1
    Have your code behind use the `Tag` property rather than `Text`. Easiest way out is using properties for what they were made for. – Rotem Mar 12 '18 at 09:12
  • @Rotem thanks a lot. Never tried using `Tag` before. Gonna try it out now. – P. Pat Mar 12 '18 at 09:13
  • @Rotem `Tags` was the right answer. I hope you could post an answer that I can mark as correct or I'll have to post one myself as I manage to make it work using your suggestion. – P. Pat Mar 19 '18 at 04:51
  • @Pat feel free to post and accept an answer. – Rotem Mar 19 '18 at 05:28

3 Answers3

1

Check this

Place Textbox in Button and set textbox.visible=false method

  • 1
    don't use button.text property. Place new textbox in your button and use that, it's a workaround but it suits your needs – Frosty Bacon Mar 12 '18 at 09:16
  • I actually tried it and it helped but the better answer was using `Tags`. Thanks anyways Frosty – P. Pat Mar 19 '18 at 04:49
0

Is there any method to hide a button text behind button image like bring to front or send to back option?

There is no such built in but you can simply clear out the text on click event of the controls. Example: if you have radio buttons for send to back then on click of that clear out the control text saying controlId.Text = string.Empty

Rahul
  • 76,197
  • 13
  • 71
  • 125
0

As @Rotem posted in the comments.

Have your code behind use the Tag property rather than Text. Easiest way out is using properties for what they were made for.

Instead of using CloseButton.text = "&Close"; I changed it to CloseButton.Tag = "&Close"; and made my code worked around it to have the same function without placing an actual Text in my Buttons. Credit this asnwer to @Rotem. Thanks.

P. Pat
  • 488
  • 4
  • 13