Board index » cppbuilder » TTreeView Transparancy?

TTreeView Transparancy?


2003-12-07 07:59:16 AM
cppbuilder17
Hi Experts :-),
Simple question, unknown answer.
Is there a way to make a TTreeView Transparant?! (don't want to use other
components)
And if an expert of this is in the room: How can I change the
hottrack-color/font and maybe
also get rid of the selection at the same time.
I have been searching for this the whole day.
Elina.
 
 

Re:TTreeView Transparancy?

I will answer your first question with this link
www.codeguru.com/treeview/background_image.shtml
Bandit Gates
President and Treasure
Microsupport Department
Microcrop Corporation
XXXX@XXXXX.COM
"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Experts :-),

Simple question, unknown answer.

Is there a way to make a TTreeView Transparant?! (don't want to use other
components)

And if an expert of this is in the room: How can I change the
hottrack-color/font and maybe
also get rid of the selection at the same time.

I have been searching for this the whole day.

Elina.


 

Re:TTreeView Transparancy?

Quote
www.codeguru.com/treeview/background_image.shtml
That's VC++... I don't use that and don't know about that.
I'm using BCB and TTreeView, not CTreeView.
Elina.
 

{smallsort}

Re:TTreeView Transparancy?

"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
That's VC++... I don't use that and don't know about that.
I'm using BCB and TTreeView, not CTreeView.
Have a look at the following article instead. The example code does the
same thing under BCB. It works with a TListView in the example, but the
same thing can be adapted for a TTreeView as well:
Sublcass a windows control
www.bcbdev.com/faqs/faq76.htm
Gambit
 

Re:TTreeView Transparancy?

Quote
Sublcass a windows control
www.bcbdev.com/faqs/faq76.htm
Thx Remy for your trouble, I now nearly have what I want :-).
I only just can't get rid of the selection-rect. in my new ETreeView
dependance from TTreeView.
Elina.
 

Re:TTreeView Transparancy?

"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
I only just can't get rid of the selection-rect. in my
new ETreeView dependance from TTreeView.
Why can't you just set the Selected property to NULL? Or is that not what
you are referring to?
Gambit
 

Re:TTreeView Transparancy?

Quote
Why can't you just set the Selected property to NULL? Or is that not what
you are referring to?
If a user clicks on a Item, it by default gets selected and that is shown by
drawing a blue rectangle with a selection-marquee around it. Now I can
change the color of that blue rectangle, but the, let's say,
'selection-dots' stay.
Elina.
 

Re:TTreeView Transparancy?

"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
If a user clicks on a Item, it by default gets selected and that
is shown by drawing a blue rectangle with a selection-marquee
around it. Now I can change the color of that blue rectangle, but
the, let's say, 'selection-dots' stay.
That is the focus, not the selection. They are two different things.
TTreeNode has separate Selected and Focused properties for that. You are
setting Selected to false, but you are not setting Focused to false as well.
Gambit
 

Re:TTreeView Transparancy?

Quote
That is the focus, not the selection. They are two different things.
TTreeNode has separate Selected and Focused properties for that. You are
setting Selected to false, but you are not setting Focused to false as
well.
Ah, that makes sense :-).
Now TTreeView has got a CustomDrawItem-Event where I have to make all the
things I want.
My TTreeView should do 2 things;
-change text color(/font/style) when MouseOver an Item.
-draw a rect that's filled with a bit different color when focused.
Pfff, I've found some examples, but I can't seem to get this done...
www.bridgespublishing.com/articles/0702/July02-02.htm
I can draw a rect when focused;
...
if (State.Contains(cdsFocused)) {
DrawFocusRect(hDC, &LineRect);
}
...but Aaargh......
Also searched google, but TTreeView examples/tutorials are very hard to
find.
Can somebody give me some pointers please?
Elina.
 

Re:TTreeView Transparancy?

You can try something like this. You might need to refresh to avoid ugly
"leftover"
when sizes and ot fonts are different.
void __fastcall TForm1::TreeView1CustomDrawItem( TCustomTreeView *Sender,
TTreeNode *Node, TCustomDrawState State, bool &DefaultDraw )
{
TCanvas *pCanvas = TreeView1->Canvas;
TreeView1->Canvas->Font->Color = clGray;
if (State.Contains(cdsSelected))
{
// Selected
// - Font name and size are changed
// - Color of font is changed
// - Brush color is changed
TreeView1->Canvas->Font->Name = "Helvetica";
TreeView1->Canvas->Font->Color = clWhite;
TreeView1->Canvas->Font->Size = 10;
TreeView1->Canvas->Font->Style =
TreeView1->Canvas->Font->Style
<< fsBold;
TreeView1->Canvas->Brush->Color = clRed;
}
else
{
//Not Selected
TreeView1->Canvas->Font->Name = "Times New Roman";
TreeView1->Canvas->Font->Size = 12;
TreeView1->Canvas->Font->Color = (TColor)0x0000ff00;
}
}
"The Universe, as a whole, is a place without outdoors". Rodolfo, 2003
"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
>That is the focus, not the selection. They are two different things.
>TTreeNode has separate Selected and Focused properties for that. You
are
>setting Selected to false, but you are not setting Focused to false as
well.


Ah, that makes sense :-).


Now TTreeView has got a CustomDrawItem-Event where I have to make all the
things I want.

My TTreeView should do 2 things;

-change text color(/font/style) when MouseOver an Item.
-draw a rect that's filled with a bit different color when focused.


Pfff, I've found some examples, but I can't seem to get this done...
www.bridgespublishing.com/articles/0702/July02-02.htm

I can draw a rect when focused;
...
if (State.Contains(cdsFocused)) {
DrawFocusRect(hDC, &LineRect);
}
...but Aaargh......


Also searched google, but TTreeView examples/tutorials are very hard to
find.

Can somebody give me some pointers please?

Elina.


 

Re:TTreeView Transparancy?

Typo: remove the first twoo lines, you won't need them
Quote
TCanvas *pCanvas = TreeView1->Canvas;
TreeView1->Canvas->Font->Color = clGray;
void __fastcall TForm1::TreeView1CustomDrawItem( TCustomTreeView *Sender,
TTreeNode *Node, TCustomDrawState State, bool &DefaultDraw )
{
if (State.Contains(cdsSelected))
{
// Selected
// - Font name and size are changed
// - Color of font is changed
// - Brush color is changed
TreeView1->Canvas->Font->Name = "Helvetica";
TreeView1->Canvas->Font->Color = clWhite;
TreeView1->Canvas->Font->Size = 10;
TreeView1->Canvas->Font->Style = TreeView1->Canvas->Font->Style
<< fsBold;
TreeView1->Canvas->Brush->Color = clRed;
}
else
{
//Not Selected
TreeView1->Canvas->Font->Name = "Times New Roman";
TreeView1->Canvas->Font->Size = 12;
TreeView1->Canvas->Font->Color = (TColor)0x0000ff00;
}
}
Rodolfo
 

Re:TTreeView Transparancy?

Quote
Rodolfo
Thx, that helped me a bit understanding it also...
Okay, we're on the right way now :-).
But... it just draws a box directly around the text;
TreeView->Canvas->Brush->Color = (TColor)0x00FFD5AA;
How can I draw it on the entire width of the TreeView and with a rect around
it so I can hide the ugly 'marquee' selection around the selected?
Plus... I want to "-change text color(/font/style) when MouseOver an Item."
I'm trying some things with the TreeViewMouseMove-Event now...
Elina.
 

Re:TTreeView Transparancy?

this code will do something like that. You could improve it a lot.
Notice that the marquee has not been removed.
...
TTreeNode* SelectedNode;
TTreeNode* PreviouslySelectedNode;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
...
TreeView1->FullExpand();
// Select the top node
TreeView1->Selected = gNode[1];
TreeView1->SetFocus();
// Init PreviouslySelectedNode
PreviouslySelectedNode = TreeView1->Selected;
}
void __fastcall TForm1::TreeView1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
PreviouslySelectedNode->Text = SavedText; // Restore Text
// Init SelectedNode
SelectedNode = TreeView1->Selected;
PreviouslySelectedNode = TreeView1->Selected;
SavedText = SelectedNode->Text; // Save current text
// Add spaces to make text longer
SelectedNode->Text = SavedText + " \
";
}
Rodolfo
Quote
Thx, that helped me a bit understanding it also...

Okay, we're on the right way now :-).


But... it just draws a box directly around the text;
TreeView->Canvas->Brush->Color = (TColor)0x00FFD5AA;

How can I draw it on the entire width of the TreeView and with a rect
around
it so I can hide the ugly 'marquee' selection around the selected?

Plus... I want to "-change text color(/font/style) when MouseOver an
Item."
I'm trying some things with the TreeViewMouseMove-Event now...

Elina.


 

Re:TTreeView Transparancy?

Quote
this code will do something like that. You could improve it a lot.
Notice that the marquee has not been removed.
I can't get this working like I want Rodolfo, thank you so much for helping
me with this. I reposted it and a zip-file with an example because I'm
nearly there I think and the Transparancy, like the subject says, doesn't
matter anymore.
Elina.
 

Re:TTreeView Transparancy?

I haven't run your code. Why are you almost there?
What is the thing that does not work correctly, Transparency?
Length of the Selected item? Font of the Selected item?
Size of the Selected item? Marquee around the Selected item?
Please clarify
Rodolfo
"Elina" < XXXX@XXXXX.COM >wrote in message
Quote
>this code will do something like that. You could improve it a lot.
>Notice that the marquee has not been removed.

I can't get this working like I want Rodolfo, thank you so much for
helping
me with this. I reposted it and a zip-file with an example because I'm
nearly there I think and the Transparancy, like the subject says, doesn't
matter anymore.

Elina.