PDA

View Full Version : transparent labels in dotNet


PEN
12-07-2010, 09:35 PM
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()

PEN
12-07-2010, 10:06 PM
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
12-07-2010, 10:22 PM
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.

Gravey
12-08-2010, 01:29 PM
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
12-08-2010, 04:52 PM
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.

denisT
12-08-2010, 05:21 PM
Looks like what I want to do just can't be done unfortunately.

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
12-08-2010, 05:39 PM
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
12-08-2010, 06:56 PM
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.

denisT
12-08-2010, 08:35 PM
try this: http://forums.cgsociety.org/showpost.php?p=6794742&postcount=475

probably I've lost anything but it has to work somehow. ;)

listener
12-09-2010, 08:39 PM
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
12-09-2010, 11:54 PM
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.

denisT
12-10-2010, 03:09 AM
Thanks again Denis.


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.

CGTalk Moderation
12-10-2010, 03:09 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.