CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

新手学习中,希望指点

楼主renmasheshou(狼狗)2005-06-01 21:13:31 在 .NET技术 / C# 提问

给一个LinkLabel控件的实例吧    
  这个控件的实例书上没有    
  要求点击链接就能转向那个链接的网页  
  代码贴出来吧   还看的懂   应该可以自己实现    
   
  新人   所以   不要见笑     呵呵  
  问题点数:10、回复次数:3Top

1 楼ljc_zy(彷徨)回复于 2005-06-01 21:56:57 得分 10

using   System;  
  using   System.Drawing;  
  using   System.Windows.Forms;  
   
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
          private   System.Windows.Forms.LinkLabel   linkLabel1;  
           
          [STAThread]  
          static   void   Main()    
          {  
                  Application.Run(new   Form1());  
          }  
   
          public   Form1()  
          {  
                  //   Create   the   LinkLabel.  
                  this.linkLabel1   =   new   System.Windows.Forms.LinkLabel();  
   
                  //   Configure   the   LinkLabel's   size   and   location.   Specify   that   the  
                  //   size   should   be   automatically   determined   by   the   content.  
                  this.linkLabel1.Location   =   new   System.Drawing.Point(34,   56);  
                  this.linkLabel1.Size   =   new   System.Drawing.Size(224,   16);  
                  this.linkLabel1.AutoSize   =   true;  
   
                  //   Configure   the   appearance.  
                  this.linkLabel1.DisabledLinkColor   =   System.Drawing.Color.Silver;  
                  this.linkLabel1.VisitedLinkColor   =   System.Drawing.Color.Blue;  
                  this.linkLabel1.LinkBehavior   =   System.Windows.Forms.LinkBehavior.HoverUnderline;  
                  this.linkLabel1.LinkColor   =   System.Drawing.Color.Navy;  
                   
                  this.linkLabel1.TabIndex   =   0;  
                  this.linkLabel1.TabStop   =   true;  
                   
   
                  //   Add   an   event   handler   to   do   something   when   the   links   are   clicked.  
                  this.linkLabel1.LinkClicked   +=   new   System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);  
   
                  //   Identify   what   the   first   Link   is.  
                  this.linkLabel1.LinkArea   =   new   System.Windows.Forms.LinkArea(0,   8);  
   
                  //   Identify   that   the   first   link   is   visited   already.  
                  this.linkLabel1.Links[0].Visited   =   true;  
                   
                  //   Set   the   Text   property   to   a   string.  
                  this.linkLabel1.Text   =   "Register   Online.     Visit   Microsoft.     Visit   MSN.";  
   
                  //   Create   new   links   using   the   Add   method   of   the   LinkCollection   class.  
                  //   Underline   the   appropriate   words   in   the   LinkLabel's   Text   property.  
                  //   The   words   'Register',   'Microsoft',   and   'MSN'   will    
                  //   all   be   underlined   and   behave   as   hyperlinks.  
   
                  //   First   check   that   the   Text   property   is   long   enough   to   accommodate  
                  //   the   desired   hyperlinked   areas.     If   it's   not,   don't   add   hyperlinks.  
                  if(this.linkLabel1.Text.Length   >=   45)  
                  {  
                          this.linkLabel1.Links[0].LinkData   =   "Register";  
                          this.linkLabel1.Links.Add(24,   9,   "www.microsoft.com");  
                          this.linkLabel1.Links.Add(42,   3,   "www.msn.com");  
                  }  
                   
                  //   Set   up   how   the   form   should   be   displayed   and   add   the   controls   to   the   form.  
                  this.ClientSize   =   new   System.Drawing.Size(292,   266);  
                  this.Controls.AddRange(new   System.Windows.Forms.Control[]   {this.linkLabel1});  
                  this.Text   =   "Link   Label   Example";  
          }  
   
          private   void   linkLabel1_LinkClicked(object   sender,   System.Windows.Forms.LinkLabelLinkClickedEventArgs   e)  
          {  
                  //   Determine   which   link   was   clicked   within   the   LinkLabel.  
                  this.linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited   =   true;  
   
                  //   Display   the   appropriate   link   based   on   the   value   of   the    
                  //   LinkData   property   of   the   Link   object.  
                  string   target   =   e.Link.LinkData   as   string;  
   
                  //   If   the   value   looks   like   a   URL,   navigate   to   it.  
                  //   Otherwise,   display   it   in   a   message   box.  
                  if(null   !=   target   &&   target.StartsWith("www"))  
                  {  
                          System.Diagnostics.Process.Start(target);  
                  }  
                  else  
                  {          
                          MessageBox.Show("Item   clicked:   "   +   target);  
                  }  
          }  
  }  
  Top

2 楼renmasheshou(狼狗)回复于 2005-06-02 20:37:27 得分 0

不急,等我那天有时间把它实现了就给分Top

3 楼sweetch(龙の吻ж龙文)回复于 2005-06-02 20:44:02 得分 0

呵呵,初学者共同学习!!Top

相关问题

  • 学习jsp正在苦恼中望高手指点呀???
  • 学习J2EE中途迷路!望高人指点,定有所报!
  • C#学习中,请各位高手指点!!!,答者有分
  • .net学习,郁闷中,高手请指点????
  • 数据库学习指点
  • 我在学习asp的过程中遇到了问题,请指点
  • 要学习4中的内容该看哪几本书,请高手指点!
  • 学习中遇到了问题,请学长和同学们给些指点
  • 郁闷中,学习编程Delphi7和C#,请高手指点迷津
  • VB.NET学习中,请高手指点,在线等待!!!!答者有分。

关键词

  • linklabel
  • drawing
  • forms
  • size

得分解答快速导航

  • 帖主:renmasheshou
  • ljc_zy

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo