为什么DialogResult里面没有OK选项啊

qq_26880613 2015-07-24 11:26:36

第一次写C++/CL,不知道为什么找不到DialogResult.OK,求大神指教,或者说有其他方法吗?
...全文
2528 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你只这只显示了System全名空间下Enum的成员 在顶上加上using System.Windows.Forms;
yahle 2016-06-16
  • 打赏
  • 举报
回复
加命名空间试试
DevExpress打印相关代码 using System; using System.Windows.Forms; using DevExpress.XtraPrinting; using System.Xml.Serialization; namespace MyDevExpressDemo { /// /// PrintSettingController 的摘要说明。 /// public class PrintSettingController { PrintingSystem ps = null; string formName=null; DevExpress.XtraPrinting.PrintableComponentLink link=null; /// /// /// /// 要打印的部件 /// 此部件对应的布局信息 public PrintSettingController(IPrintable control,string FormName) { formName=FormName; ps=new DevExpress.XtraPrinting.PrintingSystem(); link=new DevExpress.XtraPrinting.PrintableComponentLink(ps); ps.Links.Add(link); link.Component=control; ps.PageSettingsChanged-=new EventHandler(ps_PageSettingsChanged); LoadPageSetting(); ps.PageSettingsChanged+=new EventHandler(ps_PageSettingsChanged); ps.AfterMarginsChange+=new MarginsChangeEventHandler(ps_AfterMarginsChange); } public void Preview() { try { if(DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable) { Cursor.Current=Cursors.AppStarting; if(_PrintHeader!=null) { PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter; phf.Header.Content.Clear(); phf.Header.Content.AddRange(new string[] {"",_PrintHeader,""}); phf.Header.Font=new System.Drawing.Font("宋体",14,System.Drawing.FontStyle.Bold); phf.Header.LineAlignment=BrickAlignment.Center; } link.PaperKind=ps.PageSettings.PaperKind; link.Margins=ps.PageSettings.Margins; link.Landscape=ps.PageSettings.Landscape; link.CreateDocument(); ps.PreviewForm.Show(); } else { Cursor.Current=Cursors.Default; MessageBox.Show("打印机不可用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { Cursor.Current=Cursors.Default; } } /// /// 打印控制器 /// /// 要打印的部件 public PrintSettingController(IPrintable control) { if(control==null)return; Control c=(Control)control; formName=c.FindForm().GetType().FullName+"."+c.Name; ps=new DevExpress.XtraPrinting.PrintingSystem(); link=new DevExpress.XtraPrinting.PrintableComponentLink(ps); ps.Links.Add(link); link.Component=control; ps.PageSettingsChanged-=new EventHandler(ps_PageSettingsChanged); LoadPageSetting(); ps.PageSettingsChanged+=new EventHandler(ps_PageSettingsChanged); ps.AfterMarginsChange+=new MarginsChangeEventHandler(ps_AfterMarginsChange); } public void ExportToHtml() { try { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出HTML文件"; fd.RestoreDirectory=true; fd.Filter="HTML文件|*.htm"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { // if(obj is DevExpress.XtraGrid.GridControl) // { // ((DevExpress.XtraGrid.GridControl)obj).ExportToHtml(fd.FileName); // MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } // else if(obj is DevExpress.XtraTreeList.TreeList) // { link.CreateDocument(); ps.ExportToHtml(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } } } } finally { } } /// /// 网格分组时要导出,请使用这个, /// public void GridGroupToExcel() { DevExpress.XtraGrid.GridControl grid=this.link.Component as DevExpress.XtraGrid.GridControl; if(grid!=null) { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出Excel文件"; fd.RestoreDirectory=true; fd.Filter="Excel文件|*.xls"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { grid.ExportToExcel(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } } public void ExportToExcel() { try { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出Excel文件"; fd.RestoreDirectory=true; fd.Filter="Excel文件|*.xls"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { // if(obj is DevExpress.XtraGrid.GridControl) // { // ((DevExpress.XtraGrid.GridControl)obj).ExportToExcel(fd.FileName); // MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } // else if(obj is DevExpress.XtraTreeList.TreeList) // { link.CreateDocument(); ps.ExportToXls(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } } } } finally { } } string _PrintHeader=null; /// /// 打印时的标题 /// public string PrintHeader { set { _PrintHeader=value; } } /// /// 进行打印 /// public void Print() { try { if(DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable) { if(_PrintHeader!=null) { PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter; phf.Header.Content.Clear(); phf.Header.Content.AddRange(new string[] {"",_PrintHeader,""}); phf.Header.Font=new System.Drawing.Font("宋体",14,System.Drawing.FontStyle.Bold); phf.Header.LineAlignment=BrickAlignment.Center; } link.PaperKind=ps.PageSettings.PaperKind; link.Margins=ps.PageSettings.Margins; link.Landscape=ps.PageSettings.Landscape; link.CreateDocument(); link.CreateDocument(); ps.Print(); } else { Cursor.Current=Cursors.Default; MessageBox.Show("打印机不可用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { } } private void ps_AfterMarginsChange(object sender, MarginsChangeEventArgs e) { SavePageSetting(); } private void ps_PageSettingsChanged(object sender, EventArgs e) { SavePageSetting(); } //获取页面设置信息 void LoadPageSetting() { try { string path=System.Windows.Forms.Application.StartupPath+"\\PrintLayout"; if(!System.IO.Directory.Exists(path)) { return; } path+="\\"+formName+".xml"; if(!System.IO.File.Exists(path)) { return; } XmlSerializer ser=new XmlSerializer(typeof(UserPageSetting)); UserPageSetting setting=(UserPageSetting)ser.Deserialize(new System.IO.FileStream(path,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.ReadWrite)); System.Drawing.Printing.Margins m=new System.Drawing.Printing.Margins(setting.Left,setting.Right,setting.Top,setting.Bottom); ps.PageSettings.Assign(m,(System.Drawing.Printing.PaperKind)setting.PaperKind,setting.Landscape); } catch{} } /// /// 保存当前网格的布局 /// void SavePageSetting() { try { string path=System.Windows.Forms.Application.StartupPath+"\\PrintLayout"; if(!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path+="\\"+formName+".xml"; DevExpress.XtraPrinting.XtraPageSettings setting= ps.PageSettings; UserPageSetting s=new UserPageSetting(); s.Landscape=setting.Landscape; s.Left=setting.Margins.Left; s.Right=setting.Margins.Right; s.Top=setting.Margins.Top; s.Bottom=setting.Margins.Bottom; s.PaperKind=(int)setting.PaperKind; XmlSerializer ser=new XmlSerializer(s.GetType()); ser.Serialize(new System.IO.FileStream(path,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.ReadWrite),s); } catch{} } } /// /// 最终用户对某个打印页的设置 /// [Serializable()] public class UserPageSetting { public UserPageSetting() { } public bool Landscape; public int PaperKind; public int Top; public int Bottom; public int Left; public int Right; } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace MyQQ2010 { public partial class MusicForm : Form { public MusicForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //打开文件夹选项 OpenFileDialog f = new OpenFileDialog(); //设置能够选中的多个选项 f.Multiselect = true; //弹出文件对话框 DialogResult result = f.ShowDialog(); if ( DialogResult.OK==result) { //获取选中的歌曲的路径 string[] music = f.FileNames; //将歌曲添加到ListBox中 foreach (string item in music) { this.lstMusic.Items.Add(item); } } } //双击播放歌曲 private void lstmusic2_DoubleClick(object sender, EventArgs e) { //获取选中的歌曲 string music = this.lstmusic2.SelectedItem.ToString(); //播放歌曲 Player.URL = music; } private void 添加到播放列表ToolStripMenuItem_Click_1(object sender, EventArgs e) { if (this.lstMusic.SelectedItems.Count == 0) { MessageBox.Show("请选中你要选中的歌曲"); return; } else { //获取选中的歌曲 string music = this.lstMusic.SelectedItem.ToString(); //把选中的歌曲移动到播放列表中 this.lstmusic2.Items.Add(music); //从lstmusic中移除 this.lstMusic.Items.Remove(music); } } private void 删除音乐ToolStripMenuItem_Click_1(object sender, EventArgs e) { if (this.lstMusic.SelectedItems.Count == 0) { MessageBox.Show("请选中你要删除的歌曲"); } else { //获取选中的歌曲 string music = this.lstMusic.SelectedItem.ToString(); //把选中的歌曲删除掉 this.lstMusic.Items.Remove(music); } } private void 从列表中移除ToolStripMenuItem_Click_1(object sender, EventArgs e) { if (this.lstmusic2.SelectedItems.Count == 0) { MessageBox.Show("请选中你要删除的歌曲"); } else { //获取选中的歌曲 string music = this.lstmusic2.SelectedItem.ToString(); //把选中的歌曲删除 this.lstmusic2.Items.Remove(music); } } private void MusicForm_Load_1(object sender, EventArgs e) { //播放顺序默认为列表播放 this.cboPlayOrder.SelectedIndex = 0; this.trm1.Start(); } private void trm1_Tick(object sender, EventArgs e) { //判断歌曲播放的顺序 if (Player.playState == WMPLib.WMPPlayState.wmppsStopped) { if (this.cboPlayOrder.Text == "列表播放") { if (this.lstmusic2.SelectedIndex < this.lstmusic2.Items.Count - 1) { this.lstmusic2.SelectedIndex++; this.lstMusic.Items.Add(this.lstmusic2.SelectedItem.ToString()); Player.URL = this.lstmusic2.SelectedItem.ToString(); } else { this.lstmusic2.SelectedIndex = 0; Player.URL = this.lstmusic2.SelectedItem.ToString(); } } else if (this.cboPlayOrder.Text == "随机播放") { Random r = new Random(); int index = r.Next(0, this.lstmusic2.Items.Count - 1); this.lstmusic2.SelectedIndex = index; string item = this.lstmusic2.SelectedItem.ToString(); this.lstMusic.Items.Add(item);//随机播放的歌曲也要在lbmusic2中显示 Player.URL = item; } else { int index = this.lstmusic2.SelectedIndex; Player.URL = this.lstmusic2.SelectedItem.ToString(); } } } } }
没法下载,到这里折腾一把试试。 本文由abc2253130贡献 doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。 C#(WINFORM)学习 一、 C#基础 基础 类型和变量 类型和变量 类型 C# 支持两种类型:“值类型”和“引用类型”。值类型包括简单类型(如 char、int 和 float 等)、枚举类型和结构类型。引用类型包括类 (Class)类 型、接口类型、委托类型和数组类型。 变量的类型声明 变量的类型声明 每个变量必须预先声明其类型。如 int a; int b = 100; float j = 4.5; string s1; 用 object 可以表示所有的类型。 预定义类型 下表列出了预定义类型,并说明如何使用。 类型 object 说明 所有其他类型的最终 基类型 字符串类型; 字符串是 Unicode 字符序列 8 位有符号整型 16 位有符号整型 32 位有符号整型 64 位有符号整型 示例 object o = null; 范围 string sbyte short int long string s = "hello"; sbyte val = 12; short val = 12; int val = 12; long val1 = 12; -128 到 127 -32,768 到 32,767 -2,147,483,648 2,147,483,647 -9,223,372,036,854,775,808 到 第1页 C#(WINFORM)学习 long val2 = 34L; 到 9,223,372,036,854,775,807 byte ushort 8 位无符号整型 16 位无符号整型 byte val1 = 12; ushort val1 = 12; uint val1 = 12; uint 32 位无符号整型 uint val2 = 34U; ulong val1 = 12; ulong val2 = 34U; ulong 64 位无符号整型 ulong val3 = 56L; ulong val4 = 78UL; float 单精度浮点型 float val = 1.23F;7 位 double val1 = 1.23; double 双精度浮点型 double val2 = ±5.0 × 10?324 ±1.7 × 10 308 0 到 255 0 到 65,535 0 到 4,294,967,295 0 到 18,446,744,073,709,551,615 ±1.5 × 10?45 ±3.4 × 10 38 到 到 4.56D;15-16 布尔型;bool 值或为 真或为假 字符类型;char 值是 一个 Unicode 字符 精确的小数类型, 具有 28 个有效数字 bool val1 = true; bool val2 = false; char val = 'h'; decimal val = bool char decimal DateTime ±1.0 × 10?28 ±7.9 × 10 28 到 1.23M;28-29 变量转换 简单转换: float f = 100.1234f; 可以用括号转换: short s = (short)f 也可以利用 Convert 方法来转换: string s1; s1=Convert.ToString(a); MessageBox.Show(s1); 常用 Convert 方法有: 第2页 C#(WINFORM)学习 C# Convert.ToBoolean Convert.ToByte Convert.ToChar Convert.ToDateTime Convert.ToDecimal Convert.ToDouble Convert.ToInt16 Convert.ToInt32 Convert.ToInt64 Convert.ToSByte Convert.ToSingle Convert.ToString Convert.ToUInt16 Convert.ToUInt32 Convert.ToUInt64 备注 Math 类 常用科学计算方法: C# Math.Abs Math.Sqrt Math.Ro
设置窗体的代码解释 Imports System.Diagnostics Public Class 设置窗体 Private shutTime As String '关机时间的字符串 Private IsToday As Boolean = True '判断是否是今天的变量 Private delay As Integer '延时多少秒放关机 Private lastTime As Integer '关机的倒计时 Private action As String '关机或重启或注销 Private shellText As String '执行的命令字符串 Private firstShow As Boolean = True Private SysTime As Boolean = False Private autoHide As Boolean = True '启动自动隐藏 Private TotalData As New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes Total/sec", "MS TCP Loopback interface") Private proTime As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total") '双击右下角的图标的响应事件 Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick If (Me.Visible = False) Then Me.Show() End If End Sub '重载窗体的关闭事件,使窗体隐藏 Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing e.Cancel = True '取消窗体的关闭动作 delayTime.Value = delay '还原delayTime控件的值 StrToItems() '还原ListBox的值 Me.Hide() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.SelectedIndex = 2 '设置默认选项 "每天" ComboBox2.SelectedIndex = 4 '设置默认选项 "关机" Timer1.Start() readReg() '读取存放在注册表的信息 StrToItems() '把字符串的信息读取到ListBox delayTime.Value = delay '把延时时间读取到delayTime控件 DateTimePicker1.Value = Today End Sub Private Sub 退出程序ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出程序ToolStripMenuItem.Click Me.Dispose() End Sub Private Sub 立即取消关机ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即取消关机ToolStripMenuItem1.Click Timer2.Stop() 取消窗体.Close() Shell("shutdown -a") Timer1.Start() End Sub Private Sub 设置关机计划ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 设置关机计划ToolStripMenuItem.Click If Me.Visible = False Then Me.Show() End If End Sub '点击确定按钮的事件处理 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click '判断是否要开机自动运行 If autoCheck.Checked Then 创建开机自动运行() Else 删除开机自动运行() End If If Me.HideCheck.Checked Then autoHide = True Else autoHide = False End If If Me.regCheck.Checked Then 禁止修改注册表() Else 取消禁止修改注册表() End If If Me.ManCheck.Checked Then 禁止使用任务管理器() Else 取消禁止使用任务管理器() End If If Me.SysTimeCheck.Checked Then SysTime = True Else SysTime = False End If '四舍五入delayTime控件的值 delay = Math.Round(delayTime.Value, MidpointRounding.AwayFromZero) Me.Hide() ItemsToStr() '把listBox的信息保存到字符串中 writeReg() '把字符串保存把注册表中 End Sub '取消按钮事件 Private Sub canelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canelButton.Click StrToItems() '还原ListBox的值 delayTime.Value = delay '还原delayTime控件的值 Me.Hide() End Sub '点击添加按钮 Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click Dim tempStr As String = "" If ComboBox1.Items.Item(ComboBox1.SelectedIndex) = "指定日期" Then tempStr = DateTimePicker1.Value.ToShortDateString Else tempStr = ComboBox1.SelectedItem End If tempStr &= "," & CStr(Math.Round(hourNum.Value, MidpointRounding.AwayFromZero)) & ":" & CStr(Math.Round(minNum.Value, MidpointRounding.AwayFromZero)) & ":" & CStr(Math.Round(secNum.Value, MidpointRounding.AwayFromZero)) & "," Select Case ComboBox2.SelectedItem Case "打开网址" tempStr &= "打开网址" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case "提醒信息" tempStr &= "提醒信息" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case "打开文件" tempStr &= "打开文件" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case Else tempStr &= ComboBox2.SelectedItem End Select ListBox1.Items.Add(tempStr) End Sub '点击清除按钮 Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click ListBox1.Items.Clear() End Sub '把ListBox的值保存到字符串ShutTime Private Sub ItemsToStr() Dim i As Integer shutTime = "" For i = 0 To ListBox1.Items.Count - 1 '把ListBox中的各项连接到shutTime shutTime &= ListBox1.Items.Item(i) & ";" Next If shutTime "" Then '去除最后一个 ";" shutTime = Mid(shutTime, 1, shutTime.Length - 1) End If End Sub '把字符串ShutTime的值还原到ListBox Private Sub StrToItems() If shutTime "" Then '如果shutTime有保存信息 Dim temp() As String = shutTime.Split(";") 'temp字符串数组存放shutTime以";"分隔的各个字符子串 Dim t As String 't存放temp字符串数组的一项 ListBox1.Items.Clear() For Each t In temp If Not (Mid(t, 1, 2) = "今天" And Not IsToday) Then '如果今天还没过了 ListBox1.Items.Add(t) End If Next End If End Sub '读取注册表保存的信息 Private Sub readReg() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey Try key = Microsoft.Win32.Registry.LocalMachine subkey = key.OpenSubKey("SOFTWARE\AutoShutdown") shutTime = subkey.GetValue("time") delay = CInt(subkey.GetValue("delayTime")) autoHide = subkey.GetValue("autoHide") If (CStr(Today()) subkey.GetValue("day")) Then IsToday = False End If Catch ex As Exception shutTime = "" IsToday = True End Try End Sub Private Sub 禁止修改注册表() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("disableregistrytools", 1) End Sub Private Sub 取消禁止修改注册表() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("disableregistrytools", 0) End Sub Private Sub 禁止使用任务管理器() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("DisableTaskMgr", 1) End Sub Private Sub 取消禁止使用任务管理器() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("DisableTaskMgr", 0) End Sub '将需要保存的信息写入注册表 Private Sub writeReg() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\AutoShutdown") subkey.SetValue("time", shutTime) subkey.SetValue("day", CStr(Today())) subkey.SetValue("delayTime", CStr(delay)) subkey.SetValue("autoHide", autoHide) End Sub '点击删除按钮 Private Sub delButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delButton.Click Dim delIndex As Integer = ListBox1.SelectedIndex If delIndex -1 Then ListBox1.Items.RemoveAt(delIndex) End If End Sub '最小化窗体,这里指隐藏窗体 Private Sub 最小化ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 最小化ToolStripMenuItem.Click If Me.Visible = True Then StrToItems() delayTime.Value = delay Me.Hide() End If End Sub Private Sub 创建开机自动运行() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run") subkey.SetValue("定时自动关机", Application.ExecutablePath) End Sub Private Sub 删除开机自动运行() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) subkey.DeleteValue("定时自动关机") End Sub '关闭显示器 Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Const WM_SYSCOMMAND = &H112 Public Const SC_MONITORPOWER = &HF170 '关闭显示器 Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 'Timer1的Tick事件,来监视现在的时间是否应该关机或别的了 Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Static nowTime As Date = Now updataMsg() If SysTime Then If (Now nowTime) Then Today = nowTime TimeOfDay = nowTime End If End If nowTime = nowTime.AddSeconds(1) If (shutTime "") Then Dim temp1() As String = shutTime.Split(";") 'temp1字符串数组存放shutTime以";"分隔的各个字符子串 Dim temp2() As String, i As Integer 'temp2字符串数组存放temp1某项的字符串以","或":"分隔的字符子串 Dim TimeOut As Boolean = False 'TimeOut存放是否时间到了 For i = 0 To temp1.Length - 1 temp2 = temp1(i).Split(New Char() {",", ":"}) If IsTimeOut(temp2) Then '判断时间是否到了 TimeOut = True action = temp2(4) '是"关机","注销","重启" End If Next If TimeOut Then '如果时间到 Select Case Mid(action, 1, 4) '根据action肯定命令字符串 Case "关闭计算" shellText = "shutdown -s -f -t 0" Case "重启计算" shellText = "shutdown -r -f -t 0" Case "注销用户" shellText = "shutdown -l -f -t 0" Case "关闭显示" SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1) Exit Sub Case "锁定计算" shellText = "rundll32.exe user32.dll, LockWorkStation" Case "打开文件" System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":")) Exit Sub Case "提醒信息" MsgBox(Mid(action, 6, action.Length - 6), , "提醒信息") Exit Sub Case "打开网址" System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":")) Exit Sub End Select lastTime = delay '倒计时等于延时 Timer2.Start() '倒计时开始 取消窗体.Show() '倒计时窗口打开 Timer1.Stop() End If End If End Sub '判断时间是否到了 Private Function IsTimeOut(ByRef t() As String) As Boolean '如果时分秒都相等 If t(1) = CStr(Hour(Now())) And t(2) = CStr(Minute(Now()) And t(3) = Second(Now)) Then Select Case t(0) Case "每天" Return True Case "今天" Return True Case "每周二" If Weekday(Now) = FirstDayOfWeek.Tuesday Then Return True End If Case "每周六" If Weekday(Now) = FirstDayOfWeek.Saturday Then Return True End If Case "每周日" If Weekday(Now) = FirstDayOfWeek.Sunday Then Return True End If Case "每周三" If Weekday(Now) = FirstDayOfWeek.Wednesday Then Return True End If Case "每周四" If Weekday(Now) = FirstDayOfWeek.Thursday Then Return True End If Case "每周五" If Weekday(Now) = FirstDayOfWeek.Friday Then Return True End If Case "每周一" If Weekday(Now) = FirstDayOfWeek.Monday Then Return True End If Case "每周一至周五" If Weekday(Now) > FirstDayOfWeek.Sunday And Weekday(Now) < FirstDayOfWeek.Saturday Then Return True End If Case Else If (t(0) = Today.ToShortDateString) Then Return True End If End Select End If Return False End Function '刷新Msg控件 Private Sub updataMsg() Dim xingqi As String = "" Select Case Weekday(Now) Case 1 xingqi = "星期天" Case 2 xingqi = "星期一" Case 3 xingqi = "星期二" Case 4 xingqi = "星期三" Case 5 xingqi = "星期四" Case 6 xingqi = "星期五" Case 7 xingqi = "星期六" End Select msg.Text = "当前时间" & Now().ToLongDateString & " " & Now().ToLongTimeString & " " & xingqi & " CPU使用" & Format(proTime.NextValue, "#0") & "% 网速" & Format(TotalData.NextValue / 1024, "########0.00") & "KB/S" Me.NotifyIcon1.Text = msg.Text End Sub '倒计时处理事件 Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick If lastTime = 0 Then '如果时间到 Shell(shellText, AppWinStyle.Hide) 取消窗体.Label1.Text = "正在" & action Else 取消窗体.Label1.Text = "离" & action & "还有" & lastTime & "秒" '显示倒计时 lastTime -= 1 End If End Sub Private Sub 设置窗体_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown If autoHide Then Me.Hide() End If End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged Select Case ComboBox2.SelectedItem Case "打开网址" Button1.Visible = False TextBox1.Width = 299 TextBox1.Visible = True Case "提醒信息" Button1.Visible = False TextBox1.Width = 299 TextBox1.Visible = True Case "打开文件" Button1.Visible = True TextBox1.Width = 209 TextBox1.Visible = True Case Else Button1.Visible = False TextBox1.Visible = False End Select End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedItem = "指定日期" Then DateTimePicker1.Visible = True Else DateTimePicker1.Visible = False End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then TextBox1.Text = OpenFileDialog1.FileName End If End Sub Private Sub 立即关机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关机ToolStripMenuItem.Click Shell("shutdown -s -f -t 0") End Sub Private Sub 立即重启ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即重启ToolStripMenuItem.Click Shell("shutdown -r -f -t 0") End Sub Private Sub 立即注销ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即注销ToolStripMenuItem.Click Shell("shutdown -l -f -t 0") End Sub Private Sub 立即锁定计算机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即锁定计算机ToolStripMenuItem.Click Shell("rundll32.exe user32.dll, LockWorkStation") End Sub Private Sub 立即关闭显示器ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关闭显示器ToolStripMenuItem.Click SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1) End Sub Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked System.Diagnostics.Process.Start("http://lywang.5d6d.com/space-uid-1.html") End Sub End Class

1,978

社区成员

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

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