Home > Net >  C # button set the background color
C # button set the background color

Time:10-07

The Button Button=new System. Windows. Forms. The Button ();
button. BackColor=System. Drawing. Color. Red;
Button. The Location=new System. Drawing. Point (65, 108);
Button. The Name="button12";
Button. The Size=new System. Drawing. The Size (75, 23);
Button. The TabIndex=0;
Button. The Text="button12";
This. Controls. The Add (button);


Set the button. The BackColor=System. Drawing. Color. Red, but when the program runs, the background Color of the button has not changed, and the button. The UseVisualStyleBackColor attribute is set to false, how can I change the background Color of the button, thank you.

CodePudding user response:

I guess you is a button on the form, a you do according to this button again, and then added, of course, you can't see, he was held up by the original button you form,

CodePudding user response:

reference 1st floor xomix response:
I guess you is a button on the form, a you do according to this button again, and then added, of course, you can't see, he was held up by the you form the original button,

No, I saw only under such a button

CodePudding user response:

 
Private void Form5_Load (object sender, EventArgs e)
{
The Button BTN=new Button ();
BTN. Location=new Point (10, 20);
BTN. Text="myButton";
BTN. BackColor=Color. Red;
This. Controls. The Add (BTN);

}



B: yes, you can

CodePudding user response:

Turned out to be covered by other space, try to help you, more than in several places you can see, such as (10, 10)
button. The Location=new System. Drawing. Point (10, 10);

CodePudding user response:

reference 4 floor From_TaiWan response:
turned out to be covered by other space, try to help you, in a few more position can be seen, such as (10, 10)
button. The Location=new System. Drawing. Point (10, 10);

Controls the z - this property index ghost know why Microsoft is not exposed, the problem is almost a dynamically added controls one of the common problems,

CodePudding user response:

Then how to solve the building Lord I met the same problem also is another thread to the table but there has been no change the background color of the button

CodePudding user response:

What events you're in control, in which event to change the background color, this is very important,

CodePudding user response:

CSDN for traffic also by hook or by crook, direct open dig grave,

CodePudding user response:

fat uncle write code references 5 floor response:
Quote: refer to 4th floor From_TaiWan response:

Turned out to be covered by other space, try to help you, more than in several places you can see, such as (10, 10)
button. The Location=new System. Drawing. Point (10, 10);

Controls the z - this property index ghost know why Microsoft is not exposed, the problem is almost a dynamically added controls one of the common problems,


Controls a lot, it is easy to repeat, need to use TAB to jump, use the mouse to click on it, and in turn make it automatically according to the order, so I understand: (
  •  Tags:  
  • C#
  • Related