• 0

[.NET] Alpha-blended hover windows


Question

Hey guys, hope you're well.

Here's a quick question for you. I have a VB.NET project (though help in C# would be just as useful) and wish to emulate the alpha-blended hover windows that can be seen in Windows Live Messenger. Here's a screenshot:

post-32224-1236284228.png

Similarly the 'toast' popups when a contact signs in use a similar, alpha-blended effect.

Individual elements of this aren't so much of an issue - hovering and fading in/out can be achieved with relative ease, but the alpha-blended background-image of the window has got me stuck.

I've found tutorials that involve inheriting the standard Windows Form class and can produce entire forms that will take a 32-bit PNG as an image but I'm not convinced this is the most efficient manner of achieving this. Any thoughts?

Link to comment
https://www.neowin.net/forum/topic/743184-net-alpha-blended-hover-windows/
Share on other sites

15 answers to this question

Recommended Posts

  • 0
  Rob said:
Hey guys, hope you're well.

Here's a quick question for you. I have a VB.NET project (though help in C# would be just as useful) and wish to emulate the alpha-blended hover windows that can be seen in Windows Live Messenger. Here's a screenshot:

post-32224-1236284228.png

Similarly the 'toast' popups when a contact signs in use a similar, alpha-blended effect.

Individual elements of this aren't so much of an issue - hovering and fading in/out can be achieved with relative ease, but the alpha-blended background-image of the window has got me stuck.

I've found tutorials that involve inheriting the standard Windows Form class and can produce entire forms that will take a 32-bit PNG as an image but I'm not convinced this is the most efficient manner of achieving this. Any thoughts?

I don't think its a bad way of doing things (but IMO applications should stick to the UI conformities of the parent OS ;)), but if your not happy doing it with PNGs, you can probably do something using DirectDraw. I'm not sure where to start looking though, I never do anything like this.

  • 0

In normal apps I wouldn't dream of doing something like this, but for the purposes of an immersive experience I am. I'm constrained by .NET 2.0 for this so no WPF but will look into it some more and post my progress.

Thanks for the suggestions.

  • 0

Well, sorry if I'm misunderstanding here but can't you just draw a gradient background on a window with an opacity set <100?

Like this:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace testapp
{
	static class Program
	{
		[STAThread]
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Form1());
		}
	}

	public partial class Form1 : Form
	{
		public Form1()
		{
			this.SuspendLayout();

			this.Name = "Form1";
			this.Text = "Form1";
			this.ClientSize = new System.Drawing.Size(240, 200);
			this.FormBorderStyle = FormBorderStyle.None;
			this.Opacity = 0.92;

			GraphicsPath path = new GraphicsPath();

			int rad = 10;
			path.AddArc(0, 0, 2 * rad, 2 * rad, 180, 90);
			path.AddArc(this.Width - 2 * rad, 0, 2 * rad, 2 * rad, 270, 90);
			path.AddLine(this.Width, rad, this.Width, this.Height - rad);
			path.AddArc(this.Width - 2 * rad, this.Height - 2 * rad, 2 * rad, 2 * rad, 0, 90);
			path.AddLine(this.Width - rad, this.Height, rad, this.Height);
			path.AddArc(0, this.Height - 2 * rad, 2 * rad, 2 * rad, 90, 90);
			path.AddLine(0, this.Height - rad, 0, rad);

			Region = new Region(path);

			Label lb = new Label();
			lb.Name = "label1";
			lb.Location = new Point(10, 10);
			lb.AutoSize = true;

			lb.BackColor = Color.Transparent;
			lb.Font = new Font("Segoe UI", 12F, FontStyle.Bold, GraphicsUnit.Point, 0);
			lb.Text = "This is my window";

			this.Controls.Add(lb);

			this.ResumeLayout(false);
			this.PerformLayout();
		}

		protected override void OnPaintBackground(PaintEventArgs e)
		{
			Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);

			LinearGradientBrush brush = new LinearGradientBrush(rect,
					Color.FromArgb(255, 180, 205, 230), Color.FromArgb(200, 215, 230, 235),
					LinearGradientMode.Vertical);

			e.Graphics.FillRectangle(brush, rect);
		}
	}
}

  • 0

Not entirely sure what you need then :p

If you don't want it in a DLL you can just copy the code to your program and you won't need any external libraries. If you're not liking it due to code required, there isn't much (that I know, and I'm not exactly good at .NET) you can do in terms of less code. The major downside to using the layered window way is you can't use the common controls and have to make your own up, which if you're just showing text isn't too hard.

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

    • No registered users viewing this page.
  • Posts

    • And they are both to blame. SEO optimisation and the knowledge panel killed web search. Both companies knew what they were doing. Now an interactive/dedicated knowledge panel is the front and centre of AI search, with websites simply being a back end to feed data to these tech giants. Don't need to pay ad money to websites if users dont visit them in the first place. https://arstechnica.com/ai/202...site-clicks-by-almost-half/
    • People yearn for the good old days of IRC and truly open Internet, yet are dismissive of modern solutions like ActivityPub (which Mastodon pioneered) and Matrix. Make it make sense.
    • AI judges learn new tricks to fact-check and code better by Paul Hill Image via Pixabay AI researchers and developers are increasingly turning to large language models (LLMs) to evaluate the responses of other LLMs in a process known as “LLM-as-a-judge”. Unfortunately, the quality of these evaluations degrades on complex tasks like long-form factual checking, advanced coding, and math problems. Now, a new research paper published by researchers from the University of Cambridge and Apple outlines a new system that augments AI judges with external validation tools to improve their judgment quality. This system aims to overcome limitations found in both human and AI annotation. Humans face challenges and biases due to time limits, fatigue, and being influenced by writing style over factual accuracy while AI struggles with the aforementioned complex tasks. The Evaluation Agent that the researchers created is agentic so it can assess the response to determine if external tools are needed and utilizes the correct tools. For each evaluation, three main steps are passed through: initial domain assessment, tool usage, and a final decision. The fact-checking tool uses web search to verify atomic facts within a response; code execution leverages OpenAI’s code interpreter to run and verify code correctness; and math checker is a specialized version of the code execution tool for validating mathematical and arithmetic operations. If none of the tools are found to be useful for making judgments, the baseline LLM annotator is used to avoid unnecessary processing and potential performance regression on simple tasks. The system delivered notable improvements in long-form factual checking, with significant increases in agreement with ground-truth annotations across various baselines. In coding tasks, the agent-based approach significantly improved performance across all baselines. For challenging math tasks, the agents improved performance over some baselines, but not all, and overall agreement remained relatively low at around 56%. Notably, the researchers found that in long-form factual responses, the agent’s agreement with ground-truth was higher than that of human annotators. This framework is extensible, so in the future, other tools could be integrated to further improve LLM evaluation systems. The code for the framework will be made open source on Apple’s GitHub, but it isn’t up yet.
    • https://www.neowin.net/news/tags/mastodon/ In short: Federated Twitter (X)
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      592
    2. 2
      ATLien_0
      224
    3. 3
      Michael Scrip
      171
    4. 4
      Xenon
      140
    5. 5
      +FloatingFatMan
      129
  • Tell a friend

    Love Neowin? Tell a friend!