请问我自已新建的控件如何取得style属性?(100分)

weilt 2004-04-30 10:41:44
我自已建的一个控件,加入了table固定格式,有DropDownList,ListBox,和Button和连接数据库等等,我现在就是不知道如何把我新建的控件加入一些如style属性,以及设置bgColor等属性的设置等等。
请问哪位可以帮帮我呀!
以下是代码:
public class Compontision:Control, INamingContainer
{

private DropDownList DDLCOMP = new DropDownList();

private DropDownList DDLDept = new DropDownList();

private DropDownList DDLSECTION = new DropDownList();

private ListBox SelectUnit = new ListBox();

private ListBox SelectedUnit = new ListBox();



public string Value
{
get{return SelectUnit.SelectedValue;}
}

public override string ID
{
get
{
return base.ID;
}
set
{
base.ID = value;
}
}

public override Page Page
{
get
{
return base.Page;
}
set
{
base.Page = value;
}
}

public override bool Visible
{
get
{
return base.Visible;
}
set
{
base.Visible = value;
}
}

protected override void OnInit(EventArgs e)
{
base.OnInit (e);
}

public override Control FindControl(string id)
{
return base.FindControl (id);
}

public override ControlCollection Controls
{
get
{
return base.Controls;
}
}




protected override void CreateChildControls()
{
this.Controls.Add(new LiteralControl("<table cellSpacing='0' cellPadding='0' border='0' style='LEFT: 100px; POSITION: absolute; TOP: 100px'>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td style='HEIGHT: 19px'>"));



DDLCOMP.AutoPostBack = true;
DDLCOMP.SelectedIndexChanged += new EventHandler(this.DDLCOMPSelectedChanged);
DDLCOMP.Width =136;
DDLCOMP.Height =24;
this.Controls.Add(DDLCOMP);


this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td style='HEIGHT:19px' colspan=3>"));

DDLDept.AutoPostBack =true;
DDLDept.SelectedIndexChanged += new EventHandler(this.DDLDept_SelectedIndexChanged);
DDLDept.Width =136;
DDLDept.Height =24;
this.Controls.Add(DDLDept);



this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td style='HEIGHT:19px'>"));
DDLSECTION.AutoPostBack = true;
DDLSECTION.SelectedIndexChanged += new EventHandler(this.DDLSECTION_SelectedIndexChanged);
DDLSECTION.Width =136;
DDLSECTION.Height =24;
this.Controls.Add(DDLSECTION);



this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td colSpan='2' rowSpan='4'>"));
SelectUnit.Width =160;
SelectUnit.Height =120;
this.Controls.Add(SelectUnit);



this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"+" "+"</td>"));
this.Controls.Add(new LiteralControl("<td colSpan='2' rowSpan='4'>"));
SelectedUnit.Width =160;
SelectedUnit.Height =120;
this.Controls.Add(SelectedUnit);



this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td align='center'>"));
Button Button1 = new Button();
Button1.Text = ">>>";
Button1.Width=72;
Button1.Height=24;
Button1.Click += new EventHandler(this.Button1_Click);



this.Controls.Add(Button1);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td align='center'>"));
Button Button2 = new Button();
Button2.Text ="<<<";
Button2.Width=72;
Button2.Height =24;
Button2.Click += new EventHandler(this.Button2_Click);
this.Controls.Add(Button2);




this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));

this.Controls.Add(new LiteralControl("<tr>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("</tr>"));


this.Controls.Add(new LiteralControl("<tr>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));

Button Button3 = new Button();
Button3.Width =64;
Button3.Height=24;
Button3.Text = "确定";
this.Controls.Add(Button3);
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
Button Button4 = new Button();
Button4.Width =64;
Button4.Height=24;
Button4.Text ="取消";
this.Controls.Add(Button4);
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("</td>"));

this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("</table>"));


}
...全文
24 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
vzxq 2004-04-30
nod
帮你UP
  • 打赏
  • 举报
回复
bitsbird 2004-04-30
Button1.Style=""
  • 打赏
  • 举报
回复
leoAAAA 2004-04-30
例如,
Lable l1 = new Lable();
l1.BackColor=Color.Red;

TableCell tc=new TableCell();
tc.BorderColor=Color.Blue;

Table t1=new Table();

t1.BorderColor=Color.Blue;
//t1.BorderStyle=BorderStyle.Solid;
t1.GridLines=GridLines.Both;

或者用css
  • 打赏
  • 举报
回复
weilt 2004-04-30
是的,我想我自已做的控件能够像.NET自还的控件一样的控制它的STYLE 属性,而不像现在 一样只能在控件里面写好了它的大小,位置,什么的
  • 打赏
  • 举报
回复
bitsbird 2004-04-30
你的意思是不是重写这些控件样式?
override protected void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);
this.CssClass = "classTextNotEmpty";
}
.classTextNotEmpty
{
border : solid 1px #E4EAF2;
border-bottom-color:1F4D75;
color : Black;
font-size:11px;
height : 18px;
width:100%;
font-family:Tahoma;
background : #E4EAF2;
}
  • 打赏
  • 举报
回复
weilt 2004-04-30
bitsbird(一瓢.net)

是不是用这种方法有使用此自建控件时可以临时再定义其style 属性?
  • 打赏
  • 举报
回复
zhaozhongju 2004-04-30
好象挺麻烦的,帮你UP
  • 打赏
  • 举报
回复
zdnet 2004-04-30
this.Controls.Attributes.Add("onmouseup", _
"this.style.backgroundColor='Gainsboro';" + _
IIf(isIE, "this.style.borderStyle='outset';", "").ToString())
  • 打赏
  • 举报
回复
相关推荐
发帖
.NET社区
加入

6.0w+

社区成员

.NET技术交流专区
社区管理员
  • ASP.NET
  • R小R
  • 喵叔哟
帖子事件
创建了帖子
2004-04-30 10:41
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。