可以让文本框隐藏左边、上边、右边的三条线吗?就好像划了条线!

Comexe 2002-03-12 05:06:16
可以让文本框不以方框形状出现,隐藏左边、上边、右边的三条线,只出现下面的那条线吗?就好像划了条线!
...全文
132 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Comexe 2002-03-18
  • 打赏
  • 举报
回复
最后,我用BorderStyle属性为bsNone,然后用Label,caption中打了很多空格,Font中style中设下划线!
WeiXuBin 2002-03-15
  • 打赏
  • 举报
回复
---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Custom=TColor(RGB(185,239,245));
MainMenuBackground = clSilver;
MainMenuHighlightColor = Custom;
MainMenuTextColor = clBlack;
MainMenuTextBackground = clSilver;
MainMenuHighlightTextColor = clBlack;
VerticalColor = clSilver;
MenuColor = clWhite;
HighlightColor = Custom;
BorderColor = clBlack;
NormalTextColor = clBlack;
NormalTextBackground = clWhite;
HighlightTextColor = clBlack;
DisabledTextColor = clSilver;
VerticalWidth = 26;
FocusRectRightIndent = 3;
FocusRectLeftIndent = 3;
LeftTextPos = 35;
SideBuffer = 1;

if(Menu->Images == NULL)
MenuIncreaseWidth = 100;
else
MenuIncreaseWidth = 50;

Offset = 5;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Example1Click(TObject *Sender)
{
TMenuItem *MenuItem = ((TMenuItem*)Sender);
if(MenuItem->Count > 0)
{
for(int i=0; i <= MenuItem->Count-1; i++)
{
MenuItem->Items[i]->OnMeasureItem = MyExpandItemWidth;
MenuItem->Items[i]->OnDrawItem = MyDrawItem;
if(MenuItem->Items[i]->Count > 0)
{
for(int x=0; x <= MenuItem->Items[i]->Count-1; x++)
{
MenuItem->Items[i]->Items[x]->OnMeasureItem = MyExpandItemWidth;
MenuItem->Items[i]->Items[x]->OnDrawItem = MyDrawItem;
}
}
}
}
}
//---------------------------------------------------------------------------



WeiXuBin 2002-03-15
  • 打赏
  • 举报
回复
下面是画XPmenu的:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Example1DrawItem(TObject *Sender, TCanvas *ACanvas,
TRect &ARect, bool Selected)
{
TRect FocusRectBorder;
TRect FocusRectFill;
TMenuItem *MenuItem = ((TMenuItem*)Sender);

AnsiString Text = MenuItem->Caption;

// Color the background behind the text
ACanvas->Brush->Color = MainMenuBackground;
ACanvas->FillRect(ARect);

if(Text == "")
return;

if(Selected)
{
// Draw the outline of the selection box
FocusRectBorder = ARect;
ACanvas->Brush->Color = BorderColor;
ACanvas->FrameRect(FocusRectBorder);


// Draw the inside of the selection box
// Make is a little smaller so it does not erase the outline
FocusRectFill = ARect;
FocusRectFill.Top += SideBuffer;
FocusRectFill.Right -= SideBuffer;
FocusRectFill.Left += SideBuffer;
FocusRectFill.Bottom -= SideBuffer;
ACanvas->Brush->Color = MainMenuHighlightColor;
ACanvas->FillRect(FocusRectFill);

// Set the color that we want our text drawn when the item is selected
ACanvas->Font->Color = MainMenuHighlightTextColor;
}
else
{
ACanvas->Font->Color = MainMenuTextColor;
}


int TextLength;
TRect TextRect;

TextLength = Text.Length();
TextRect = ARect;
// This determines where the text is drawn.
TextRect.Left += 5;
TextRect.Top += 1;

// Draw the text
DrawText(ACanvas->Handle,Text.c_str(), TextLength, &TextRect, 0);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::MyDrawItem(TObject* Sender, TCanvas* ACanvas,
const TRect &ARect, bool Selected)
{
int TopPos, TextLength;
AnsiString Text;
TRect TempRect;
TRect VerticalRect;
TRect FocusRectBorder;
TRect FocusRectFill;
TRect TextRect;

TMenuItem *MenuItem = ((TMenuItem*)Sender);

Text = MenuItem->Caption;

// Draw the Background erases anything that was there before.
ACanvas->Brush->Color = MenuColor;
ACanvas->FillRect(ARect);

// Draw any seperator lines
if(Text==BLANK_LINE)
{
// Draw the Vertical Bar
VerticalRect = ARect;
VerticalRect.Top -= SideBuffer;
VerticalRect.Right = VerticalWidth;
VerticalRect.Bottom += SideBuffer;
ACanvas->Brush->Color = VerticalColor;
ACanvas->FillRect(VerticalRect);

// Draw the Blank Line
ACanvas->MoveTo(VerticalWidth,ARect.Top+ARect.Height()/2);
ACanvas->LineTo(ARect.Right,ARect.Top+ARect.Height()/2);
return;
}

// This is for non seperator lines

TextLength = Text.Length();

if(Selected)
{
// Have to draw the vertical bar section to fill in the area that is not
// covered by the selection rect
VerticalRect = ARect;
VerticalRect.Top -= SideBuffer;
VerticalRect.Right = VerticalWidth;
VerticalRect.Bottom += SideBuffer;
ACanvas->Brush->Color = VerticalColor;
ACanvas->FillRect(VerticalRect);

if(MenuItem->Enabled)
{
// The item is selected and enabled

// Draw the focus rect outline border
FocusRectBorder = ARect;
FocusRectBorder.Left += FocusRectLeftIndent - SideBuffer;
FocusRectBorder.Right -= FocusRectRightIndent - SideBuffer;
ACanvas->Brush->Color = BorderColor;
ACanvas->FrameRect(FocusRectBorder);


// Fill in the focus rect. Making it a little smaller so as to not
// draw over the outline
FocusRectFill = ARect;
FocusRectFill.Right -= FocusRectRightIndent;
FocusRectFill.Left += FocusRectLeftIndent;
FocusRectFill.Bottom -= SideBuffer;
FocusRectFill.Top += SideBuffer;
ACanvas->Brush->Color = HighlightColor;
ACanvas->FillRect(FocusRectFill);

// Set the way we want to draw our text
ACanvas->Font->Color = HighlightTextColor;
ACanvas->Font->Style = TFontStyles() << fsBold;
}
else
{
// Menu item is not enabled so do not draw any selection
// rect and change the text color to reflect its unenabled state
// NOTE: The icon is still drawn normally and not disabled
ACanvas->Font->Style = TFontStyles();
ACanvas->Brush->Color = NormalTextBackground;
ACanvas->Font->Color = DisabledTextColor;
}

}
else
{
// Fill in the vertical area
VerticalRect = ARect;
VerticalRect.Top -= SideBuffer;
VerticalRect.Right = VerticalWidth;
VerticalRect.Bottom += SideBuffer;
ACanvas->Brush->Color = VerticalColor;
ACanvas->FillRect(VerticalRect);

// Set the text background color and font based on if it is enabled or not
if(MenuItem->Enabled)
{
ACanvas->Brush->Color = NormalTextBackground;
ACanvas->Font->Color = NormalTextColor;
}
else
{
ACanvas->Brush->Color = NormalTextBackground;
ACanvas->Font->Color = DisabledTextColor;
}

}

// Calculate out the Rect we want to draw our text in
TextRect = ARect;
TextRect.Left += LeftTextPos;
if(Offset > 0)
TextRect.Top += Offset/2 + SideBuffer;
else
TextRect.Top += 2 + SideBuffer;

TextRect.Top += SideBuffer;

// Draw any menu item icons
if(Menu->Images != NULL)
{
Icon = new TIcon();
Menu->Images->GetIcon(MenuItem->ImageIndex,Icon);
ACanvas->Draw(5,ARect.Top+ItemOffset+1,Icon);
delete Icon;
}

// Draw the text
DrawText(ACanvas->Handle,Text.c_str(), TextLength, &TextRect, 0);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::MyExpandItemWidth(TObject *Sender,
TCanvas *ACanvas, int &Width, int &Height)
{
Width += MenuIncreaseWidth;
Height += Offset;
MenuItemHeight = Height;
ItemOffset = Offset/2;
}
//
ddeng 2002-03-15
  • 打赏
  • 举报
回复
干嘛把问题弄得太复杂??真的没必要吧。
fly_bird 2002-03-15
  • 打赏
  • 举报
回复
哪儿可以找到XPmenu哪个例程,我是新手!
40Star 2002-03-13
  • 打赏
  • 举报
回复
自画Edit
Detective 2002-03-13
  • 打赏
  • 举报
回复
只能自己画
ploto 2002-03-13
  • 打赏
  • 举报
回复
使用OwnerDraw即可。
skywolfY 2002-03-13
  • 打赏
  • 举报
回复
用代码把上边的三个线及阴影画了去
ddeng 2002-03-13
  • 打赏
  • 举报
回复
只能四边全部隐藏,设置TEdit的BorderStyle属性为bsNone;
至于下面的线可以使用TBevel来做:设置TBelvel高度为1,Shape为bsTopLine。
Comexe 2002-03-13
  • 打赏
  • 举报
回复
没人知道吗?

呜呜呜呜呜呜——

在线等待!!
potatopro 2002-03-13
  • 打赏
  • 举报
回复
登登的就很好嘛。
把四边都隐藏,画线就简单了。还可以用panel等任何有边框并可以不放内容的空间。还可以用canvas属性画:canvas->moveto(x1,y1);canvas->lineto(x2,y2);颜色,形状都可以自定。
40Star 2002-03-13
  • 打赏
  • 举报
回复
XPmenu就是很好的例子
fly_bird 2002-03-13
  • 打赏
  • 举报
回复
如何自画呢?

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧