范例 1
► 新建项目
这里将使用该控件新建一个程序,这个程序将使人力资源招聘人员查看一项工作的候选人。
打开 Visual Studio 2005.
- 选择File | New | Project (或者使用快捷键 CTRL+SHIFT+N).
- 在New Project 对话框中的 Project Type 中选择 Visual C# | Windows.
- 选择Windows Application模板.
- 在 Location 中填入 “C:\Demos\SmartClient\Mod1-Winform\”.
- 在 Name 处填入 “Candidate Viewer”,然后按OK.
► 新增一个 MenuStrip
- 从 工具箱中添加一个 MenuStrip 控件到Form窗体:
MenuStrip是ToolStrip 系列控件中的一部分, 它可以创建允许用户添加各种不同类型项目的菜单栏,它还支持很多高级特性。
- 点击菜 单的智能标记,选择插入Standard Items.
:
- 点击 菜单的智能标记,选择 Edit Items.
:这将打开如下图所示的Items Collection Editor.
- 在Items Collection Editor中添加一个ToolStripTextBox 设置它的Size-Width为150 ,设置它的Alignment 为 Right.
: 设置一个菜单项的 Alignment 属性为 Right 能使该项出现在菜单的右边缘.
:
- 点击 OK.
► 添加ToolStrip
- 选择一个ToolStrip 控件到form窗体.
: ToolStrip 控件允许建立强大的工具栏。
- 单击ToolStrip的智能标记 ,选择插入 Standard Items.
- 在属性窗口中设置AllowItemReorder属性为True.
: 这个设置允许用户改变子项在toolbar中的顺序,方法是按住ALT,然后拖拽按钮
ToolStrip不仅能装规则的控件,还能装 类似drop-down menus 这样的非规则控件。.
- 单击ToolStrip的智能标记选择Edit Items.
- 在 Items Collection Editor中添加一个 DropDownButton ,设置它的Text 属性为Departments.
- 设置DisplayStyle 为 Text.
- 选择DropDownItems属性,单击椭圆形按钮。.
: 这将打开ToolStripMenuItem的 Items Collection Editor .
- 在 Items Collection Editor中添加 一个名为Accounting的MenuItem .
- 在Items Collection Editor中添加一个名为Human Resources的MenuItem.
- 点击OK两次.
- 在窗体设计中, 单击名为 Departments 的drop-down button.
:
- 另添加一个名为Information Technology的子项.
:
► 添加StatusStrip
- 添加一个 StatusStrip 控件到窗体.
添加一个 StatusLabel 项到StatusStrip. 设置 StatusLabel的Text 属性为“Status Information…”.
- 打开智能标记选择Edit Items.
- 在Items Collection Editor中添加ProgressBar 设置Alignment属性为Right.
- 点OK.
► 运行程序.
- 选择Debug | Start Without Debugging 命令(或者按CTRL+F5).
- 可以通过按 ALT不放,拖动 tool-bar中的按钮.
范例2:
这个例子演示怎样包含Web内容,以及怎样使用新的布局空间方便的管理其他空间
► 添加 TableLayoutPanel
- 添加一个 TableLayoutPanel 到窗体并设置它的Dock属性为Fill.
- 在属性窗口, 设置ColumnCount属性为4 ,RowCount 属性为3.
- 在属性窗口, 选择Columns property 然后单击椭圆形按钮.
: 这将打开Column and Row Styles Editor.
4. 在Column and Rows Styles Editor中按下表配置每一列的SizeType属性。
|
Column |
SizeType |
Width |
|
1 |
AutoSize |
|
|
2 |
AutoSize |
|
|
3 |
AutoSize |
|
|
4 |
AutoSize |
|
5. 点击OK.
6. 从工具箱中拖以下控件到 TableLayoutPanel 中的指定位子
|
Control Type |
Row |
Column |
|
Label |
1 |
1 |
|
TextBox |
1 |
2 |
|
Label |
1 |
3 |
|
TextBox |
1 |
4 |
|
Label |
2 |
1 |
|
WebBrowser |
3 |
1 |
► 设置控件属性
在属性窗口中按下表设置控件属性.
|
Control |
Property |
Value |
|
Form1 |
Text |
Candidate Manager |
|
label1 |
Dock |
Fill |
|
|
Font.Bold |
True |
|
|
Text |
First Name |
|
|
TextAlign |
MiddleRight |
|
label2 |
Dock |
Fill |
|
|
Text |
Last Name |
|
|
TextAlign |
MiddleRight |
|
label3 |
Dock |
Fill |
|
|
Font.Bold |
True |
|
|
Text |
Website |
|
|
TextAlign |
MiddleCenter |
|
textBox1 |
Dock |
Fill |
|
|
Text |
Nancy |
|
textBox2 |
Dock |
Fill |
|
|
Text |
Davolio |
|
webBrowser1 |
ColumnSpan |
4 |
|
|
Dock |
Fill |
|
|
Url |
“File://c:\inetpub\wwwroot\WindowsFormSite.htm”. |
- 调整好row和column的大小,最后的界面如下图所示
3. 为WebBrowser控件的ProgressChanged 事件添写如下代码
if (e.CurrentProgress > 0)


{
toolStripProgressBar1.Maximum = (int)e.MaximumProgress;
toolStripProgressBar1.Value = (int)e.CurrentProgress;
}

► 运行程序
posted on 2005-12-03 20:41
圣炎¢天乐 阅读(3951)
评论(3) 编辑 收藏 网摘