网站公告列表

  没有公告

加入收藏
设为首页
在线投稿

您现在的位置: IT知识网 >> IT知识 >> 程序设计 >> 汇编语言 >> 文章正文

 

  DotNET WinForm FAQ 16个(下)         

DotNET WinForm FAQ 16个(下)
作者:佚名 文章来源:不详 点击数: 更新时间:2006-12-1 17:18:03
15.     如何设置初始的启动窗体

无论是C#还是Visual Basic的Winform项目中你都可以在Solution Explorer窗口中右键你的Project,然后选择属性,从你Project的属性页中选择你启动的窗体或是Main()方法。

有些不同的是在目前的VS.NET Beta2中C#项目会自动产生Main() 方法,Visual Basic.Net 的项目中你必须自己添加Main()代码,C#中你可以将Form1改成任何你可以启动的窗体名:

     // ( C# )

        static void Main()

        {

            Application.Run(new Form1());

        }

 

16.     如何建立一个有背景图像的窗体

现在的Winform中所有的窗体都有一个BackgroundImage属性,只用对它赋值就可以了。普通窗体可以在运行模式也可以在运行模式完成这个设置。比如在InitializeComponent()或窗体的构造函数中加入这样的代码:

this.BackgroundImage = new Bitmap("C:\\DotNetApp\\WinForm\\Tile.bmp" ) ;

    对于MDI的主窗体要麻烦一些,在VS.NET的IDE窗体中,当你设置完IsMdiContainer属性为True后,你需要查看一下InitializeComponent()中是否有这样的代码 ( C# ):

            this.mdiClient1.Dock = System.Windows.Forms.DockStyle.Fill;

            this.mdiClient1.Name = "mdiClient1";

或是在窗口的属性窗口组合框中看到mdiClient1 System.Windows.Forms.mdiClient.这就是主MDI窗口,不过我没有在dotnet的文档中找到任何有关System.Windows.Forms.mdiClient的说明。然后你可以在InitializeComponent()或窗体的构造函数中加入这样的代码( C# ):

this.mdiClient1.BackgroundImage  = new Bitmap("C:\\DotNetApp\\WinForm\\Tile.bmp" ) ;

    网上有一个ImageView的例子,里面演示了给MDI主窗体中背景上加入一行Logo文字的方法,这样使你的MDI窗体看起来很商业化,具体的你可以这样做:

1.   先在VS.NET 自动产生代码的InitializeComponent中看是否有这样的语句( C# ):

this.Controls.AddRange(new System.Windows.Forms.Control[] {this.mdiClient1});

    又是这个mdiClient (haha)

2.   建立以下两个函数用于显示这个Logo字符:

// ( C# )

        protected  void Mdi_OnPaint (  Object s,  System.Windows.Forms.PaintEventArgs e )

        {

            Control c = (Control)s;

           

 

            Rectangle r1 = c.ClientRectangle;

            r1.Width -= 4;

            r1.Height -= 4;

 

            Rectangle r2 = r1;

            r2.Width -= 1;

            r2.Height -= 1;

 

            Font f = new Font("Tahoma", 8);

 

            String str = "MyWinform.NET ?2001 MyWinform Application V1.0";

 

            StringFormat sf = new StringFormat();

            sf.Alignment = StringAlignment.Far;

            sf.LineAlignment = StringAlignment.Far;

 

            e.Graphics.DrawString(str, f, new SolidBrush(SystemColors.ControlDarkDark), r1, sf);

            e.Graphics.DrawString(str, f, new SolidBrush(SystemColors.ControlLight), r2, sf);

 

        }

 

        protected  void Mdi_OnResize ( Object s ,  System.EventArgs e )

        {

           

            Control c = (Control)s;

            c.Invalidate();

        }

3.   在InitializeComponent()或窗体的构造函数中加入这样的代码:

( C# )

    this.Controls[0].Paint += new PaintEventHandler( Mdi_OnPaint ) ;

    this.Controls[0].Resize += new EventHandler( Mdi_OnResize ) ;

        注意将它加在InitializeComponent()后面或是在InitializeComponent函数中this.Controls.AddRange函数之后。


 

总的看来,整个Winform部分始终透着Hejlsberg设计VJ++中WFC库的气息,现在还没有任何线索能证明dotnet是照搬WFC库,但我还是相信Delphi和VJ++的用户会更容易感受到Hejlsberg的设计风格,比如事件委托在几年前就被视为领先而严重违背“纯Java”原则而使开发人员陷入尴尬,现在我们可以很自然的享受这种特性,但另一方面dotnet和Java或Delphi似乎靠得更近些,你几乎不能像MFC时代那样去从源代码中找寻秘密和内幕了。


上一页  [1] [2] [3] 

文章录入:bolang    责任编辑:bolang 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最 新 热 门
    相 关 文 章
    OSPF Troubleshooting 实
    采用基于Guard和Detecto
    Cisco works windows 5.
    CISCO学习问题之ip forw
    六、PSTN,CISCO路由器配
    Cisco 路由器如何防止 D
    Cisco路由器由Windows20
    Cisco路由器由Windows20
    Cisco路由器如何防止DDo
    Cisco路由器由Windows 2
     
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    Copyright© ITZS.NET All Rights Reserved
    QQ:272895858   ICP备案编号:吉ICP备07000044号
    IT知识网 站长:博浪