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


    分享一款自己制作的小工具。功能很简单,就是点击按钮打开指定网页,同时记录点击次数、时间、当前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

  • 相关阅读:
    commons-fileupload源码学习心得
    commons-io源码阅读心得
    java反射机制
    构建简单的socket连接池
    maven主仓库中找不到restlet的解决办法
    修改eclipse中web项目的server部署路径
    Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project '项目名'
    JVM中的Stack和Heap
    JVM工作原理和特点
    spring mvc 3.1的自动注入参数遇到的问题
  • 原文地址:https://www.cnblogs.com/Birdmafly/p/3616904.html
Copyright © 2020-2023  润新知