Hiding/Removing the "Triangle" from Parent MenuItem

  • Thread starter Thread starter javadkhan
  • Start date Start date
J

javadkhan

Hi All,
I am trying to supress the small black triangle that shows up in the
menus meaning the menuitem is parent. The reason for that is I
owner-drew my own 3D looking triangle in DrawItem using GraphicPath
glyph (drew lines making triangle). What I have right now is my 3D
triangle and default windows menu triangle on it.
Please help, thanks in advance
 
Are you calling base.DrawItem after your custom code? The call to base
should come first.
Maybe you could post a little code?

-Eric
 
You cannot stop the system from drawing the Menu arrow. You can override
everything or even create your menus via Interop and you will still get the
arrow. I couldn't even find a secret undocumented message to intercept when
I tried it. Quite why this paint is not included in the standard windows
Paint/NC_Paint/Print methods I don't know.
 
Here's the code where I am trying to do this.
I am not using base.DrawItem... Do I need to?


private: System::Void menuItem1_DrawItem(System::Object * sender,
System::Windows::Forms::DrawItemEventArgs * e)
{
System::Drawing::Font *f = new System::Drawing::Font(S"Microsoft
Sans Serif", 10, System::Drawing::FontStyle::Bold,
System::Drawing::GraphicsUnit::Point, (System::Byte)0);

MenuItem *mi = __try_cast<MenuItem*>(sender);

//contextMenu1->MenuItems->Item[e->Index]->Text
e->Graphics->DrawString(mi->Text->ToString(),
f, System::Drawing::Brushes::Black,
RectangleF::op_Implicit(e->Bounds),
StringFormat::GenericDefault);

if (mi->IsParent) {


Rectangle rect = e->Bounds;

// where to put a 9 x 5 triangle in rect:
//PointF *location = __nogc new PointF((rect.Width - 2.0 - 9.0)/2.0
+ rect.Left + 1.0,(rect.Height - 2.0 - 5.0)/2.0 + rect.Top + 1.0);
PointF *location = __nogc new PointF(rect.Left + rect.Width -
14,(rect.Height - 2.0 - 5.0)/2.0 + rect.Top + 1.0);

//location->X += 45;
//location->X += 0;
location->X += 0;
location->Y -= 3;


SizeF *size = __nogc new SizeF(10.0, 6.0);
System::Drawing::RectangleF *triangleRect = __nogc new
System::Drawing::RectangleF(*location, *size);

// draw the white triangle:
Drawing::Drawing2D::GraphicsPath *glyph = new
Drawing::Drawing2D::GraphicsPath();

//glyph->AddLine(triangleRect->Left, triangleRect->Top,
triangleRect->Right - 1 , triangleRect->Top);
//glyph->AddLine(triangleRect->Right - 1, triangleRect->Top,
triangleRect->Left + 4, triangleRect->Bottom -1 );
//glyph->AddLine(triangleRect->Left+2, triangleRect->Bottom,
triangleRect->Left+2, triangleRect->Top-3);
//glyph->AddLine(triangleRect->Left+2, triangleRect->Top-3,
triangleRect->Right-1, triangleRect->Top-2+(triangleRect->Bottom -
triangleRect->Top)/2.0);
glyph->AddLine(triangleRect->Left-1, triangleRect->Bottom+3,
triangleRect->Left-1, triangleRect->Top-2);
glyph->AddLine(triangleRect->Left-1, triangleRect->Top-2,
triangleRect->Right, triangleRect->Top + 4);
glyph->CloseFigure();

e->Graphics->FillPath(SystemBrushes::ActiveCaptionText, glyph);

// draw the dark triangle:
Drawing::Drawing2D::GraphicsPath *glyph2 = new
Drawing::Drawing2D::GraphicsPath();
glyph2->AddLine(triangleRect->Left-1, triangleRect->Bottom+1,
triangleRect->Left-1, triangleRect->Top-2);
glyph2->AddLine(triangleRect->Left-1, triangleRect->Top-2,
triangleRect->Right-1, triangleRect->Top-2+4);
glyph2->CloseFigure();

e->Graphics->FillPath(SystemBrushes::ControlDarkDark, glyph2);

// draw the same color triangle:
Drawing::Drawing2D::GraphicsPath *glyph3 = new
Drawing::Drawing2D::GraphicsPath();
glyph3->AddLine(triangleRect->Left+1, triangleRect->Bottom+1,
triangleRect->Left+1, triangleRect->Top+1);
glyph3->AddLine(triangleRect->Left+1, triangleRect->Top,
triangleRect->Right-4, triangleRect->Top+3);
glyph3->CloseFigure();


e->Graphics->FillPath(SystemBrushes::ControlLight, glyph3);

}
}
 
anybody?

Here's the code where I am trying to do this.
I am not using base.DrawItem... Do I need to?


private: System::Void menuItem1_DrawItem(System::Object * sender,
System::Windows::Forms::DrawItemEventArgs * e)
{
System::Drawing::Font *f = new System::Drawing::Font(S"Microsoft
Sans Serif", 10, System::Drawing::FontStyle::Bold,
System::Drawing::GraphicsUnit::Point, (System::Byte)0);

MenuItem *mi = __try_cast<MenuItem*>(sender);

//contextMenu1->MenuItems->Item[e->Index]->Text
e->Graphics->DrawString(mi->Text->ToString(),
f, System::Drawing::Brushes::Black,
RectangleF::op_Implicit(e->Bounds),
StringFormat::GenericDefault);

if (mi->IsParent) {


Rectangle rect = e->Bounds;

// where to put a 9 x 5 triangle in rect:
//PointF *location = __nogc new PointF((rect.Width - 2.0 - 9.0)/2.0
+ rect.Left + 1.0,(rect.Height - 2.0 - 5.0)/2.0 + rect.Top + 1.0);
PointF *location = __nogc new PointF(rect.Left + rect.Width -
14,(rect.Height - 2.0 - 5.0)/2.0 + rect.Top + 1.0);

//location->X += 45;
//location->X += 0;
location->X += 0;
location->Y -= 3;


SizeF *size = __nogc new SizeF(10.0, 6.0);
System::Drawing::RectangleF *triangleRect = __nogc new
System::Drawing::RectangleF(*location, *size);

// draw the white triangle:
Drawing::Drawing2D::GraphicsPath *glyph = new
Drawing::Drawing2D::GraphicsPath();

//glyph->AddLine(triangleRect->Left, triangleRect->Top,
triangleRect->Right - 1 , triangleRect->Top);
//glyph->AddLine(triangleRect->Right - 1, triangleRect->Top,
triangleRect->Left + 4, triangleRect->Bottom -1 );
//glyph->AddLine(triangleRect->Left+2, triangleRect->Bottom,
triangleRect->Left+2, triangleRect->Top-3);
//glyph->AddLine(triangleRect->Left+2, triangleRect->Top-3,
triangleRect->Right-1, triangleRect->Top-2+(triangleRect->Bottom -
triangleRect->Top)/2.0);
glyph->AddLine(triangleRect->Left-1, triangleRect->Bottom+3,
triangleRect->Left-1, triangleRect->Top-2);
glyph->AddLine(triangleRect->Left-1, triangleRect->Top-2,
triangleRect->Right, triangleRect->Top + 4);
glyph->CloseFigure();

e->Graphics->FillPath(SystemBrushes::ActiveCaptionText, glyph);

// draw the dark triangle:
Drawing::Drawing2D::GraphicsPath *glyph2 = new
Drawing::Drawing2D::GraphicsPath();
glyph2->AddLine(triangleRect->Left-1, triangleRect->Bottom+1,
triangleRect->Left-1, triangleRect->Top-2);
glyph2->AddLine(triangleRect->Left-1, triangleRect->Top-2,
triangleRect->Right-1, triangleRect->Top-2+4);
glyph2->CloseFigure();

e->Graphics->FillPath(SystemBrushes::ControlDarkDark, glyph2);

// draw the same color triangle:
Drawing::Drawing2D::GraphicsPath *glyph3 = new
Drawing::Drawing2D::GraphicsPath();
glyph3->AddLine(triangleRect->Left+1, triangleRect->Bottom+1,
triangleRect->Left+1, triangleRect->Top+1);
glyph3->AddLine(triangleRect->Left+1, triangleRect->Top,
triangleRect->Right-4, triangleRect->Top+3);
glyph3->CloseFigure();


e->Graphics->FillPath(SystemBrushes::ControlLight, glyph3);

}
}
 
I already gave you the answer!
You cannot stop the system from drawing the arrow when a menuitem has a
childmenu.
 
ok... there is no any way I can change the way the default triangle is
displayed too?
 
Back
Top