频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

.NET Framework创建基于Windows应用程序

来源: 作者: 出处:巧巧读书 2007-10-09 进入讨论组
上一页 1 2 3 4 5 6 下一页 
引用:http://www.qqread.com/dotnet/u351075.html

  因为 Win Forms 建立在通用语言运行时的基础之上,开发人员可以任选目前针对通用语言运行时的众多语言中的一种,构建 Win32 应用程序。

开发人员现在可以使用多种语言编写 Win Forms 应用程序(或 Web Forms 应用程序或 Data 应用程序):从 C# 到 COBOL 到 Eiffel 再到 Perl 等等,中间还有很多种(上一次计数是 17 种)。方便易用再加上广泛的应用场合相得益彰,为开发人员提供了深厚的基础,使他们能够迅速有效地使用 Win Forms 构建实用的应用程序。

  布局

  如果您曾尝试创建能够正常调整大小的窗体,您就会知道这一过程有多么困难。Microsoft Foundation Classes (MFC) 或早期的 Visual Basic 版本没有对这一功能提供内置的支持。然而现在只需几行代码(通常情况下您甚至不需要编写这些代码,因为在设计时就能通过 Property Browser 实现这些功能!),即可创建能够正常调整大小的对话框。

  基本布局由两条组成:Anchoring 和 Docking。RichControl 有一个 Anchor 属性,它是一种枚举类型,可以用“或”操作将这些值组合在一起,以说明控件将与其父控件的某一边保持恒定距离。例如,如果您将一个按钮置于窗体上,并将 Anchor 属性设置为 AnchorStyles.BottomRight,则在调整按钮的大小时,按钮将与窗体的底边和右边保持同一距离。此外,如果将 Anchor 设置为 AnchorStyles.All,则按钮的各个边都与窗体的对应边保持同一距离,在调整按钮大小时仍要满足这些约束条件。

  Docking 实际上是 Anchoring 的一个特殊情况。RichControl 的 Dock 属性说明控件要将自身固定到其父控件的哪一边。Docking 可以是 Top、Left、Right、Bottom 或 Fill。在每种情况下,控件都将移动到尽量靠近指定边,并调整其大小,以填满那一边。如果父控件的大小有所调整,这一状况仍将保持。将一个控件移动到父控件的底端,并将 Anchor 设置为 AnchorStyle.BottomLeftRight,可以模拟 Docking Bottom。在此处的示例中,列表框是 Docked Left,按钮与窗体的顶端、左边和右边保持恒定距离,由此它们保持了相对位置和大小。下面的示例对话框(图 2)完全使用 Visual Studio.NET 中的 Win Forms 设计器创建,只花了两分钟的时间,没有编写一行代码。

// ResizableSample.cs
namespace ResizableSampleNamespace {
using System;
using System.Drawing;
using System.ComponentModel;
using System.WinForms;
/// <summary>
/// ResizableSample 的摘要说明
/// </summary>
public class ResizableSample : System.WinForms.Form {
/// <summary>
/// 为 Win Forms 设计器所要求
/// </summary>
private System.ComponentModel.Container components;
private System.WinForms.Button button3;
private System.WinForms.Button button2;
private System.WinForms.Button button1;
private System.WinForms.ListBox listBox1;
public ResizableSample() {
// 为 Win Form 设计器支持所要求
InitializeComponent();
}
/// <summary>
/// 释放正在使用的所有资源
/// </summary>
public override void Dispose() {
base.Dispose();
components.Dispose();
}
/// <summary>
/// 应用程序的主入口点
/// </summary>
public static void Main(string[] args) {
Application.Run(new ResizableSample());
}
/// <summary>
/// 设计器支持所要求的方法 ― 不要用编辑器
/// 修改这一方法的内容
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button2 = new System.WinForms.Button();
this.button3 = new System.WinForms.Button();
this.button1 = new System.WinForms.Button();
this.listBox1 = new System.WinForms.ListBox();
//@design this.TrayLargeIcon = false;
//@design this.TrayHeight = 0;
this.Text = "Resizable Dialog";
this.IMEMode = System.WinForms.IMEMode.Off;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(256, 173);
button2.Location = new System.Drawing.Point(152, 60);
button2.Size = new System.Drawing.Size(92, 32);
button2.TabIndex = 2;
button2.Anchor = System.WinForms.AnchorStyles.TopLeftRight;
button2.Text = "Cancel";
button3.Location = new System.Drawing.Point(152, 120);
button3.Size = new System.Drawing.Size(92, 44);
button3.TabIndex = 3;
button3.Anchor = System.WinForms.AnchorStyles.All;
button3.Text = "Filler";
button1.Location = new System.Drawing.Point(152, 8);
button1.Size = new System.Drawing.Size(92, 32);
button1.TabIndex = 1;
button1.Anchor = System.WinForms.AnchorStyles.TopLeftRight;
button1.Text = "OK";
listBox1.Size = new System.Drawing.Size(120, 173);
listBox1.Dock = System.WinForms.DockStyle.Left;
listBox1.TabIndex = 0;
listBox1.Items.All = new object[] {"Item One",
"Item Two",
"Item Three",
"Item Four"};
this.Controls.Add(button3);
this.Controls.Add(button2);
this.Controls.Add(button1);
this.Controls.Add(listBox1);
}
}
}

  GDI+

更多文章 更多内容请看Windows操作系统安装Windows权限设置Windows操作系统安全集专题,或进入讨论组讨论。
上一页 1 2 3 4 5 6 下一页 
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章