0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その645

0
Posted at

概要

cscの作法、調べてみた。
bginfo、書いてみた。

環境

windows10

写真

image.png

サンプルコード

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());
		}
	}
}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?