Opacity of controls on a form

J

Jonathan

I want to be able to draw lines and shapes on a form that is completly
transparent. I am finding that as I decrease the opacity the lines fade out
also. Is there a way around this problem?

Thanks
 
J

Joe Cool

I want to be able to draw lines and shapes on a form that is completly
transparent. I am finding that as I decrease the opacity the lines fade out
also. Is there a way around this problem?

You want the form itself transparent, but the controls on it visible?
 
J

Jonathan

That's correct. I want to use this as an overlay to make annotations. If you
have a better technique I’d be interested to know. Open to all suggestions.
 
G

Gregory A. Beamer

I want to be able to draw lines and shapes on a form that is completly
transparent. I am finding that as I decrease the opacity the lines
fade out also. Is there a way around this problem?

Thanks

One way to do it is to create a transparency key and then color the entire
form in that color. This will make it so the form becomes invisible without
reducing the opacity to 0, so the lines should still show up.

Just an idea. I have not tried it personally, except to remove corners from
a custom form shape.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
J

Joe Cool

That's correct. I want to use this as an overlay to make annotations. If you
have a better technique I’d be interested to know. Open to all suggestions.

I got nothing. In fact, I'd be surprised if you got it to work at all.
 
K

kndg

Jonathan said:
Tried this. No luck. I appriciate the info.

Hi Jonathan,

It should work.
If you need your form to completely transparent, you should handle a way
for the user to exit your application.

public class MyForm : Form
{
public MyForm()
{
BackColor = Color.Magenta;
TransparencyKey = Color.Magenta;

//FormBorderStyle = FormBorderStyle.None; // CAUTION
//ShowInTaskbar = false; // CAUTION
}

private void DrawSomething(Graphics g)
{
Font font = new Font(FontFamily.GenericSansSerif, 14.0f);

g.DrawString("Hello World!", font, Brushes.Blue, 20f, 20f);

font.Dispose();
}

protected override void OnPaint(PaintEventArgs e)
{
DrawSomething(e.Graphics);

base.OnPaint(e);
}

[STAThread]
public static void Main(string[] args)
{
Application.Run(new MyForm());
}
}
 
J

Jonathan

I see the difference between what you're doing and I'm doing. I want to draw
lines dynamically with mouse events. Making the opacity 0 appently disables
the event handlers.
--
Jonathan


kndg said:
Jonathan said:
Tried this. No luck. I appriciate the info.

Hi Jonathan,

It should work.
If you need your form to completely transparent, you should handle a way
for the user to exit your application.

public class MyForm : Form
{
public MyForm()
{
BackColor = Color.Magenta;
TransparencyKey = Color.Magenta;

//FormBorderStyle = FormBorderStyle.None; // CAUTION
//ShowInTaskbar = false; // CAUTION
}

private void DrawSomething(Graphics g)
{
Font font = new Font(FontFamily.GenericSansSerif, 14.0f);

g.DrawString("Hello World!", font, Brushes.Blue, 20f, 20f);

font.Dispose();
}

protected override void OnPaint(PaintEventArgs e)
{
DrawSomething(e.Graphics);

base.OnPaint(e);
}

[STAThread]
public static void Main(string[] args)
{
Application.Run(new MyForm());
}
}
 
W

wannabe geek

I know this is an old post but I think I could solve that problem. What I
think would work is have one form that is _almost_ transparent (99%?) to get
mouse input and another one using TransparencyKey that will show a line and
then have communication between the two forms, either by methods or by
properties. That way you can pick up the mouse events and also have an opaque
line. Be aware that antialiasing the line will result in a thin outline of
the form BackgroundColor around the line, ditto with any other antialiased
object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top