How to create transparent and tangible component - Windows Form C#

Asked

Viewed 183 times

1

I’m looking to create a Panel who will always have the property BringToFront, capable of being fully transparent to the point where it shows components behind it and still be possible to click on it.

inserir a descrição da imagem aqui .

Thanks for the help! :)

  • Hello Tsplayert, already tried changing the color of the Panel to Transparent?

  • Yes, I have tried but only leaves visible the background color of the back component which in the case was the Form itself :/

1 answer

1

To make the Panel transparent adjust the property panel1.BackColor with the method Color.FromArgb where the alpha argument regulates the degree of transparency,

Example:

// Para uma cor sólida alpha deve ser 255
// Para completa transparência alpha deve ser 0
// Nesse caso alpha é 25
panel1.BackColor = Color.FromArgb(25, Color.Blue);

As for control over others the property TopMost only exists for Forms. What you can do is use the method Control.ControlCollection.SetChildIndex(Control, Int32) with a very high number compared to the other controls because even if you create or modify your sibling controls they will always be below it.

Example:

// Enquanto o child index dos outros componentes ficam entre 0 e 10 panel1 
//tem child index 10000 o que garante sempre estar por cima 
form1.setChildIndex(panel1, 10000);
  • I changed the coloring of the component using this property, Backcolor but even so it only leaves transparent to colors, does not show the Label. Now, while overriding the component. I override OnControlAdded() with panel1.BringToFront()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.