偶然下载了IEWebControl的控件,因为原先知道treeview,对他的应用也略知一二,因为大家有太多的贴子讨论treeview.不过我今天来谈谈如何用toolbar控件,在这里介绍的也是toolbar的基本应用.
toolbar的应用主要是对ToolbarButton 、ToolbarCheckButton、ToolbarTextBox、ToolbarDropDownList等的定义,事件的处理。
下面是我对toobar研究的代码,主要环境是vs.net.
首先安装IEWebControl。
在vs.net的工具箱里,把toolbar控件加进去。这样你可以借助vs.net的可视化来设置toobar的一些属性了。
下面贴出代码供大家参考:
1..aspx文件
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Excel.WebForm2" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm2" method="post" runat="server">
<FONT face="宋体">
<iewc:Toolbar id="Toolbar1" style="Z-INDEX: 101; LEFT: 14px; POSITION: absolute; TOP: 61px" runat="server" Width="468px" Height="17px" Font-Size="X-Small">
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="文件(F)" ID="Button1" AccessKey="f"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="编辑(E)" ID="Button2" AccessKey="e"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="视图(V)" ID="Button3" AccessKey="v"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="项目(P)" ID="Button4" AccessKey="p"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="生成(B)" ID="Button5" AccessKey="b"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarButton Text="调试(D)" ID="Button6" AccessKey="d"></iewc:ToolbarButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarCheckButton Text="boy" ID="CheckButton1"></iewc:ToolbarCheckButton>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarTextBox ID="TextBox1"></iewc:ToolbarTextBox>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarDropDownList AutoPostBack="True" ID="DropDownList1">
<asp:ListItem Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</iewc:ToolbarDropDownList>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
<iewc:ToolbarLabel ID="Label2"></iewc:ToolbarLabel>
<iewc:ToolbarSeparator></iewc:ToolbarSeparator>
</iewc:Toolbar>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 243px; POSITION: absolute; TOP: 219px" runat="server" Width="65px" Height="37px"></asp:Label></FONT>
</form>
</body>
</HTML>
2..cs文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
namespace Excel
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected Microsoft.Web.UI.WebControls.Toolbar Toolbar1;
protected Microsoft.Web.UI.WebControls.ToolbarDropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
ShowTime();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Toolbar1.ButtonClick += new System.EventHandler(this.Toolbar1_ButtonClick);
this.Load += new System.EventHandler(this.Page_Load);
this.DropDownList1.SelectedIndexChanged+=new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
}
#endregion
private void Toolbar1_ButtonClick(object sender, System.EventArgs e)
{
ToolbarButton bt=new ToolbarButton();
bt=(ToolbarButton)sender;
switch(bt.ID)
{
case "Button1":
Label1.Text="Button1";
break;
case "Button2":
Label1.Text="Button2";
break;
case "Button3":
Label1.Text="Button3";
break;
case "Button4":
Label1.Text="Button4";
break;
case "Button5":
Label1.Text="Button5";
break;
case "Button6":
Label1.Text="Button6";
break;
}
}
private void DropDownList1_SelectedIndexChanged(object sender,System.EventArgs e)
{
DropDownList1=(ToolbarDropDownList)Toolbar1.Items[17];
Label1.Text=DropDownList1.SelectedItem.Text;
}
private void ShowTime()
{
ToolbarLabel Label2=new ToolbarLabel();
Label2=(ToolbarLabel)Toolbar1.Items[19];
Label2.Text=DateTime.Now.ToLongDateString();
}
}
}