C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 132 を表示中)
■77695 / )  4点の座標位置をおぼえるにはどうしています?
□投稿者/ ミルク (11回)-(2015/11/17(Tue) 12:45:04)

分類:[.NET 全般] 

2015/11/17(Tue) 12:46:33 編集(投稿者)

環境 c# .net Windows7

C#で Rectangle があり、それぞれ Left, Top, Right, Bottom があるので
使おうと思いましたが、

Width, Height でしか設定できないみたいです。

Rectangle ra = new Rectangle(Left, Top, Width, Height);

Rectangle ra = new Rectangle(); を行って
ra.Left, ra.Top, ra.Right, ra.Bottom を代入しようとしたけど読取専用になっています。

結局
Rectangle ra = new Rectangle(left, top, right - left + 1, bottom - top + 1);
にして使うしか手はないのでしょうか?

または、別の構造体を作成するとか?
class RectAngle
{
 public int Left;
 public int Top;
 public int Right;
 public int Bottom;

 public void RectAngle(int l, int t, int r, int b)
 {
  Left = l;
  Top = t;
  Right = r;
  Bottom = b;  
 }
}

皆さんはどうしていますか?
返信 編集キー/


管理者用

- Child Tree -