实现右下角弹窗效果和发送邮件的功能

分享一款自己制作的小工具。功能很简单,就是点击按钮打开指定网页,同时记录点击次数、时间、当前ip地址。

界面用DotNetBar来美化,使用时直接导入dll文件即可。

软件启动时自下向上慢慢浮现,主要使用了Animatewindow函数来实现这种效果。

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Runtime.InteropServices;
 10 using System.Net;
 11 using DevComponents.DotNetBar;
 12 using System.Net.Mail;
 13 
 14 namespace visit
 15 {
 16     public partial class Form1 : Form
 17     {
 18         string hostname;
 19         IPHostEntry localhost;
 20         IPAddress localIPaddr;
 21 
 22         [DllImport("user32")]
 23         private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
 24         //下面是可用的常量,根据不同的动画效果声明自己需要的   
 25         private const int AW_HOR_POSITIVE = 0x0001;//自左向右显示窗口   
 26         private const int AW_HOR_NEGATIVE = 0x0002;//自右向左显示窗口  
 27         private const int AW_VER_POSITIVE = 0x0004;//自顶向下显示窗口  
 28         private const int AW_VER_NEGATIVE = 0x0008;//自下向上显示窗口
 29         private const int AW_CENTER = 0x0010;//若使用了AW_HIDE标志,则使窗口向内重叠;否则向外扩展   
 30         private const int AW_HIDE = 0x10000;//隐藏窗口   
 31         private const int AW_ACTIVE = 0x20000;//激活窗口,在使用了AW_HIDE标志后不要使用这个标志   
 32         private const int AW_SLIDE = 0x40000;//使用滑动类型动画效果,默认为滚动动画类型,当使用AW_CENTER标志时,这个标志就被忽略   
 33         private const int AW_BLEND = 0x80000;//使用淡入淡出效果
 34         public Form1()
 35         {
 36             InitializeComponent();
 37             //label1.Text = "软件正在运行中...";
 38             //label2.Text = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]";
 39             hostname = Dns.GetHostName();
 40             localhost = Dns.GetHostByName(hostname);
 41             localIPaddr = localhost.AddressList[0];
 42             label3.Text = hostname;
 43             label6.Text = localIPaddr.ToString();
 44         }
 45         
 46         private void Form1_Load(object sender, EventArgs e)
 47         {
 48             int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
 49             int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
 50             this.Location = new Point(x, y);//设置窗体在屏幕右下角显示   
 51             AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVE | AW_VER_NEGATIVE);
 52         }
 53         int count = 0;
 54         List<string> str = new List<string>();
 55 
 56         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 57         {
 58             AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);
 59         }
 60 
 61         private void buttonX1_Click(object sender, EventArgs e)
 62         {
 63             count++;
 64             str.Add("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "已成功搜索了" + count + "");
 65             System.Diagnostics.Process.Start("www.baidu.com");
 66             richTextBox1.Lines = str.ToArray();
 67             textBox2.Text = count.ToString();
 68         }
 69 
 70         private void expandablePanel1_ExpandedChanged(object sender, ExpandedChangeEventArgs e)
 71         {
 72             if (expandablePanel1.Expanded == false)
 73             {
 74                 richTextBox1.Visible = true;
 75             }
 76             else
 77             {
 78                 richTextBox1.Visible = false;
 79             }
 80         }
 81 
 82         private void buttonX2_Click(object sender, EventArgs e)
 83         {
 84             MailMessage mmsg = new MailMessage();
 85             string sendAddress = textBoxX2.Text.ToString().Trim();
 86             string password = textBoxX4.Text.ToString().Trim();
 87             string receivedAddress = textBoxX1.Text.ToString().Trim();
 88             string mailBody = textBoxX3.Text.ToString().Trim();
 89             mmsg.To.Add(receivedAddress);  //接收邮箱
 90             mmsg.From = new MailAddress(sendAddress, "visitor",System.Text.Encoding.UTF8);  //发送邮箱
 91             mmsg.Subject = "ss";
 92             mmsg.Body = mailBody;//邮件正文
 93             mmsg.BodyEncoding = Encoding.UTF8;//正文编码
 94             mmsg.IsBodyHtml = true;//设置为HTML格式           
 95             mmsg.Priority = MailPriority.High;//优先级
 96 
 97             SmtpClient client = new SmtpClient();   //设置邮件协议
 98             client.Host = "smtp.163.com";
 99             client.UseDefaultCredentials = false;
100             client.Credentials = new NetworkCredential(sendAddress, password);
101             client.DeliveryMethod = SmtpDeliveryMethod.Network;
102             try
103             {
104                 client.Send(mmsg);
105                 MessageBox.Show("Send Success!");
106                 textBoxX4.Text = "";
107             }
108             catch(System.Net.Mail.SmtpException ex)
109             {
110                 MessageBox.Show(ex.Message,"Send Fail!");
111             }
112         }
113 
114         private void buttonX4_Click(object sender, EventArgs e)
115         {
116             Application.Exit();
117         }  
118     }
119 }
View Code

转载于:https://www.cnblogs.com/Birdmafly/p/3616904.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在frameset框架上实现右下角弹窗,可以按照以下步骤进行操作: 1. 在frameset框架中添加一个子框架,用于显示弹窗内容。 2. 在父框架中添加一个按钮或链接,用于触发弹窗。 3. 通过CSS样式设置子框架的位置,使其显示在页面的右下角。 4. 编写JavaScript代码,在点击按钮或链接时显示子框架,点击弹窗以外的区域时隐藏子框架。 以下是具体的实现步骤: 1. 在frameset框架中添加一个子框架: ```html <frameset rows="*,30" frameborder="0"> <frame src="content.html" name="contentFrame"> <frame src="popup.html" name="popupFrame"> </frameset> ``` 上面的代码中,frameset框架中包含两个子框架,分别是名为"contentFrame"和"popupFrame"的框架,其中"contentFrame"用于显示页面内容,"popupFrame"用于显示弹窗内容。 2. 在父框架中添加一个按钮或链接,用于触发弹窗: ```html <a href="#" onclick="showPopup();">弹窗</a> ``` 上面的代码中,我们添加了一个链接,当用户点击链接时会触发名为"showPopup()"的JavaScript函数,用于显示弹窗。 3. 通过CSS样式设置子框架的位置,使其显示在页面的右下角: ```css frame[name="popupFrame"] { position: fixed; right: 20px; bottom: 20px; width: 200px; height: 100px; border: 1px solid #ccc; display: none; } ``` 上面的代码中,我们通过CSS样式设置了名为"popupFrame"的子框架的位置,将它固定在页面的右下角,设置了它的宽度、高度和边框样式,并将它的显示方式设置为"none",即初始时不显示。 4. 编写JavaScript代码,在点击按钮或链接时显示子框架,点击弹窗以外的区域时隐藏子框架: ```javascript function showPopup() { var popupFrame = window.frames['popupFrame']; popupFrame.style.display = 'block'; } document.onclick = function(event) { var popupFrame = window.frames['popupFrame']; if (event.target != popupFrame) { popupFrame.style.display = 'none'; } } ``` 上面的代码中,我们定义了名为"showPopup()"的函数,用于显示子框架。当用户点击弹窗以外的区域时,会触发"document.onclick"事件,用于隐藏子框架。注意,在这里我们不能直接通过"popupFrame.style.display = 'none'"来隐藏子框架,因为如果用户直接点击子框架上的内容,也会触发"document.onclick"事件,导致子框架无法正常显示。因此,我们需要通过"event.target"来判断用户是否点击了子框架上的内容,从而决定是否隐藏子框架。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值