Notifications
Clear all

[Closed] transparent labels in dotNet

 PEN

I have a form and I have two labels. Both are added directly to the form. Is there a way to have the second label transparent over the first? I can get things to be transparent over their parent but not a sibling.

Any idea if that can be done?

Doesn’t work:


f=dotNetObject "form"

lb01=dotNetObject "label"
lb01.backColor=(dotNetClass "system.drawing.color").fromArgb 255 255 0 0
lb01.bounds=(dotNetObject "system.drawing.rectangle" 0 0 100 100)

lb02=dotNetObject "label"
lb02.backColor=(dotNetClass "system.drawing.color").fromArgb 50 0 0 0
lb02.bounds=(dotNetObject "system.drawing.rectangle" 50 50 100 100)

f.controls.add lb02
f.controls.add lb01

f.show()

11 Replies
 PEN

Well this is working. Interesting that it will not show up over the form now only where the parent object is.


fn paintLabel sender arg=
(
	g=arg.graphics
	penDotNet.show g
	c=(dotNetClass "system.drawing.color").fromArgb 150 0 0 0
	b=dotNetObject "system.drawing.solidBrush" c
	rec=dotNetObject "system.drawing.rectangle" 10 10 50 50
	g.FillRectangle b rec
)

f=dotNetObject "form"
f.backColor=(dotNetClass "system.drawing.color").fromArgb 255 0 0 255

lb02=dotNetObject "label"
lb02.backColor=(dotNetClass "system.drawing.color").fromArgb 255 0 0 0
lb02.backColor=lb02.backColor.transparent
lb02.bounds=(dotNetObject "system.drawing.rectangle" 50 50 100 100)
dotNet.addEventHandler lb02 "Paint" paintLabel

lb01=dotNetObject "label"
lb01.backColor=(dotNetClass "system.drawing.color").fromArgb 255 255 0 0
lb01.bounds=(dotNetObject "system.drawing.rectangle" 0 0 100 100)

-- Add the controls and set the parent after adding them. 
f.controls.add lb02
f.controls.add lb01
lb02.parent=lb01

f.show()

 PEN

Well never mind, making the other label parent is no different then adding it to it in the first place so it is no longer a sibling. I have to have it a sibling.

I’m still open for suggestions.

have you considered using WPF? I’m not sure how far along you are in your project but if its still early enough and depending on your requirements it might be a good idea since all WPF controls have an opacity property as standard.

 PEN

I have considered it. I think that I will use it on the next version as I need this to work on several versions of Max without installing or updating anything else.

Looks like what I want to do just can’t be done unfortunately.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it can be done but you have to use c# (or VB, or whatever) to override Label control and its couple methods and events…

 PEN

I have seen a couple of posts on it Denis, just haven’t been able to get it to work as of yet as it has been suggested. I’ll keep playing with it.

The issue I’m having is that the painting of controls that are children of an object I have a back ground image in is very slow. If they are not children of that object it is real time. Even though I’m invalidating the children and not the parent the image must be getting updated or something called to slow it down.

 PEN

I’m trying to get something like this to compile in real time in Max without luck

http://stackoverflow.com/questions/395256/transparent-images-with-c-winforms

Any suggestions. Will it work in the first place?

This is the error I’m getting:

-- Error occurred in anonymous codeblock; filename: E:\Clients\PEN_Productions\Development\maxScripts\PEN_XmlControlPanel\; position: 2588; line: 83
-- Runtime error: dotNet runtime exception: Could not load file or assembly 'file:///C:\Documents and Settings\Paul Neale\Local Settings\Temp\cp1wupbt.dll' or one of its dependencies. The system cannot find the file specified.

try this: http://forums.cgsociety.org/showpost.php?p=6794742&postcount=475

probably I’ve lost anything but it has to work somehow.

Maybe this helps or gives you idea…

public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form1_Paint);
}
public void Form1_Paint(object sender, PaintEventArgs e)
{
String drawString = “Sample Text”;
Font drawFont = new Font(“Arial”, 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
PointF drawPoint = new PointF(150.0F, 150.0F);
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
}

This basically draws text on specified location on screen and you wont have problems with transparency if you can use it in your project of course…

 PEN

Thanks again Denis.

Dejan I can’t use GDI as that will need to be constantly redrawn and I can’t have that happening for speed reasons.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

does it work for you? honestly i’m not happy with the code what i wrote. definitely the code needs a revision. e.g. i’m doing the parent invalidation too late.
unfortunately i don’t have time right now to complete the research. hopefully i’ll be back soon with new more accurate solution. but if you have any “cosmetic” issue please let me know.