Drawing Solid and See Through Lines

G

Guest

Drawing Solid and See Through Lines

I want to create a custom form (all drawn in the pain event) that is part
solid (i.e. non see through) and part see through (e.g. 50% opacity). I've
tried setting the BackColor and TransparanceKey colors to the same value and
drawing lines with different Alpha color values. The lines with an Alpha
value of 255 are drawn solid, but the other lines with lower Alpha values
(e.g. 100) are also drawn solid.

How can I draw solid lines and lines I can see the desktop through on the
same form?

Thansk for your help.
 
M

Michael Powell

Hi,
The way to do this would be to make a transparent form, and draw all of your
object (backgrounds, controls...) from there
to do this you would need to set the
ControlStyles.SupportsTransparentBackground flag to true, set the background
colour to transparent and custom draw your entire form.
 
G

Guest

Hi Mike

Thank you for your reply, but I can't get your suggestion to work.

I've added the following code into the Form Load event and tried drawing a
few lines in the Paint event with different Alpha values, but the form
background doesn't appear transparent:

private void Form2_Load(object sender, System.EventArgs e)
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.UserPaint, true);
this.UpdateStyles();
this.BackColor = Color.Transparent;
}

Can you please show me how to make the form transparent and draw see through
lines on the form.

Thanks for your help.

Regards
Mark
 
M

Michael Powell

Hi

I appologize for the last post, i was thinking about transparent controls,
to make the form itself transparent use the following line in the form's
constructor:

this.TransparencyKey = this.BackColor;

this will set the forms BackColor to be see through (you may want to make it
fuschia or some other horrible colour that you will never use to avoid
inadvertantly making other sections transparent)

you also need to set the forms opacity in the constructor, remember though
that this make all of the form's items transparent, no matter what the alpha
value of its colour is, and colours from ARGB veer towards white when the
alpha value veers towards 255

this.Opacity = X; //where X is a flaot in between 0 and 1

the problem of this solution is that everythig becomes semi-opaque

I've been looking into the possibility of changing the opacity depending on
the region, i will update this post if i find anything to let you draw solid
lines on a transparent form
 

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