/// <summary> /// PictureBox (pb) 上の座標から、pb.Image 上の座標に変換する。 /// pb.SizeMode == PictureBoxSizeMode.Zoom であること。 /// </summary> /// <param name="pb"></param> /// <param name="pbPt"></param> /// <param name="toRangeFlag"></param> /// <returns>null == 枠外 || 画像が設定されていない。</returns> public static XYPoint getPictureBoxPointToImagePoint(PictureBox pb, XYPoint pbPt, bool toRangeFlag = false) { Image img = pb.Image; if (img == null) { return(null); } double w = (double)img.Width; double h = (double)img.Height; double screen_w = (double)pb.Width; double screen_h = (double)pb.Height; Rect imgRect = new Rect(w, h); Rect screenRect = new Rect(0, 0, screen_w, screen_h); imgRect.adjustInside(screenRect); double x = pbPt.x; double y = pbPt.y; x -= imgRect.l; y -= imgRect.t; x /= imgRect.w; y /= imgRect.h; if (toRangeFlag) { x = DoubleTools.toRange(x, 0.0, 1.0); y = DoubleTools.toRange(y, 0.0, 1.0); } else { if (DoubleTools.isRange(x, 0.0, 1.0) == false) { return(null); } if (DoubleTools.isRange(y, 0.0, 1.0) == false) { return(null); } } x *= img.Width; y *= img.Height; return(new XYPoint(x, y)); }
private void mainTimer_Tick(object sender, EventArgs e) { if (this.mtEnabled == false || this.mtBusy) { return; } this.mtBusy = true; try { if ( this._historyData == null && Gnd.i.mkSudokuProc != null && Gnd.i.mkSudokuProc.isEnded() ) { this._historyData = Gnd.i.mkSudokuProc.getResult(); this.historyDataCreated(); } if ( this._historyData == null && Gnd.i.mkSudokuProc != null && Gnd.i.mkSudokuProc.isEnded() == false ) { double progressRate; lock (Gnd.i.n2Listener.SYNCROOT) { progressRate = Gnd.i.n2Listener.progressRate; } // なんちゃってプログレスバー効果 { const long MC_MAX = 3000L; // 5 min const double MC_MAX_RATE = 0.3; // 30 pct long mc = Math.Min(mtCount, MC_MAX); double rate = (mc * MC_MAX_RATE) / MC_MAX; progressRate = Math.Max(progressRate, rate); } progressRate = DoubleTools.toRange(progressRate, 0.0, 1.0); progressRate *= 0.9; progressRate += 0.05; int value = IntTools.toInt(progressRate * IntTools.IMAX); if (pbMk.Value != value) { pbMk.Value = value; } } } finally { this.mtBusy = false; this.mtCount++; } }