为什么我在Form里的MouseMove和MouseDown事件里写Application.Exit ();出现问题

imickey 2003-10-15 06:46:06
结果不是我想要的,程序总是一闪就关闭了,这个时候鼠标根本就没有操作,在Form里的KeyDown也是如此,不能达到预期的效果。
...全文
63 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoutiance 2003-10-21
  • 打赏
  • 举报
回复
屏保不是鼠标移动就推出的吗?
如果不想,就不要在MouseMove里加Application.Exit()
或者用个判断不就行了?
CodeSpirit 2003-10-21
  • 打赏
  • 举报
回复
居然有人用.net写屏保的,晕,很占cpu的
CodeSpirit 2003-10-21
  • 打赏
  • 举报
回复
晕,可以加一个延时阿,如果不加的话就太敏感了,而且mousemove时间一般会保存在buffer里面,所以有时候你明明运行了程序鼠标没有动,还是会激活mousemove

另外,好一点的屏保一定要注意,不是mousemove了就可以退出了,而应该是mouse非常大的move了才退出
imickey 2003-10-19
  • 打赏
  • 举报
回复
请问各位,有没有解决的办法呀?
ferrerocao 2003-10-19
  • 打赏
  • 举报
回复
我也试验过了,鼠标是一闪而过,不过在mousemove中写application.exit()是不怎么合理。
imickey 2003-10-17
  • 打赏
  • 举报
回复
就是做屏保的,网上有个关于用C#BUILDER做屏保的例子,我就是按照那篇文章写的,运行时候出错。
imickey 2003-10-16
  • 打赏
  • 举报
回复
代码很简单啊,就是建一个工程,然后就在窗口的MOUSEMOVE事件里写代码了:Application.Exit ();就这么简单
wideroad 2003-10-16
  • 打赏
  • 举报
回复
鼠标动了贝,要不然怎么会退出。你干吗要在mousemove事件里让程序退出,你不会想做屏保吧!
我不懂电脑 2003-10-16
  • 打赏
  • 举报
回复
MouseMove只要你手抖一抖鼠标就移动了。
baqiaoyang 2003-10-15
  • 打赏
  • 举报
回复
老兄,鼠标一定有操作,不然,程序怎退出,你再试一试.
changezhong 2003-10-15
  • 打赏
  • 举报
回复
代码拿出来看看
changezhong 2003-10-15
  • 打赏
  • 举报
回复
代码拿出来看看
Option Strict OnImports System.MathPublic Class MandelbrotForm Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code " Public Sub New() MyBase.New() ‘This call is required by the Windows Form Designer. InitializeComponent() ‘Add any initialization after the InitializeComponent() call End Sub ‘Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ‘Required by the Windows Form Designer Private components As System.ComponentModel.IContainer ‘NOTE: The following procedure is required by the Windows Form Designer ‘It can be modified using the Windows Form Designer. ‘Do not modify it using the code editor. Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents txtMin As System.Windows.Forms.TextBox Friend WithEvents txtMax As System.Windows.Forms.TextBox Friend WithEvents txtColorMin As System.Windows.Forms.TextBox Friend WithEvents txtColorMax As System.Windows.Forms.TextBox Friend WithEvents bttnMandelbrot As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents bttnViewPrevious As System.Windows.Forms.Button Friend WithEvents bttnViewNext As System.Windows.Forms.Button Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(MandelbrotForm)) Me.PictureBox1 = New System.Windows.Forms.PictureBox Me.bttnMandelbrot = New System.Windows.Forms.Button Me.bttnViewPrevious = New System.Windows.Forms.Button Me.bttnViewNext = New System.Windows.Forms.Button Me.txtMin = New System.Windows.Forms.TextBox Me.txtMax = New System.Windows.Forms.TextBox Me.txtColorMin = New System.Windows.Forms.TextBox Me.txtColorMax = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.Label5 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label Me.SuspendLayout() ‘ ‘PictureBox1 ‘ Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.PictureBox1.Location = New System.Drawing.Point(5, 97) Me.PictureBox1.Name = "PictureBox1" Me.PictureBox1.Size = New System.Drawing.Size(512, 512) Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage Me.PictureBox1.TabIndex = 0 Me.PictureBox1.TabStop = False ‘ ‘bttnMandelbrot ‘ Me.bttnMandelbrot.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.bttnMandelbrot.Location = New System.Drawing.Point(62, 4) Me.bttnMandelbrot.Name = "bttnMandelbrot" Me.bttnMandelbrot.Size = New System.Drawing.Size(399, 30) Me.bttnMandelbrot.TabIndex = 1 Me.bttnMandelbrot.Text = "New Fractal" ‘ ‘bttnViewPrevious ‘ Me.bttnViewPrevious.Image = CType(resources.GetObject("bttnViewPrevious.Image"), System.Drawing.Image) Me.bttnViewPrevious.Location = New System.Drawing.Point(3, 4) Me.bttnViewPrevious.Name = "bttnViewPrevious" Me.bttnViewPrevious.Size = New System.Drawing.Size(50, 30) Me.bttnViewPrevious.TabIndex = 3 ‘ ‘bttnViewNext ‘ Me.bttnViewNext.Image = CType(resources.GetObject("bttnViewNext.Image"), System.Drawing.Image) Me.bttnViewNext.Location = New System.Drawing.Point(470, 4) Me.bttnViewNext.Name = "bttnViewNext" Me.bttnViewNext.Size = New System.Drawing.Size(50, 30) Me.bttnViewNext.TabIndex = 4 ‘ ‘txtMin ‘ Me.txtMin.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.txtMin.Location = New System.Drawing.Point(61, 67) Me.txtMin.Name = "txtMin" Me.txtMin.Size = New System.Drawing.Size(46, 26) Me.txtMin.TabIndex = 6 Me.txtMin.Text = "0" ‘ ‘txtMax ‘ Me.txtMax.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.txtMax.Location = New System.Drawing.Point(165, 67) Me.txtMax.Name = "txtMax" Me.txtMax.Size = New System.Drawing.Size(46, 26) Me.txtMax.TabIndex = 7 Me.txtMax.Text = "128" ‘ ‘txtColorMin ‘ Me.txtColorMin.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.txtColorMin.Location = New System.Drawing.Point(336, 67) Me.txtColorMin.Name = "txtColorMin" Me.txtColorMin.Size = New System.Drawing.Size(46, 26) Me.txtColorMin.TabIndex = 9 Me.txtColorMin.Text = "0" ‘ ‘txtColorMax ‘ Me.txtColorMax.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.txtColorMax.Location = New System.Drawing.Point(451, 67) Me.txtColorMax.Name = "txtColorMax" Me.txtColorMax.Size = New System.Drawing.Size(46, 26) Me.txtColorMax.TabIndex = 10 Me.txtColorMax.Text = "512" ‘ ‘Label1 ‘ Me.Label1.Font = New System.Drawing.Font("Verdana", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label1.Location = New System.Drawing.Point(11, 41) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(121, 22) Me.Label1.TabIndex = 11 Me.Label1.Text = "Iterations" ‘ ‘Label2 ‘ Me.Label2.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label2.Location = New System.Drawing.Point(16, 72) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(39, 16) Me.Label2.TabIndex = 12 Me.Label2.Text = "Min" ‘ ‘Label3 ‘ Me.Label3.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label3.Location = New System.Drawing.Point(120, 72) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(46, 16) Me.Label3.TabIndex = 13 Me.Label3.Text = "Max" ‘ ‘Label4 ‘ Me.Label4.Font = New System.Drawing.Font("Verdana", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label4.Location = New System.Drawing.Point(285, 41) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(158, 22) Me.Label4.TabIndex = 14 Me.Label4.Text = "Color Range" ‘ ‘Label5 ‘ Me.Label5.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label5.Location = New System.Drawing.Point(293, 72) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(39, 16) Me.Label5.TabIndex = 15 Me.Label5.Text = "Min" ‘ ‘Label6 ‘ Me.Label6.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.Label6.Location = New System.Drawing.Point(402, 72) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(46, 16) Me.Label6.TabIndex = 16 Me.Label6.Text = "Max" ‘ ‘MandelbrotForm ‘ Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(524, 620) Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtColorMax) Me.Controls.Add(Me.txtColorMin) Me.Controls.Add(Me.txtMax) Me.Controls.Add(Me.txtMin) Me.Controls.Add(Me.bttnViewNext) Me.Controls.Add(Me.bttnViewPrevious) Me.Controls.Add(Me.bttnMandelbrot) Me.Controls.Add(Me.PictureBox1) Me.KeyPreview = True Me.Name = "MandelbrotForm" Me.Text = "Fractal Generator: The Mandelbrot Set" Me.ResumeLayout(False) End Sub#End Region Dim XMin As Double, XMax As Double Dim YMin As Double, YMax As Double Dim XStart, YStart As Integer Dim XEnd, YEnd As Integer Dim currentFractal As Integer Dim breaknow As Boolean Dim limits As New ArrayList Structure Bounding Dim XMin As Double Dim XMax As Double Dim YMin As Double Dim YMax As Double End Structure Private Sub bttnMandelbrot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnMandelbrot.Click Static IterMin As Integer = 100000 Dim IterMax As Integer = -100000 Dim bmap As Bitmap bmap = New Bitmap(512, 512, Drawing.Imaging.PixelFormat.Format32bppPArgb) PictureBox1.Image = bmap Dim pX, pY As Integer Dim NX As Integer = 512 Dim NY As Integer = 512 Dim MaxIter As Integer Dim X, Y As Double Dim Iterations As Integer Dim minIterations As Integer = CInt(txtMin.Text) Dim maxIterations As Integer = CInt(txtMax.Text) Dim colorMin As Integer Dim colorMax As Integer Dim pixelColor As Color If IsNumeric(txtColorMin.Text) Then colorMin = CInt(txtColorMin.Text) If IsNumeric(txtColorMax.Text) Then colorMax = CInt(txtColorMax.Text) If IsNumeric(txtMin.Text) Then minIterations = CInt(txtMin.Text) If IsNumeric(txtMax.Text) Then maxIterations = CInt(txtMax.Text) If maxIterations <= minIterations Then MsgBox("The number of maximum iterations should be larger " & _ "than the number of minimum iterations") Exit Sub End If If colorMax <= colorMin Then MsgBox("The first color‘s value should be smalled than the last color‘s value") Exit Sub End If For pY = 0 To NY - 1 Y = YMin + pY * (YMax - YMin) / (NY - 1) For pX = 0 To NX - 1 X = (XMin + pX * (XMax - XMin) / (NY - 1)) Iterations = Mandelbrot(X, Y, maxIterations) Dim clr As Integer clr = CInt(colorMin + _ (colorMax - colorMin) / (maxIterations - minIterations) * _ (Iterations - minIterations)) clr = Math.Max(minIterations, clr) pixelColor = PaintPixel(clr) bmap.SetPixel(pX, pY, pixelColor) Next PictureBox1.Invalidate() Application.DoEvents() If breaknow Then breaknow = False Exit Sub End If Next End Sub Private Function PaintPixel(ByVal clr As Integer) As Color Select Case clr Case 0 To 256 - 1 Return Color.FromArgb(clr, 0, 0) Case 256 To 256 * 2 - 1 Return Color.FromArgb(255, clr - 256, 0) Case 256 * 2 To 256 * 3 - 1 Return Color.FromArgb(255, 255, clr - 256 * 2) Case 256 * 3 To 256 * 4 - 1 Return Color.FromArgb(255, clr - 256 * 3, clr - 256 * 3) Case 256 * 4 To 256 * 5 - 1 Return Color.FromArgb(255, 256 * 5 - clr - 1, 255) Case 256 * 5 To 256 * 6 - 1 Return Color.FromArgb(clr - 256 * 5, clr - 256 * 5, clr - 256 * 5) Case Else Return Color.FromArgb(clr Mod 256, clr Mod 256, clr Mod 256) End Select End Function Function Mandelbrot(ByVal Cx As Double, ByVal Cy As Double, ByVal max As Integer) As Integer Dim iter As Integer Dim X2, Y2 As Double Dim X, Y As Double Dim temp As Double Dim currentBounds As Bounding currentBounds = CType(limits.Item(currentFractal), Bounding) XMin = currentBounds.XMin XMax = currentBounds.XMax YMin = currentBounds.YMin YMax = currentBounds.YMax While iter < max And (Sqrt(X2 * X2 + Y2 * Y2) < 100000) temp = X2 - Y2 + Cx Y = 2 * X * Y + Cy X = temp X2 = X * X Y2 = Y * Y * Y iter = iter + 1 End While Return (iter) End Function Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown XStart = e.X YStart = e.Y End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If e.Button <> MouseButtons.Left Then Exit Sub PictureBox1.Refresh() Dim newX, newY As Integer newX = e.X newY = e.Y If Math.Abs(newX - XStart) < Math.Abs(newY - YStart) Then newY = YStart + Math.Abs(newX - XStart) Else newX = XStart + Math.Abs(newY - YStart) End If PictureBox1.CreateGraphics.DrawRectangle(Pens.White, XStart, YStart, newX - XStart, newY - YStart) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load XMin = -1.5 : XMax = 0.5 YMin = -1 : YMax = 1 Dim currentBounds As Bounding currentBounds.XMin = XMin currentBounds.XMax = XMax currentBounds.YMin = YMin currentBounds.YMax = YMax limits.Add(currentBounds) End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp XEnd = e.X YEnd = e.Y If Math.Abs(XEnd - XStart) < Math.Abs(YEnd - YStart) Then YEnd = YStart + Math.Abs(XEnd - XStart) Else XEnd = XStart + Math.Abs(YEnd - YStart) End If Dim currentBounds As Bounding currentBounds = CType(limits.Item(currentFractal), Bounding) XMin = currentBounds.XMin XMax = currentBounds.XMax YMin = currentBounds.YMin YMax = currentBounds.YMax If XEnd <> 0 And YEnd <> 0 Then Dim DX, DY As Double DX = XMax - XMin DY = YMax - YMin Dim newXMin, newXMax, newYMin, newYMax As Double newXMin = XMin + DX * XStart / PictureBox1.Width newXMax = XMin + DX * XEnd / PictureBox1.Width newYMin = YMin + DY * YStart / PictureBox1.Height newYMax = YMin + DY * YEnd / PictureBox1.Height XMin = newXMin : XMax = newXMax YMin = newYMin : YMax = newYMax currentBounds.XMin = XMin currentBounds.XMax = XMax currentBounds.YMin = YMin currentBounds.YMax = YMax limits.Add(currentBounds) currentFractal = currentFractal + 1 End If End Sub Private Sub bttnViewNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnViewNext.Click Dim currentBounds As Bounding currentBounds.XMin = XMin currentBounds.XMax = XMax currentBounds.YMin = YMin currentBounds.YMax = YMax limits.Add(currentBounds) currentFractal += 1 If currentFractal <= limits.Count Then bttnMandelbrot_Click(sender, e) End If End Sub Private Sub bttnViewPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnViewPrevious.Click currentFractal = currentFractal - 1 If currentFractal >= 0 Then bttnMandelbrot_Click(sender, e) Else currentFractal = 0 End If End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp If e.KeyCode = Keys.Escape Then breaknow = True End If End SubEnd Class
Javascript小技巧一箩筐 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode event.shiftKey event.altKey event.ctrlKey 事件返回值 event.returnValue 鼠标位置 event.x event.y 窗体活动元素 document.activeElement 绑定事件 document.captureEvents(Event.KEYDOWN); 访问窗体元素 document.all("txt").focus(); document.all("txt").select(); 窗体命令 document.execCommand 窗体COOKIE document.cookie 菜单事件 document.oncontextmenu 创建元素 document.createElement("SPAN"); 根据鼠标获得元素: document.elementFromPoint(event.x,event.y).tagName=="TD document.elementFromPoint(event.x,event.y).appendChild(ms) 窗体图片 document.images[索引] 窗体事件绑定 document.onmousedown=scrollwindow; 元素 document.窗体.elements[索引] 对象绑定事件 document.all.xxx.detachEvent("onclick",a); 插件数目 navigator.plugins 取变量类型 typeof($js_libpath) == "undefined" 下拉框 下拉框.options[索引] 下拉框.options.length 查找对象 document.getElementsByName("r1"); document.getElementById(id); 定时 timer=setInterval("scrollwindow()",delay); clearInterval(timer); UNCODE编码 escape() ,unescape 父对象 obj.parentElement(dhtml) obj.parentNode(dom) 交换表的行 TableID.moveRow(2,1) 替换CSS document.all.csss.href = "a.css"; 并排显示 display:inline 隐藏焦点 hidefocus=true 根据宽度换行 style="word-break:break-all" 自动刷新 简单邮件 快速转到位置 obj.scrollIntoView(true) 锚 anchors 网页传递参数 location.search(); 可编辑 obj.contenteditable=true 执行菜单命令 obj.execCommand 双字节字符 /[^x00-xff]/ 汉字 /[u4e00-u9fa5]/ 让英文字符串超出表格宽度自动换行 word-wrap: break-word; word-break: break-all; 透明背景 获得style内容 obj.style.cssText HTML标签 document.documentElement.innerHTML 第一个style标签 document.styleSheets[0] style标签的第一个样式 document.styleSheets[0].rules[0] 防止点击空链接时,页面往往重置到页首端。 word 上一网页源 asp: request.servervariables("HTTP_REFERER") javascript: document.referrer 释放内存 CollectGarbage(); 禁止右键 document.oncontextmenu = function() { return false;} 禁止保存 mouseup="document.selection.empty()> 禁止粘贴 地址栏图标 favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下 收藏栏图标 查看源码 关闭输入法 自动全选 ENTER键可以让光标移到下一个输入框 文本框的默认值 title换行 obj.title = "123 sdfs " 获得时间所代表的微秒 var n1 = new Date("2004-10-10".replace(/-/g, "/")).getTime() 窗口是否关闭 win.closed checkbox扁平
获取选中内容 document.selection.createRange().duplicate().text 自动完成功能 打开该功能 关闭该功能 窗口最大化 无关闭按钮IE window.open("aa.htm", "meizz", "fullscreen=7"); 统一编码/解码 alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe"))) encodeURIComponent对":"、"/"、";" 和 "?"也编码 表格行指示 mouseover="this.bgColor="#f0f0f0"" onmouseout="this.bgColor="#ffffff""> //各种尺寸 s += " 网页可见区域宽:"+ document.body.clientWidth; s += " 网页可见区域高:"+ document.body.clientHeight; s += " 网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)"; s += " 网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)"; s += " 网页正文全文宽:"+ document.body.scrollWidth; s += " 网页正文全文高:"+ document.body.scrollHeight; s += " 网页被卷去的高:"+ document.body.scrollTop; s += " 网页被卷去的左:"+ document.body.scrollLeft; s += " 网页正文部分上:"+ window.screenTop; s += " 网页正文部分左:"+ window.screenLeft; s += " 屏幕分辨率的高:"+ window.screen.height; s += " 屏幕分辨率的宽:"+ window.screen.width; s += " 屏幕可用工作区高度:"+ window.screen.availHeight; s += " 屏幕可用工作区宽度:"+ window.screen.availWidth; //过滤数字 //特殊用途 //不缓存 //正则匹配匹配中文字符的正则表达式: [u4e00-u9fa5] 匹配双字节字符(包括汉字在内):[^x00-xff] 匹配空行的正则表达式: [s| ]* 匹配HTML标记的正则表达式:/<(.*)>.*|<(.*) />/ 匹配首尾空格的正则表达式:(^s*)|(s*$)(像vbscript那样的trim函数) 匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)* 匹配网址URL的正则表达式:http://([w-]+.)+[w-]+(/[w- ./?%&=]*)? 以下是例子: 利用正则表达式限制网页表单的文本框输入内容: 用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,"")" onbeforepaste="clipboardData.setData("text",clipboardData.getData("text").replace(/[^u4E00-u9FA5]/g,""))" 1.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,"")" onbeforepaste="clipboardData.setData("text",clipboardData.getData("text").replace(/[^uFF00-uFFFF]/g,""))" 2.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^d]/g,"") "onbeforepaste="clipboardData.setData("text",clipboardData.getData("text").replace(/[^d]/g,""))" 3.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[W]/g,"") "onbeforepaste="clipboardData.setData("text",clipboardData.getData("text").replace(/[^d]/g,""))" //消除图像工具栏 or //无提示关闭 function Close() { var ua=navigator.userAgent var ie=navigator.appName=="Microsoft Internet Explorer"?true:false if(ie) { var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE ")))) if(IEversion< 5.5) { var str = "" str += ""; document.body.insertAdjacentHTML("beforeEnd", str); document.all.noTipClose.Click(); } else { window.opener =null; window.close(); } } else { window.close() } } //取得控件得绝对位置(1) <script language="javascript"> function getoffset(e) { var t=e.offsetTop; var l=e.offsetLeft; while(e=e.offsetParent) { t+=e.offsetTop; l+=e.offsetLeft; } var rec = new Array(1); rec[0] = t; rec[1] = l; return rec } //光标停在文字最后 <script language="javascript"> function cc() { var e = event.srcElement; var r =e.createTextRange(); r.moveStart("character",e.value.length); r.collapse(true); r.select(); } //页面进入和退出的特效 进入页面 推出页面 这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使 用哪种特效,取值为1-23:   0 矩形缩小   1 矩形扩大   2 圆形缩小   3 圆形扩大   4 下到上刷新   5 上到下刷新   6 左到右刷新   7 右到左刷新   8 竖百叶窗   9 横百叶窗   10 错位横百叶窗   11 错位竖百叶窗   12 点扩散   13 左右到中间刷新   14 中间到左右刷新   15 中间到上下   16 上下到中间   17 右下到左上   18 右上到左下   19 左上到右下   20 左下到右上   21 横条   22 竖条   23 //网页是否被检索   其中属性值有以下一些:   属性值为"all": 文件将被检索,且页上链接可被查询;   属性值为"none": 文件不被检索,而且不查询页上的链接;   属性值为"index": 文件将被检索;   属性值为"follow": 查询页上的链接;   属性值为"noindex": 文件不检索,但可被查询链接;   属性值为"nofollow": //打印分页

page1

page2

//设置打印 <script language=javascript> function window.onload() { // -- advanced features factory.printing.SetMarginMeasure(2) // measure margins in inches factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3 factory.printing.printer = "HP DeskJet 870C" factory.printing.copies = 2 factory.printing.collate = true factory.printing.paperSize = "A4" factory.printing.paperSource = "Manual feed" // -- basic features factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页" factory.printing.footer = "(自定义页脚)" factory.printing.portrait = false factory.printing.leftMargin = 0.75 factory.printing.topMargin = 1.5 factory.printing.rightMargin = 0.75 factory.printing.bottomMargin = 1.5 } function Print(frame) { factory.printing.Print(true, frame) // print with prompt }
具体使用手册,更多信息,点这 //自带的打印预览 WebBrowser.ExecWB(1,1) 打开 Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口 Web.ExecWB(4,1) 保存网页 Web.ExecWB(6,1) 打印 Web.ExecWB(7,1) 打印预览 Web.ExecWB(8,1) 打印页面设置 Web.ExecWB(10,1) 查看页面属性 Web.ExecWB(15,1) 好像是撤销,有待确认 Web.ExecWB(17,1) 全选 Web.ExecWB(22,1) 刷新 Web.ExecWB(45,1) 关闭窗体无提示

//去掉打印时的页眉页脚 <script language="JavaScript"> var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root="HKEY_CURRENT_USER"; HKEY_Path="\Software\Microsoft\Internet Explorer\PageSetup\"; //设置网页打印的页眉页脚为空 function PageSetup_Null() { try { var Wsh=new ActiveXObject("WScript.Shell"); HKEY_Key="header"; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); HKEY_Key="footer"; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); } catch(e){} } //设置网页打印的页眉页脚为默认值 function PageSetup_Default() { try { var Wsh=new ActiveXObject("WScript.Shell"); HKEY_Key="header"; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); HKEY_Key="footer"; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d"); } catch(e){} } //浏览器验证 function checkBrowser() { this.ver=navigator.appVersion this.dom=document.getElementById?1:0 this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0; this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; this.ie4=(document.all && !this.dom)?1:0; this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.mac=(this.ver.indexOf("Mac") > -1) ?1:0; this.ope=(navigator.userAgent.indexOf("Opera")>-1); this.ie=(this.ie6 || this.ie5 || this.ie4) this.ns=(this.ns4 || this.ns5) this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope) this.nbw=(!this.bw) return this; } //计算内容宽和高 //无模式的提示框 function modelessAlert(Msg) { window.showModelessDialog("javascript:alert(""+escape(Msg)+"");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;"); } //屏蔽按键 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 <script language="Javascript"> //可编辑SELECT //设置光标位置 function getCaret(textbox) { var control = document.activeElement; textbox.focus(); var rang = document.selection.createRange(); rang.setEndPoint("StartToStart",textbox.createTextRange()) control.focus(); return rang.text.length; } function setCaret(textbox,pos) { try { var r =textbox.createTextRange(); r.moveStart("character",pos); r.collapse(true); r.select(); } catch(e) {} } function selectLength(textbox,start,len) { try { var r =textbox.createTextRange(); r.moveEnd("character",len-(textbox.value.length-start)); r.moveStart("character",start); r.select(); } catch(e) {//alert(e.description)} } function insertAtCaret(textbox,text) { textbox.focus(); document.selection.createRange().text = text; } //页内查找 function findInPage(str) { var txt, i, found,n = 0; if (str == "") { return false; } txt = document.body.createTextRange(); for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } if (found) { txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; } else { if (n > 0) { n = 0; findInPage(str); } else { alert(str + "... 您要找的文字不存在。 请试着输入页面中的关键字再次查找!"); } } return false; } //书 http://www.itpub.net/attachment.php?s=&postid=1894598 http://www.wrclub.net/down/listdown.aspx?id=1341//操作EXECL <script language="javascript"> function jStartExcel() { var xls = new ActiveXObject ( "Excel.Application" ); xls.visible = true; var newBook = xls.Workbooks.Add; newBook.Worksheets.Add; newBook.Worksheets(1).Activate; xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2; xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5; newBook.Worksheets(1).Columns("A").columnwidth=50; newBook.Worksheets(1).Columns("A").WrapText = true; newBook.Worksheets(1).Columns("B").columnwidth=50; newBook.Worksheets(1).Columns("B").WrapText = true; newBook.Worksheets(1).Range("A1:B1000").NumberFormat = "0"; newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment = -4131; newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15"; newBook.Worksheets(1).Cells(1,1).value="First Column, First Cell"; newBook.Worksheets(1).Cells(2,1).value="First Column, Second Cell"; newBook.Worksheets(1).Cells(1,2).value="Second Column, First Cell"; newBook.Worksheets(1).Cells(2,2).value="Second Column, Second Cell"; newBook.Worksheets(1).Name="My First WorkSheet"; } tip <script Language="JavaScript"> //***********默认设置定义.********************* tPopWait=50;//停留tWait豪秒后显示提示。 tPopShow=5000;//显示tShow豪秒后关闭提示 showPopStep=20; popOpacity=99; //***************内部变量定义***************** sPop=null; curShow=null; tFadeOut=null; tFadeIn=null; tFadeWaiting=null; document.write(""); document.write("
"); function showPopupText(){ var o=event.srcElement; MouseX=event.x; MouseY=event.y; if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""}; if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""}; if(o.dypop!=sPop) { sPop=o.dypop; clearTimeout(curShow); clearTimeout(tFadeOut); clearTimeout(tFadeIn); clearTimeout(tFadeWaiting); if(sPop==null || sPop=="") { dypopLayer.innerHTML=""; dypopLayer.style.filter="Alpha()"; dypopLayer.filters.Alpha.opacity=0; } else { if(o.dyclass!=null) popStyle=o.dyclass else popStyle="cPopText"; curShow=setTimeout("showIt()",tPopWait); } } } function showIt(){ dypopLayer.className=popStyle; dypopLayer.innerHTML=sPop; popWidth=dypopLayer.clientWidth; popHeight=dypopLayer.clientHeight; if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24 else popLeftAdjust=0; if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24 else popTopAdjust=0; dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust; dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust; dypopLayer.style.filter="Alpha(Opacity=0)"; fadeOut(); } function fadeOut(){ if(dypopLayer.filters.Alpha.opacity0) { dypopLayer.filters.Alpha.opacity-=1; tFadeIn=setTimeout("fadeIn()",1); } } document.onmouseover=showPopupText; 插入文字"); } } //netscapte下操作xml doc = new ActiveXObject("Msxml2.DOMDocument"); doc = new ActiveXObject("Microsoft.XMLDOM") ->> doc = (new DOMParser()).parseFromString(sXML,"text/xml") //判断键值 <script language="javascript"> var ie =navigator.appName=="Microsoft Internet Explorer"?true:false; function keyDown(e) { if(!ie) { var nkey=e.which; var iekey="现在是ns浏览器"; var realkey=String.fromCharCode(e.which); } if(ie) { var iekey=event.keyCode; var nkey="现在是ie浏览器"; var realkey=String.fromCharCode(event.keyCode); if(event.keyCode==32){realkey="" 空格""} if(event.keyCode==13){realkey="" 回车""} if(event.keyCode==27){realkey="" Esc""} if(event.keyCode==16){realkey="" Shift""} if(event.keyCode==17){realkey="" Ctrl""} if(event.keyCode==18){realkey="" Alt""} } alert("ns浏览器中键值:"+nkey+" "+"ie浏览器中键值:"+iekey+" "+"实际键为"+realkey); } document.onkeydown = keyDown; //Javascript Document.

请按任意一个键。。。。

//禁止FSO 1.注销组件 regsvr32 /u scrrun.dll 2.修改PROGID HKEY_CLASSES_ROOTScripting.FileSystemObject Scripting.FileSystemObject 3.对于使用object的用户,修改HKEY_CLASSES_ROOTScripting. //省略号
就是比如有一行文字,很长,表格内一行显示不下.
//检测media play版本 //图象按比例 <script language="JavaScript"> //细线SELECT function getComputerName() { var objWMIService = GetObject("Winmgmts:rootcimv2"); for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext()) { var getComputer = e.item(); return getComputer.Name; } } //条件编译 <script language=javascript> /*@cc_on @*/ /*@if (@_win32 && @_jscript_version>5) function window.confirm(str) { execScript("n = msgbox(""+ str +"", 257)", "vbscript"); return(n == 1); } @end @*/ //mergeAttributes 复制所有读/标签属性到指定元素。
mouseover="this.style.color="#0000FF";" onmouseout="this.style.color="#000000";" > This is a sample DIV element.
This is another sample DIV element.
以上内容可以随意转载,转载后请注名来源和出处! 原文链接:http://ttyp.cnblogs.com/archive/2004/11/15/63900.aspx //Import function Import() { for( var i=0; i"); else document.write(""); } }; //js枚举 function getComputerName() { var objWMIService = GetObject("Winmgmts:rootcimv2"); for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext()) { var getComputer = e.item(); return getComputer.Name; } } //条件编译 <script language=javascript> /*@cc_on @*/ /*@if (@_win32 && @_jscript_version>5) function window.confirm(str) { execScript("n = msgbox(""+ str +"", 257)", "vbscript"); return(n == 1); } @end @*/ //mergeAttributes 复制所有读/标签属性到指定元素。
mouseover="this.style.color="#0000FF";" onmouseout="this.style.color="#000000";" > This is a sample DIV element.
This is another sample DIV element.
电子书制作:源码爱好者

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧