概要
cscの作法、調べてみた。
bginfo、書いてみた。
環境
windows10
写真
サンプルコード
using System;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BgInfoFormApp
{
public partial class Form1: Form {
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_NOACTIVATE = 0x0010;
private Label lblInfo;
public Form1() {
this.Text = "BgInfo";
this.BackColor = Color.Magenta;
this.Width = 500;
this.Height = 200;
Rectangle screenRect = Screen.PrimaryScreen.WorkingArea;
this.Location = new Point(screenRect.Width - this.Width - 20, screenRect.Height - this.Height - 20);
lblInfo = new Label {
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 13, FontStyle.Bold),
BackColor = Color.Transparent
};
this.Controls.Add(lblInfo);
string hostName = Dns.GetHostName();
string ipAddress = "N/A";
foreach (var ip in Dns.GetHostAddresses(hostName))
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
ipAddress = ip.ToString();
break;
}
}
lblInfo.Text = string.Format("Host Name: {0}\n", hostName) + string.Format("IP Address: {0}\n", ipAddress) +
string.Format("OS Version: {0}\n", Environment.OSVersion.VersionString) + string.Format("User Name: {0}\n", Environment.UserName) +
string.Format("Update Time: {0}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
}
[STAThread]
public static void Main() {
Application.Run(new Form1());
}
}
}
以上。
