Quantcast
Channel: プログラム の個人的なメモ
Viewing all 860 articles
Browse latest View live

【C#】【Form】 NotifyIcon ~ ポップアップ通知を行うには... ~

$
0
0

■ はじめに

https://blogs.yahoo.co.jp/dk521123/37826442.html
で、Javaでメッセージ通知したが、今度は、C#で実装する。

■ 注意事項

 * Icon を設定しないと、ポップアップ通知が表示されない。

■ 主なプロパティ

BalloonTipIcon

 * バルーンToolTipに関連付けるアイコン
  + None:表示しない
  + Info:インフォメーション
  + Warning:警告
  + Error:エラー

BalloonTipText

 * バルーンToolTipに関連付けるメッセージ

BalloonTipTitle

 * バルーンToolTipに関連付けるタイトル

■ サンプル

コントロール構成

 * button1
 * notifyIcon1
   + BalloonTipIcon : Info
   + BalloonTipText : テストです。
   + BalloonTipTitle : Hello World
   + Icon : アイコンファイル (「補足:アイコンファイルについて」参照)
 * contextMenuStrip1 (右クリックで表示するために必要)
   + Item : exitToolStripMenuItem を追加
補足:アイコンファイルについて
 * とりあえずでいいなら、
   [追加]-[新しい項目]-[Visual C#アイコン]-[アイコンファイル]で追加

コード

using System;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      this.notifyIcon1.ShowBalloonTip(500);
      this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
      Application.Exit();
    }
  }
}


関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

Java で Windows の メッセージ通知を行うには...

https://blogs.yahoo.co.jp/dk521123/37826442.html

【C#】画像処理 ~ 切り取り ~

$
0
0

【C#】タスクトレイにある常駐アプリの作成

$
0
0

■ ポイント

【1】 プロジェクトは、Windows Formのままでいい

■ サンプルコード

Program.cs

using System;
using System.Windows.Forms;

namespace SampleForm
{
  static class Program
  {
    /// <summary>
    /// アプリケーションのメイン エントリ ポイントです。
    /// </summary>
    [STAThread]
    static void Main()
    {
      //Application.EnableVisualStyles();
      //Application.SetCompatibleTextRenderingDefault(false);
      //Application.Run(new Form1());
      var form = new Form1();
      Application.Run();
    }
  }
}

【C#】【Form】PictureBox [2] ~ PictureBox を マウスで移動する ~

$
0
0

■ はじめに

Windows Formで、以下の実装する。
仕様
[1] Panel内でマウス左をクリックし、Panel内のPictureBox をマウスで選択。その際、カーソルを変更。
[2] マウスを左クリックされている間は、そのPictureBox はPanel内を自由に移動する。
[3] マウスを左クリックを離すと、PictureBox の動きが止まり、カーソルもデフォルトに戻る。

■ サンプル

 * 以下のサイトを参考。
https://social.msdn.microsoft.com/Forums/vstudio/ja-JP/89b37ead-59d5-4cdc-b605-7486e6aae8f2/12500124631248112515125401250812483124631247312398312272120565?forum=csharpgeneralja
https://code.i-harness.com/ja/q/8b4d6

コントロール構成

 + Panel (Background : Black)
    + PictureBox

コード

using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    // クリック時点の座標
    private Size startSize = Size.Empty;
    // ドラッグされているか
    public bool IsDragging
    {
      get
      {
        return this.startSize != Size.Empty;
      }
    }

    public Form1()
    {
      InitializeComponent();
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      if (pictureBox == null)
      {
        return;
      }

      if (e.Button != MouseButtons.Left)
      {
        return;
      }

      this.startSize = new Size(e.X, e.Y);
      this.Cursor = Cursors.SizeAll;
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      if (pictureBox == null)
      {
        return;
      }

      if (e.Button != MouseButtons.Left || !this.IsDragging)
      {
        return;
      }

      // 画面座標をクライアント座標(コントロール上の座標)に変換する
      // https://dobon.net/vb/dotnet/control/pointtoclient.html
      // http://www.atmarkit.co.jp/fdotnet/dotnettips/377screentoclient/screentoclient.html
      Point currentPoint = this.panel1.PointToClient(Cursor.Position);

      // 画像を動かす
      //  Point.Subtract
      //   https://docs.microsoft.com/ja-jp/dotnet/api/system.drawing.point.subtract?view=netframework-4.7.2
      pictureBox.Location = Point.Subtract(currentPoint, this.startSize);
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      if (pictureBox == null)
      {
        return;
      }

      this.startSize = Size.Empty;
      this.Cursor = Cursors.Default;
    }
  }
}


関連記事

Windows Form

Windows Form ~ 目次 ~
https://blogs.yahoo.co.jp/dk521123/8054245.html
PictureBox [1] ~ 画像を表示する ~
https://blogs.yahoo.co.jp/dk521123/23504075.html

【C#】【Form】PictureBox [3] ~ マウスホイール で画像の拡大・縮小する ~

$
0
0

■ ポイント

 * 現在表示している点を中心として画像を拡大縮小する
  => 中心の点を原点へ移動し、拡大縮小後、元の位置へ移動する
  => 以下のサイトの説明が分かりやすい
http://imagingsolution.blog.fc2.com/blog-entry-287.html

■ その他、学べる事

【1】マウスホイールイベントの追加方法
【2】アフィン変換


関連記事

== Windows Form
Windows Form ~ 目次 ~
https://blogs.yahoo.co.jp/dk521123/8054245.html
PictureBox [1] ~ 画像を表示する ~
https://blogs.yahoo.co.jp/dk521123/23504075.html

【C#】【Form】 マウスホイールイベントの追加方法

$
0
0

■ マウスホイールイベントの追加方法

 * デザイナーでは対応されていないので、以下の「■ サンプル」のように追加する。

■ サンプル

//ホイールイベントの追加  
this.panel1.MouseWheel   
  += new System.Windows.Forms.MouseEventHandler(this.OnMouseWheel);


private void OnScroll(object sender, MouseEventArgs mouseEventArgs)
{
  // 実装
}

実際の使用例

 * 実際の使用例は、以下の関連記事を参照のこと
https://blogs.yahoo.co.jp/dk521123/37838702.html

関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

スクロール に関するあれこれ

https://blogs.yahoo.co.jp/dk521123/37838702.html

【C#】【Form】ドラッグ&ドロップでファイルを開く

$
0
0

■ サンプル

 * DragDropイベントを追加

コード

private void pictureBox1_DragDrop(object sender, DragEventArgs eventArgs)
{
  var fileNames =  (string[]) eventArgs.Data.GetData(DataFormats.FileDrop, false);

  // ファイル名の一覧を取得できたので、後は、通常処理
}

関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

【C#】図形 ~ 矩形 / Rectangle ~


【C#】【Form】アプリ状態を復元する仕組みを考える

$
0
0

■ はじめに

 * Windowsアプリの状態(ウインドウ位置, サイズ etc)を復元する仕組みを調べてみた。

■ サンプル

例1:Hello World

手順
[1] ソリューションエクスプローラ内のプロジェクト名を右クリックして、
    [プロパティ]-[設定]を選択する

 名前         型      スコープ	値
 HelloWorld   string  ユーザー	

 ※ 名前「HelloWorld」は、キーとなる値
コントロール構成
 * button x 2
 * Textbox x 1
コード
using System;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    // 保存処理
    private void button1_Click(object sender, EventArgs e)
    {
      Properties.Settings.Default.HelloWorld = this.textBox1.Text;
      Properties.Settings.Default.Save();
    }

    // 復元処理
    private void button2_Click(object sender, EventArgs e)
    {
      this.textBox1.Text = Properties.Settings.Default.HelloWorld;
    }
  }
}


関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

【C#】【Form】PictureBox [4] ~ PictureBox 内に文字列を描画する ~

$
0
0

■ はじめに

 * 以下について、考える

【1】 PictureBox 内に文字列を描画する
【2】 PictureBox 内に文字列をマウスで動かす

【1】 PictureBox 内に文字列を描画する

実装案1:DrawString() を使う

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private List<Point> targetPoints = new List<Point>();

    public Form1()
    {
      InitializeComponent();
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button != MouseButtons.Left)
      {
        return;
      }

      var pictureBox = sender as PictureBox;
      this.PaintText(pictureBox, e.Location, "これはテストです");
      targetPoints.Add(e.Location);
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      foreach (var targetPoint in this.targetPoints)
      {
        this.PaintText(pictureBox, targetPoint, "これはテストです");
      }
    }

    private void PaintText(PictureBox pictureBox, Point targetPoint, String targetText)
    {
      using (var font = new Font("メイリオ", 10))
      using (var graphics = pictureBox.CreateGraphics())
      {
        graphics.DrawString(targetText, font, Brushes.Blue, targetPoint);
      }
    }
  }
}

【2】 PictureBox 内に文字列をマウスで動かす

実装案1:GraphicsPath.AddString() を使う

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private GraphicsPath graphicsPath = new GraphicsPath();
    private Point downPoint;
    private float dx;
    private float dy;
    private bool isDragging;

    public Form1()
    {
      InitializeComponent();

      this.graphicsPath.AddString("これはテストです", Font.FontFamily,
            (int)Font.Style, 10, new Point(10, 10), StringFormat.GenericDefault);
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button != MouseButtons.Left)
      {
        return;
      }
      this.downPoint = e.Location;
      if (this.graphicsPath.GetBounds(new Matrix(1, 0, 0, 1, this.dx, this.dy)).Contains(e.Location))
      {
        this.graphicsPath.Transform(new Matrix(1, 0, 0, 1, this.dx, this.dy));
        this.isDragging = true;
      }
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
      if (e.Button != MouseButtons.Left)
      {
        return;
      }

      if (this.isDragging)
      {
        this.dx = e.X - this.downPoint.X;
        this.dy = e.Y - this.downPoint.Y;
        pictureBox1.Invalidate();
      }
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
      this.isDragging = false;
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
      e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
      this.graphicsPath.Transform(new Matrix(1, 0, 0, 1, this.dx, this.dy));
      e.Graphics.FillPath(Brushes.Red, this.graphicsPath);
      this.graphicsPath.Transform(new Matrix(1, 0, 0, 1, -dx, -dy));

    }

    private void button1_Click(object sender, EventArgs e)
    {
      // 文字を消す
      this.graphicsPath.Reset();
      this.pictureBox1.Refresh();
    }
  }
}

実装案:Label を使う

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private Point labelDownPoint;

    public Form1()
    {
      InitializeComponent();

      this.label1.BackColor = Color.Transparent;
      this.label1.Parent = this.pictureBox1;
    }

    private void button1_Click(object sender, EventArgs e)
    {
      this.label1.Visible = false;
    }

    private void label1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        this.labelDownPoint = e.Location;
      }
    }

    private void label1_MouseMove(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        this.label1.Left += e.X - this.labelDownPoint.X;
        this.label1.Top += e.Y - this.labelDownPoint.Y;
      }
    }
  }
}

参考文献

【2】 PictureBox 内に文字列をマウスで動かす

https://stackoverflow.com/questions/20312831/drag-string-on-picturebox-c-sharp

関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

【C#】【Form】PictureBox [5] ~ PictureBox 内に画像を描画する ~

$
0
0

■ サンプル

{
using SampleForm.Properties;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private List<Point> targetPoints = new List<Point>();

    public Form1()
    {
      InitializeComponent();
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      var image = Resources.Mark;
      var targetPoint = new Point(e.X - (image.Width / 2), e.Y - (image.Height / 2));
      this.targetPoints.Add(targetPoint);
      this.PaintImageOnPictureBox(pictureBox, image, targetPoint);
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
      var pictureBox = sender as PictureBox;
      foreach (var targetPoint in this.targetPoints)
      {
        this.PaintImageOnPictureBox(pictureBox, Resources.Mark, targetPoint);
      }
    }

    private void PaintImageOnPictureBox(PictureBox pictureBox, Bitmap image, Point point)
    {
      using (var graphics = pictureBox.CreateGraphics())
      {
        graphics.DrawImage(image, point);
      }
    }
  }
}

関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

【C#】【Form】キーイベント ~ KeyDown/KeyUp/KeyPress・PreviewKeyDown ~

$
0
0

■ キーイベント

1-1) KeyDown  : キーダウン
1-2) KeyPress : キー押下
1-3) KeyUp    : キーアップ

2) PreviewKeyDown : 矢印、Tab、Enter、Escキーなどが押下された場合のイベント(KeyDownイベントでは拾えない)


関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

【C#】【Form】PictureBox [6] ~ PictureBox 内でMouseMoveイベントにより線を描画する ~

$
0
0

■ はじめに

https://blogs.yahoo.co.jp/dk521123/32877749.html
で「例4:マウスを追いかける」を行ったが、
VS2017/Windows10で実行したらうまくいかなかったので作り直す

■ サンプル

例1:シンプルなサンプル

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private Point startPoint = Point.Empty;
    private Point nowPoint = Point.Empty;

    public Form1()
    {
      InitializeComponent();
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button != MouseButtons.Left)
      {
        // 右クリックは無視
        return;
      }

      this.startPoint = e.Location;
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
      if (this.startPoint.IsEmpty)
      {
        return;
      }

      this.nowPoint = e.Location;

      var pictureBox = sender as PictureBox;
      pictureBox.Invalidate();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
      var graphics = e.Graphics;
      graphics.DrawLines(Pens.Red, new Point[] { startPoint, nowPoint });
    }
  }
}

例2:マウスを追いかける(改)

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form1 : Form
  {
    private Point startPoint = Point.Empty;
    private Point endPoint = Point.Empty;
    private Point nowPoint = Point.Empty;

    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      this.pictureBox1.InitialImage = this.pictureBox1.Image;
    }

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button != MouseButtons.Left)
      {
        // 右クリックは無視
        return;
      }

      var targetPoint = e.Location;

      if (!this.startPoint.IsEmpty && !this.endPoint.IsEmpty)
      {
        // Clear
        this.Clear();
      }
      else if (!this.startPoint.IsEmpty && this.endPoint.IsEmpty)
      {
        this.endPoint = targetPoint;
      }
      else
      {
        this.startPoint = targetPoint;
        this.endPoint = Point.Empty;
      }

      var pictureBox = sender as PictureBox;
      pictureBox.Invalidate();
    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
      if (this.startPoint.IsEmpty)
      {
        return;
      }

      if (this.endPoint.IsEmpty)
      {
        this.nowPoint = e.Location;
      }
      else
      {
        this.nowPoint = Point.Empty;
      }

      var pictureBox = sender as PictureBox;
      pictureBox.Invalidate();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
      var graphics = e.Graphics;

      if (!this.startPoint.IsEmpty)
      {
        this.FillCircle(graphics, Brushes.White, this.startPoint.X, this.startPoint.Y, 10);
        this.FillCircle(graphics, Brushes.SkyBlue, this.startPoint.X, this.startPoint.Y, 8);
      }

      if (!this.endPoint.IsEmpty)
      {
        this.FillCircle(graphics, Brushes.White, this.endPoint.X, this.endPoint.Y, 10);
        this.FillCircle(graphics, Brushes.LightGreen, this.endPoint.X, this.endPoint.Y, 8);

        graphics.DrawLine(new Pen(Color.LightGreen, 3), this.startPoint, this.endPoint);

        return;
      }

      if (!this.nowPoint.IsEmpty)
      {
        graphics.DrawLines(Pens.Red, new Point[] { startPoint, nowPoint });
      }
    }

    private void Clear()
    {
      this.startPoint = Point.Empty;
      this.endPoint = Point.Empty;
      this.nowPoint = Point.Empty;

      this.pictureBox1.Image = this.pictureBox1.InitialImage;
    }

    /// <summary>
    /// x,yを中心とした半径radiusの円を書く
    /// </summary>
    /// <param name="graphics">graphicsオブジェクト</param>
    /// <param name="brush">brushオブジェクト</param>
    /// <param name="x">x座標</param>
    /// <param name="y">y座標</param>
    /// <param name="radius">半径</param>
    /// <see cref="https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11173767351"/>
    private void FillCircle(Graphics graphics, Brush brush, float x, float y, float radius)
    {
      graphics.FillEllipse(brush, x - radius, y - radius, radius * 2, radius * 2);
    }
  }
}


関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

Graphics ~ さまざまな描画 ~

https://blogs.yahoo.co.jp/dk521123/32877749.html

PictureBox

PictureBox [1] ~ 画像を表示する ~
https://blogs.yahoo.co.jp/dk521123/23504075.html
PictureBox [2] ~ PictureBox を マウスで移動する ~
https://blogs.yahoo.co.jp/dk521123/37861699.html
PictureBox [3] ~ マウスホイール で画像の拡大・縮小する ~
https://blogs.yahoo.co.jp/dk521123/37866101.html
PictureBox [4] ~ PictureBox 内に文字列を描画する ~
https://blogs.yahoo.co.jp/dk521123/37890831.html
PictureBox [5] ~ PictureBox 内に画像を描画する ~
https://blogs.yahoo.co.jp/dk521123/37890873.html

【C#】【Form】 トグルボタン

$
0
0

■ はじめに

 * トグルボタン(ボタンを凹んだ)を実装する

■ 手順

【1】RadioButton (又はCheckBox)を追加 
【2】 『RadioButton.Appearance プロパティ:Button』すればいい。
【3】 CheckBoxでも、同様な方法で表示可能。

■ サンプル

例1:ToolStrip の代わりになるレイアウトを考える

 * ToolStrip は、(古くさいが)ToolStripContainerを使えば、
   ユーザ側でレイアウトをある程度、自由に変更できるし、
   使いやすいから、いいコントローラだと思うが、
   なんせ小さいから見にくい。   なので、代わりになるレイアウトを考えてみた。 
解決案
 * TableLayoutPanel と Button を組み合わせる
  => 以下「コントローラ構成」を参照
コントローラ構成
 * TableLayoutPanel
  + Column x 5 (サイズの型 : 各20%:大きさを均等にする)
  + Dock : Top
 * CheckBox x 5 (TableLayoutPanelのColumn内に設定)
  + Appearance : Button
  + Dock : Fill (TableLayoutPanelのColumn内、いっぱいに表示させるため)
  + Image : 好みのアイコン画像を設定
  + Text : 好みのテキストを設定(もしくは「設定しない」)
  + TextAlign : BottomCenter


関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

RadioButton / CheckBox / ListBox

https://blogs.yahoo.co.jp/dk521123/20533862.html

TableLayoutPanel ~ カルーセルをWindows Formで実装する ~

https://blogs.yahoo.co.jp/dk521123/37849474.html

【AIスピーカー】Google Home アプリ作成 ~ 基礎知識編 ~

$
0
0

■ Google Home アプリ作成方法

【1】IFTTT を利用する
【2】Actions on Google の テンプレート を利用する
【3】Actions on Google + Dialogflow を利用する
【4】Actions on Google + Actions SDK を利用する

【1】IFTTT を利用する

IFTTT とは?

IFTTT(イフト) : If this, then that(もしこれ(入力)をしたなら、その時あれ(出力)する)
 * 2つのWebサービスを連携させるサービス
 * プログラミング不要


【設計】【モデリング】ロバストネス分析

$
0
0

■ ロバストネス分析

 * robust(ロバスト) : 頑強な

■ 要素

`名前`備考
`No
`例
01 アクター(Actor) ユーザ 02 バウンダリー(Boundary:境界) 外部とのインタフェース 名詞 03 コントロール(Control) 処理 動詞 04 エンティティ(Entity) データ 名詞

参考文献

https://www.ogis-ri.co.jp/otc/swec/process/am-res/am/artifacts/robustnessDiagram.html
https://qiita.com/reoring/items/d3c5bb9506386404b297
https://thinkit.co.jp/article/13487
http://d.hatena.ne.jp/m-hiyama/20120618/1339979590

【C#】【Form】 DataGridView ~ ソート編 ~

$
0
0

■ はじめに

 DataGridView のソートについて、纏める

■ 使用上の注意:独自クラスのリストをバインドする場合、ソートが効かなくなる

サンプル:ソートが効かなくなる例

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace SampleForm
{
  public partial class Form2 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
      var list = new List<Person>()
      {
        new Person(1L, "Mike", 23),
        new Person(2L, "Tom", 18),
        new Person(3L, "Smith", 32),
        new Person(4L, "Naomi", 56),
        new Person(5L, "Kevin", 45)
      };

      this.dataGridView1.DataSource = list;
    }
  }

  // 独自クラス
  public class Person
  {
    public long Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }

    public Person(long id, string name, int age)
    {
      this.Id = id;
      this.Name = name;
      this.Age = age;
    }
  }
}

解決案

 * 以下のサイトが参考になる
https://garafu.blogspot.com/2016/09/cs-sorablebindinglist.html

関連記事

Windows Form ~ 目次 ~

https://blogs.yahoo.co.jp/dk521123/8054245.html

DataGridView

DataGridView ~ プロパティ編 ~
https://blogs.yahoo.co.jp/dk521123/14718079.html
DataGridView ~イベント編 ~
https://blogs.yahoo.co.jp/dk521123/23687833.html
DataGridView ~ 画像・アイコン編 ~
https://blogs.yahoo.co.jp/dk521123/22293894.html
DataGridView を Label のように扱う
https://blogs.yahoo.co.jp/dk521123/29362064.html
DataGridView に ACCESS のデータを表示させる
https://blogs.yahoo.co.jp/dk521123/32859068.html
DataGridView に右クリックを適用する
https://blogs.yahoo.co.jp/dk521123/30488275.html

【JS】ユーザ情報取得

$
0
0

■ はじめに

https://blogs.yahoo.co.jp/dk521123/23844430.html
で、C#によるユーザ情報取得を行った。
今回、JavaScriptで調べてみた。

■ サンプル

<script>
document.write("location.host : " + location.host + "</br>");
document.write("location.hostname : " + location.hostname + "</br>");
document.write("location.port : " + location.port + "</br>");
document.write("location.pathname : " + location.pathname + "</br>");
document.write("navigator.appCodeName : " + navigator.appCodeName + "</br>");
document.write("navigator.appName : " + navigator.appName + "</br>");
document.write("navigator.appVersion : " + navigator.appVersion + "</br>");
document.write("navigator.language : " + navigator.language + "</br>");
document.write("navigator.platform : " + navigator.platform + "</br>");
document.write("navigator.userAgent : " + navigator.userAgent + "</br>");
document.write("document.referrer : " + document.referrer + "</br>");
document.write("document.domain : " + document.domain + "</br>");
document.write("screen.width : " + screen.width + "</br>");
document.write("screen.height : " + screen.height + "</br>");
document.write("screen.colorDepth : " + screen.colorDepth);
</script>


関連記事

【C#】ユーザ情報取得 ~ コンピュータ名 etc ~

https://blogs.yahoo.co.jp/dk521123/23844430.html

【AIスピーカー】Google Home アプリ作成 ~ Actions on Google + Dialogflow編 ~

$
0
0

■ はじめに

https://blogs.yahoo.co.jp/dk521123/37906061.html
で、おおよその知識を学んだので、今回は、Hello Worldを作ってみる

■ 手順

【1】プロジェクトの作成
【2】Invocationの設定
【3】Actionの追加

【1】プロジェクトの作成

Actions on Googleで、プロジェクトを作成する
[1-1] 以下のURLからアクセス
https://console.actions.google.com/
[1-2] [Add/import project]を選択

[1-3] 「New Project」ダイアログで、以下を入力し、「CREATE PROJECT」ボタン押下。
~~~~~~~~~~
 * Project Name : 任意の文字列(プロジェクト名。例「hello-world」)
 * Choose a language for your Actions project (you can add more languages later) : Japanese
 * Choose your country or region : Japan
~~~~~~~~~~

[1-4] 「Welcome to your project, 【プロジェクト名】!」ページで「SKIP」リンクをクリック

【2】Invocationの設定

[2-1] 「Overview」ページで、左側にある [Setup]-[Invocation]を選択
[2-2] 「Invocation」ページで、以下を入力し、右上の「SAVE」ボタン押下。
~~~~~~~~~~
 * Display Name : 任意の文字列
                 (例「ハローワールド」(※)。これで、「OK Google, ハローワールドにつないで」と言うことで起動する)
~~~~~~~~~~

※ 実際に「ハローワールド」だと『Could not reserve your pronunciation 'ハローワールド'
 because: Your pronunciation is already reserved by another Assistant Action.
 If you need further guidance, please contact support』って怒られるので、違う名前にした方がいい。

【3】Actionの追加

[3-1] 左側にある [Actions]を選択し、「ADD YOUR FIRST ACTION」ボタン押下。


関連記事

Google Home アプリ作成 ~ 基礎知識編 ~

https://blogs.yahoo.co.jp/dk521123/37906061.html

【C#】列挙型・Enum ~ フラグ・アトリビュート ~

$
0
0

■ フラグ・アトリビュート(Flags Attribute)

 * Flags属性(FlagsAttributeクラス)を付与することにより、Enum型がビットフラグとして使えるようになる

■ 定義

 * Flags属性([Flags])を付与する

サンプル

[Flags]
public enum SampleEnum
{
    None = 0,
    Sample1 = 1,
    Sample2 = 2,
    Sample3 = 4,
}

■ フラグ操作

フラグを立てる

 *  |演算子(OR演算子) を使う
サンプル
[Flags]
public enum Week
{
    Sunday    = 0x001,
    Monday    = 0x002,
    Tuesday   = 0x004,
    Wednesday = 0x008,
    Thursday  = 0x010,
    Friday    = 0x020,
    Saturday  = 0x040
}

var flag = Week.Saturday;
flag = flag | Week.Sunday;

フラグを下す

 * &演算子(AND演算子) と ~演算子(反転演算子) の組み合わせ
サンプル
var flag = Week.Saturday | Week.Friday;
flag = flag & ~Week.Friday;
}

■ 関連メソッド

Enum.HasFlag()

 * From .NET Framework4
 * 指定したビットフィールドが設定されているかどうかを判断するEnum.HasFlag メソッドが追加された
サンプル
enum Country
{
    Japan,
    Italy,
    US,
    Korea,
    India,
    Australia,
    Brazil,
}

private void button1_Click(object sender, EventArgs e)
{
    this.label1.Text = string.Empty;

    Country myStayed = Country.Japan | Country.Italy | Country.Korea;

    if (myStayed.HasFlag(Country.Korea))
    {
        this.label1.Text += "\n韓国に行った事あるの!?";
    }

    if (myStayed.HasFlag(Country.Japan | Country.Italy))
    {
        this.label1.Text += "\nイタリアと日本に行った事あるの!?";
    }

    if (myStayed.HasFlag(Country.Japan | Country.Brazil))
    {
        this.label1.Text += "\nブラジルに行った事あるの!?";
    }
}

従来との比較

 * 大分すっきりした感がある
.NET Framework4以前
if ((myStayed & (Country.Japan | Country.Italy)) == (Country.Japan | Country.Italy))
.NET Framework4
if (myStayed.HasFlag(Country.Japan | Country.Italy))


関連記事

列挙型・Enum ~ 基本編 ~

https://blogs.yahoo.co.jp/dk521123/22338133.html

列挙型・Enum ~ 数値からEnumに変換 ~

https://blogs.yahoo.co.jp/dk521123/29496843.html

列挙型・Enum ~ Enumの文字列化 ~

https://blogs.yahoo.co.jp/dk521123/31367224.html

属性(アトリビュート) ~カスタム属性~

https://blogs.yahoo.co.jp/dk521123/29483903.html
Viewing all 860 articles
Browse latest View live