选择显示字体大小

为asp.net控件添加设计时支持(12)

     列表 4:blog_dt.vb
  
  '支持设计时特性
  imports system.componentmodel
  '支持颜色结构
  imports system.drawing
  '支持 uitypeeditor 类型
  imports system.drawing.design
  '支持 streamwriter 类型
  imports system.io
  imports system.web.ui
  '支持 controldesigner 类型
  ' 请注意,必须添加程序集
  ' system.design 的引用,才能导入此命名空间
  imports system.web.ui.design
  '支持使用 html 控件
  imports system.web.ui.htmlcontrols
  '支持使用 web 控件
  imports system.web.ui.webcontrols
  
  <assembly: tagprefix("blogcontrol", "blogcontrol")>
  
  public enum blogmode
  add
  display
  end enum
  
  <description("simple blog control.supports display " & _
  "of web log / news items from an xml file."), _
  designer("blogcontrol.blogdesigner"), _
  toolboxdata("<{0}:blog_dt runat=server></{0}:blog_dt>")> _
  public class blog_dt
  inherits panel
  implements inamingcontainer
  
  protected blogds as dataset
  protected titletb as textbox
  protected blogtext as textbox
  
  private _addredirect as string
  private _email as string
  private _mode as blogmode
  private _separatorcolor as color = color.black
  
  <browsable(true), _
  category("behavior"), _
  description("url to which the page should redirect after successful submission of a new blog entry."), _
  editor("system.web.ui.design.urleditor", _
  gettype(uitypeeditor))> _
  public property addredirect() as string
  get
  return me._addredirect
  end get
  set(byval value as string)
  me._addredirect = value
  end set
  end property
  
  <browsable(true), _
  category("behavior"), _
  description("email address the control will use for listing in new blog entries.")> _
  public property email() as string
  get
  return me._email
  end get
  set(byval value as string)
  me._email = value
  end set
  end property
  
  <browsable(true), _
  category("behavior"), _
  description("controls whether existing blogs are displayed, or fields for creating a new blog entry.")> _
  public property mode() as blogmode
  get
  return me._mode
  end get
  set(byval value as blogmode)
  me._mode = value
  end set
  end property
  
  <browsable(true), _
  category("appearance"), _
  description("controls the color of the line that separates blog entries when in display mode.")> _
  public property separatorcolor() as color
  get
  return me._separatorcolor
  end get
  set(byval value as color)
  me._separatorcolor = value
  end set
  end property
  
  protected overrides sub oninit(byval e as eventargs)
  loaddata()
  mybase.oninit(e)
  end sub
  
  protected overrides sub createchildcontrols()
  if not me._mode = blogmode.add then
  displayblogs()
  else
  newblog()
  end if
  end sub
  
  protected sub loaddata()
  blogds = new dataset()
  
  try
  blogds.readxml(page.server.mappath("blog.xml"))
  catch fnfex as filenotfoundexception
  createblankfile()
  loaddata()
  end try
  end sub
  
  protected sub displayblogs()
  dim blogdate as datetime
  dim currentdate as datetime = new datetime()
  
  dim blogrows as datarowcollection = _
  blogds.tables(0).rows
  dim blogdr as datarow
  for each blogdr in blogrows
  dim bdate as string = blogdr("date").tostring()
  blogdate = new datetime _
  (convert.toint32(bdate.substring(4, 4)), _
  convert.toint32(bdate.substring(0, 2)), _
  convert.toint32(bdate.substring(2, 2)))
  
  if not currentdate = blogdate then
  dim tempdate as label = new label()
  tempdate.text = blogdate.tolongdatestring()
  tempdate.font.size = fontunit.large
  tempdate.font.bold = true
  me.controls.add(tempdate)
  me.controls.add _
  (new literalcontrol("<br/><br/>"))
  currentdate = blogdate
  end if
  
  dim anchor as htmlanchor = new htmlanchor()
  anchor.name = "#" + blogdr("anchorid").tostring()
  me.controls.add(anchor)
  
  dim title as label = new label()
  title.text = blogdr("title").tostring()
  title.font.size = fontunit.larger
  title.font.bold = true
  me.controls.add(title)
  
  me.controls.add(new literalcontrol("<p>"))
  dim blogtext as literalcontrol = _
  new literalcontrol("<div>" & _
  blogdr("text").tostring() & "</div>")
  me.controls.add(blogtext)
  me.controls.add(new literalcontrol("</p>"))
  
  dim email as hyperlink = new hyperlink()
  email.navigateurl = "mailto:" & _
  blogdr("email").tostring()
  email.text = "e-mail me"
  me.controls.add(email)
  
  me.controls.add(new literalcontrol(" "))
  dim anchorlink as hyperlink = new hyperlink()
  anchorlink.navigateurl = _
  page.request.url.tostring() & "#" & _
  blogdr("anchorid").tostring()
  anchorlink.text = "link"
  me.controls.add(anchorlink)
  
  me.controls.add _
  (new literalcontrol("<hr color='" & _
  colortranslator.tohtml(_separatorcolor) & _
  "' width='100%'/><br/>"))
  next
  end sub
  
  protected sub newblog()
  dim title as label = new label()
  title.text = "create new blog"
  title.font.size = fontunit.larger
  title.font.bold = true
  me.controls.add(title)
  
  me.controls.add(new literalcontrol("<br/><br/>"))
  
  dim titlelabel as label = new label()
  titlelabel.text = "title: "
  titlelabel.font.bold = true
  me.controls.add(titlelabel)
  titletb = new textbox()
  me.controls.add(titletb)
  
  me.controls.add(new literalcontrol("<br/>"))
  
  dim blogtextlabel as label = new label()
  blogtextlabel.text = "text: "
  blogtextlabel.font.bold = true
  me.controls.add(blogtextlabel)
  blogtext = new textbox()
  blogtext.textmode = textboxmode.multiline
  blogtext.rows = 10
  blogtext.columns = 40
  me.controls.add(blogtext)
  
  me.controls.add(new literalcontrol("<br/>"))
  
  dim submit as button = new button()
  submit.text = "submit"
  addhandler submit.click, addressof me.submit_click
  me.controls.add(submit)
  end sub
  
  protected sub submit_click(byval sender as object, _
  byval e as eventargs)
  ensurechildcontrols()
  addblog()
  end sub
  
  protected sub addblog()
  dim newblogdr as datarow
  newblogdr = blogds.tables(0).newrow()
  newblogdr("date") = formatdate(datetime.today)
  newblogdr("title") = titletb.text
  newblogdr("text") = blogtext.text
  newblogdr("anchorid") = guid.newguid().tostring()
  newblogdr("email") = _email
  blogds.tables(0).rows.insertat(newblogdr, 0)
  blogds.writexml(page.server.mappath("blog.xml"))
  page.response.redirect(_addredirect)
  end sub
  
  protected function formatdate(byval dt as datetime) as string
  dim retstring as string
  retstring = string.format("{0:d2}", dt.month)
  retstring &= string.format("{0:d2}", dt.day)
  retstring &= string.format("{0:d2}", dt.year)
  return retstring
  end function
  
  public sub createblankfile()
  dim newxml as streamwriter = _
  file.createtext(page.server.mappath("blog.xml"))
  
  newxml.writeline("<blogs>")
  newxml.writeline _
  (" <!-- blog field describes a single blog -->")
  newxml.writeline(" <blog>")
  newxml.writeline(" <!-- date field contains" & _
  " the creation date of the blog -->")
  newxml.writeline(" <date>" & _
  formatdate(datetime.today) & "</date>")
  newxml.writeline _
  (" <title>temporary blog</title>")
  newxml.writeline(" <!-- text field " & _
  "should contain the blog text, including any " & _
  "desired html tags -->")
  newxml.writeline(" <text>this entry " & _
  "indicates that the file blog.xml was not " & _
  "found.a default version of this file has " & _
  "been created for you.you can modify the " & _
  "fields in this file as desired.if you set " & _
  "the blog control to add mode (add the " & _
  "attribute mode='add' to the control's " & _
  "declaration), the control will " & _
  "automatically populate the xml file when " & _
  "you submit the form.</text>")
  newxml.writeline(" <!-- anchorid field " & _
  "will be autopopulated by the control -->")
  newxml.writeline(" <anchorid></anchorid>")
  newxml.writeline(" <!-- email field should" & _
  " contain the email address for feedback -->")
  newxml.writeline(" <email>change this to a " & _
  "valid email address</email>")
  newxml.writeline(" </blog>")
  newxml.writeline("</blogs>")
  newxml.close()
  end sub
  
  end class
  
  public class blogdesigner
  inherits controldesigner
  
  public overrides function getdesigntimehtml() as string
  return "<h1>blog</h1><hr/><hr/>"
  end function
  
  end class
  
    


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons