• 0

[VB .Net] Label Transparency over Pic


Question

I am working on my on going project and have come across a problem. I wan tto have a picture box filling the back ground with 2 labels over it. However, when I set the label background color to Web/Transparent, the background still comes out grey when I run the program and this is a problem. How do I make it so that the label is truely transparent and you see the contents of the picture box behind it?

Link to comment
https://www.neowin.net/forum/topic/66887-vb-net-label-transparency-over-pic/
Share on other sites

Recommended Posts

  • 0

Hmmm... i had the exact same problem with .NET... This is why i still use VB6 for most of my work, rather than using VB .NET which causes me a lot of headaches with the new structure... Some changes in .NET are really stupid, and create big incompatabilities... I believe the problem with the label (IF it is a problem) makes my life difficult so when i HAVE to do it, i use VB6... I would also be interested in a solution about this issue... Anyone knows?

/Raptor

  • 0

Ok now here is now it works!

Conclusion: Use Form1.BackgroundImage or Panel1.BackgroundImage instead of PictureBox1.Image or PictureBox1.BackgroundImage

And when you set Label1.Backcolor to Transparece, the background of Label1 actually goes to the background or back colour of the form. I suggest you to set the image into Form1.BackgroundImage and it will work! (Or you can try use Panel, too)

post-47-1048021474.jpg

  • 0

When a label's background colour is set to Transparent, it inherits the background colour of its parent control. IIRC, a PictureBox cannot be the parent of another control, so you'll never be able to get the PictureBox's image to show through. You need to do as no name said and put the background image on a panel or other control that can be a parent.

--

Danny Smurf

  • 0
  no name? said:
Well, try this...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 ? ? ? ?Label1.BackColor = System.Drawing.Color.Transparent
End Sub

And here's the screen shot...

it doesn't:(ork :( i duno I guess I'll have to forget being able to resize the form.

  • 0
  bangbang023 said:
  no name? said:
Well, try this...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 ? ? ? ?Label1.BackColor = System.Drawing.Color.Transparent
End Sub

And here's the screen shot...

it doesn't:(ork :( i duno I guess I'll have to forget being able to resize the form.

what do you mean resize?? tell me what exactly you wanna do and i will figure it out for you. i thought you just wanna put some labels on to picture box. btw, that code does work in my .ne:stho :s

  • 0

Why not just override the panel's onpaint and write your own code to size the bitmap? Better yet, since panel doesn't allow double-buffering, create a user control that inherits from panel and use SetStyle to setup double-buffering.

public class UserPanel : System.Windows.Forms.Panel
	{
  /// <summary> 
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public UserPanel()
  {
 	 // This call is required by the Windows.Forms Form Designer.
 	 InitializeComponent();

 	 // TODO: Add any initialization after the InitializeComponent call
 	 SetStyle(ControlStyles.AllPaintingInWmPaint | 
        ControlStyles.UserPaint |
        ControlStyles.DoubleBuffer, true );
  }

As far as the label not drawing transparent, what is its FlatStyle property set to? I think that some of the settings will not draw transparent( e.g. System ). Set it to Standard and it should draw transparent. If that doesn't work, again, you could override OnPaint and used the DrawString method to write text over the image. It isn't that much work to do so.

The pics have a panel that resizes the image, and a string drawn over it with DrawString. Ugly, I know, but you could probably do something nice with it.

UserControl.jpg

UserControl2.jpg

Edited by weenur
  • 0

So what if it's c# and not vb.net? you can do the same thing. The framework is the same. You can override painting in VB, you can create controls in VB.

I'll try and write this in VB.net just to show you how to do it. Granted, I don't write alot in VB so this may take a while.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • This guy is just salty that Waymo is about to get buried by a company with cars that cost significantly less, charge significantly lower fares, and will soon dramatically outnumber their fleet. Waymo made the mistake of not reducing their vehicle cost quick enough and not overcoming their route limitations. Unless they start allowing their cars to use the freeways and have significantly wider geofencing, they're going to soon join the list of discontinued Google products. If Tesla wasn't the one to make them irrelevant, somebody else soon was. There's a long list of companies designing robotaxis right now.
    • LOL. Hard to believe people still fall for this. If you are having some sort of issue, I would work on fixing that instead turning off these settings.
    • That is a great option for compatibility, but in my opinion, that isn't the future. Xorg/Xserver is outdated with massive security holes and limitations built into the core design, which cannot be easily fixed. The reason Wayland exists is because it was apparent that no one had the resources/will to revamp Xorg, so it was basically put into a support only mode until it was eventually abandoned. Yes, X11Libre has taken up the mantal, but I don't expect to see anything from them other than basic support.
    • I agree with your frustrations, but after nearly a decade of Wayland ideologs debating how software they don't write should work...its time to rip the band aid of X11 off and let Wayland sink or swim on its own. Its not like Linux can just fail at this point, so devs will flock together to find solutions. It is my opinion that a lot of these silly debates about things like window decorations take place because they can. People feel like they have time to have these academic conversations to "get it right." However, the conversation will change very quickly when the issue is "###### don't work." People will quickly find fixes once we are forced into that mode. I draw a parallel to the infancy of the internet going public in the late 1980s. It became quickly apparent that IPv4 really wasn't up to the task. The ivory tower response to the issues was basically "your doing it wrong, you shouldn't want that" while debating long-off solutions like IPv6. Then some rando cames along and invited NAT, the standards people saw it as an abomination and absolutely refused to include it. He didn't care, sold the product anyway under the name PIX, which he later sold to Cisco. It was not only a massive success, but it changed the entire concept of the internet, basically inventing the idea of public and privet addresses, which totally reformed the way the internet works. The standards guys were forced to adopt it once they realized it was impossible to put the cat back in the bag.
    • Download How to Engage Buyers and Drive Growth in the Age of AI (worth $22.95) for free by Steven Parker Claim your complimentary eBook worth $22.95 for free, before the offer ends on July 1. Develop stronger, more profitable relationships with your buyers in the digital era. Right now, how we buy and sell is evolving dramatically. People have fundamentally changed the way they do business. To put it simply: buyers no longer interact with sellers in the same way. To ensure a profitable future, sales leaders and teams need to embrace this transformation. In the face of globalisation, ecommerce, subscription services, and new digital tools for buyers and sellers alike, you need new strategies to generate successful sales and better bottom lines. Deep Selling shares the cutting-edge sales model you need to create a buyer-obsessed, high-performance culture. Your team urgently needs to embrace the growing suite of digital and AI technologies. But new technologies alone won’t solve all your selling problems. To really maximise your success, you need to evolve your selling frameworks and behaviours. You need to use these new tools in smart ways, embedding them into your sales execution models. In this book, you’ll discover how to: Audit the current sales techniques and cycles in your organisation Transform your sales execution models Achieve organisational buy-in through new performance measures and shared goals for success Use data to drive strategy, and revolutionise your selling with the latest digital and AI tools Build deeper buyer relationships that create more value and improve buyer outcomes With Deep Selling, you and your team will learn how to meet buyers on today’s real-world terms — and engage them more fully and successfully than ever before. This free to download offer expires July 1. How to get it Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these free offers, you will not need to re-register. While supplies last! Download How to Engage Buyers and Drive Growth in the Age of AI (worth $22.95) for free Offered by Wiley, view other free resources The below offers are also available for free in exchange for your (work) email: Excel Quick and Easy ($12 Value) FREE – Expires 6/24 The Inclusion Equation: Leveraging Data & AI ($21 Value) FREE – Expires 6/24 Microsoft 365 Copilot At Work ($60 Value) FREE – Expires 6/25 Natural Language Processing with Python ($39.99 Value) FREE – Expires 6/25 How to Engage Buyers and Drive Growth in the Age of AI ($22.95 Value) FREE – Expires 7/1 Using Artificial Intelligence to Save the World ($30.00 Value) FREE – Expires 7/1 Essential: How Distributed Teams, Generative AI, [...] ($18.00 Value) FREE – Expires 7/2 The Chief AI Officer's Handbook: Master AI leadership with strategies to innovate, overcome challenges, and drive business growth ($9.99 Value) FREE for a Limited Time – Expires 7/2 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
  • Recent Achievements

    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • One Month Later
      GoForma earned a badge
      One Month Later
    • Week One Done
      GoForma earned a badge
      Week One Done
    • Week One Done
      ravenmanNE earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      652
    2. 2
      Michael Scrip
      226
    3. 3
      ATLien_0
      219
    4. 4
      +FloatingFatMan
      146
    5. 5
      Steven P.
      137
  • Tell a friend

    Love Neowin? Tell a friend!