本文整理汇总了C#中System.Drawing.Rectangle.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Rectangle.Contains方法的具体用法?C# System.Drawing.Rectangle.Contains怎么用?C# System.Drawing.Rectangle.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rectangle
的用法示例。
在下文中一共展示了System.Drawing.Rectangle.Contains方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FadingTextField
public FadingTextField(string s, Vector2 position, Vector2 velocity, Rectangle rect, Func<FadingTextField, Task> remove)
{
Text = new Text(s, position, Color.White);
Velocity = new Vector3(velocity, 0);
var every = TimeSpan.FromSeconds(1 / 30.0);
Unsubscribe = Observable.Timer(TimeSpan.Zero, every)
.TimeInterval()
.Subscribe(t =>
{
Text.Position += Velocity * (float)t.Interval.TotalSeconds;
if (!rect.Contains((int)Text.Position.X, (int)Text.Position.Y))
{
remove(this);
if (Unsubscribe != null)
Unsubscribe.Dispose();
}
});
}
示例2: CountBinaryTransitions
/// <summary>
/// Count the number of black/white transitions for a single ellipse
/// </summary>
/// <param name="e">Ellipse</param>
/// <param name="matrix">Affine ellipse frame that transforms the ellipse to a circle located at origin</param>
/// <param name="gray">Binary image</param>
/// <returns>The number of black/white transitions found</returns>
private int CountBinaryTransitions(DetectedEllipse e, Matrix matrix, Emgu.CV.Image<Gray, byte> gray) {
// Generate points on circle
double r = e.Ellipse.MCvBox2D.size.Height * 0.5;
double t_step = (2 * Math.PI) / _number_circle_points;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, gray.Size);
int count_transitions = 0;
double last_intensity = 0;
for (double t = 0; t <= 2 * Math.PI; t += t_step) {
Vector v = new Vector(new double[] { r * Math.Cos(t), r * Math.Sin(t), 1.0 });
Vector x = matrix.Multiply(v.ToColumnMatrix()).GetColumnVector(0);
System.Drawing.Point p = new System.Drawing.Point((int)Math.Round(x[0]), (int)Math.Round(x[1]));
if (rect.Contains(p)) {
if (t == 0) {
last_intensity = gray[p].Intensity;
} else {
double i = gray[p].Intensity;
if (i != last_intensity) {
count_transitions += 1;
last_intensity = i;
}
}
}
}
return count_transitions;
}
示例3: checkOverflow
private void checkOverflow(Basic ctrlFrame)
{
CtrlDef_T ctrlDef;
System.Drawing.Rectangle rectFrame = new System.Drawing.Rectangle(
ctrlFrame.m_selScreenX, ctrlFrame.m_selScreenY, ctrlFrame.m_selW, ctrlFrame.m_selH);
if (ctrlFrame != null && ctrlFrame.m_xe != null && ctrlFrame.m_xe.Name != "" && CtrlDef_T.isFrame(ctrlFrame.m_xe.Name) == true)
{
foreach (object item in ctrlFrame.Items)
{
if (item is Basic)
{
Basic ctrlItem = (Basic)item;
if (ctrlItem.m_xe.GetAttribute("visible") != "false")
{
System.Drawing.Rectangle rectItem = new System.Drawing.Rectangle(
ctrlItem.m_selScreenX, ctrlItem.m_selScreenY, ctrlItem.m_selW, ctrlItem.m_selH);
if (ctrlItem.m_xe.Name != "event" && !rectFrame.Contains(rectItem))
{
Public.ResultLink.createResult("\r\n[" + ctrlItem.mx_text.Text + "]",
Public.ResultType.RT_INFO, ctrlItem);
Public.ResultLink.createResult(" 超出了 ", Public.ResultType.RT_INFO);
Public.ResultLink.createResult("[" + ctrlFrame.mx_text.Text + "]",
Public.ResultType.RT_INFO, ctrlFrame);
Public.ResultLink.createResult(" 的范围。", Public.ResultType.RT_INFO, ctrlItem);
}
checkOverflow(ctrlItem);
}
}
}
}
}
示例4: isContainedElement
internal bool isContainedElement(ElementWrapper elementWrapper)
{
if(elementWrapper == null) {
return false;
}
// The element in question must be a direct child of the regions owning element
if(elementWrapper.wrappedElement.ParentID != redefinedElement.wrappedElement.ElementID)
{
return false;
}
if(partition != null)
{
// Check if the element in question resides inside the graphical representation of this region
//--------------------------------------------------------------------------------------------
if(masterDiagram != null)
{
// Get the element in question's graphical representation from the master diagram
global::EA.DiagramObject elementDiagramObject = getMasterDiagramObject(elementWrapper);
if(elementDiagramObject != null)
{
System.Drawing.Rectangle elementRectangle =
new System.Drawing.Rectangle
( elementDiagramObject.left
, System.Math.Abs(elementDiagramObject.top)
, elementDiagramObject.right - elementDiagramObject.left
, System.Math.Abs(elementDiagramObject.bottom) - System.Math.Abs(elementDiagramObject.top)
);
// Get the owning elements graphical region representation from the master diagram
global::EA.DiagramObject owningElementDiagramObject = getMasterDiagramObject(redefinedElement);
if(owningElementDiagramObject != null)
{
int x = owningElementDiagramObject.left;
int y = System.Math.Abs(owningElementDiagramObject.top) + getRegionTopOffset(partition);
int width = owningElementDiagramObject.right - x;
int height = partition.Size;
System.Drawing.Rectangle regionRectangle = new System.Drawing.Rectangle(x,y,width,height);
if(regionRectangle.Contains(elementRectangle))
{
return true;
}
}
}
}
}
else
{
return true;
}
return false;
}
示例5: DelayTimer_Tick
void DelayTimer_Tick(object sender, EventArgs e) {
_DelayTimer.Stop();
var t = new Thread(() => {
var clonedCurrentItem = this.CurrentItem.Clone();
var tooltip = clonedCurrentItem.ToolTipText;
if (String.IsNullOrEmpty(tooltip) && Type == 1) {
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(this.Hide));
return;
}
Contents = Type == 0 ? $"{clonedCurrentItem.DisplayName}\r\n{clonedCurrentItem.ToolTipText}" : clonedCurrentItem.ToolTipText;
RaisePropertyChanged("Contents");
// BE-557: clonedCurrentItem.GetPropertyValue returned VT_EMPTY, edge case included to handle this
var perceivedTypeProperty = clonedCurrentItem.GetPropertyValue(
SystemProperties.PerceivedType,
typeof(PerceivedType));
if (perceivedTypeProperty.VarType != VarEnum.VT_EMPTY
&& ((PerceivedType)perceivedTypeProperty.Value) == PerceivedType.Image && !clonedCurrentItem.IsFolder)
{
var image = clonedCurrentItem.ThumbnailSource(
350,
ShellThumbnailFormatOption.Default,
ShellThumbnailRetrievalOption.Default);
image.Freeze();
this.Image = image;
RaisePropertyChanged("Image");
this.FileNameWidth = this.Image.Width - 110;
RaisePropertyChanged("FileNameWidth");
try
{
var ratingValue = clonedCurrentItem.GetPropertyValue(MediaProperties.Rating, typeof(Double)).Value;
var rating = ratingValue == null ? 0 : Convert.ToDouble(ratingValue) / 20D;
this.Rating = rating;
RaisePropertyChanged("Rating");
this.Dimentions =
((Math.Ceiling(
Convert.ToDouble(clonedCurrentItem.GetPropertyValue(SystemProperties.FileSize, typeof(double)).Value))
/ 1024).ToString("# ### ### ##0") + " KB ("
+ clonedCurrentItem.GetPropertyValue(MediaProperties.Dimensions, typeof(String)).Value.ToString()
+ " px )").Trim();
RaisePropertyChanged("Dimentions");
}
catch (NullReferenceException)
{
}
this.FileName = Path.GetFileName(clonedCurrentItem.ParsingName)?.Trim();
RaisePropertyChanged("FileName");
}
else
{
var image = clonedCurrentItem.ThumbnailSource(
64,
ShellThumbnailFormatOption.Default,
ShellThumbnailRetrievalOption.Default);
image.Freeze();
this.Image = image;
RaisePropertyChanged("Image");
}
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(() => {
var lvi = new LVITEMINDEX();
lvi.iItem = this.ItemIndex;
lvi.iGroup = this._View.GetGroupIndex(this.ItemIndex);
var bounds = new User32.RECT();
User32.SendMessage(this._View.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref bounds);
var rect = new System.Drawing.Rectangle(bounds.Left, bounds.Top, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
var posm = User32.GetCursorPosition();
var mousePos = this._View.PointToClient(posm);
var isInsideItem = rect.Contains(mousePos);
if (isInsideItem)
this.Show();
else
this.Hide();
}));
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
示例6: dgvChars_MouseMove
private void dgvChars_MouseMove(object sender, MouseEventArgs e)
{
// キャラのドラッグ中の操作
if (dragPrevIndexes != null && dragPrevIndexes.Length > 0 && dragStartIndexes != null && dragStartIndexes.Length == dragPrevIndexes.Length && dragHoldRelIndex >= 0)
{
// 現在のマウスの位置
DataGridView.HitTestInfo hitc = dgvChars.HitTest(e.X, e.Y);
// 現在の位置が、有効なセル上を選択している場合
if (hitc.Type == DataGridViewHitTestType.Cell
&& (dgvChars.NewRowIndex == -1
|| dgvChars.NewRowIndex != hitc.RowIndex))
{
if (dragPrevIndexes[dragHoldRelIndex] != hitc.RowIndex)
{
slideChar(dragPrevIndexes, hitc.RowIndex); // ここで dragPrevIndexes の調整もしてしまう
//dragPrevIndex = hitc.RowIndex;
this.Cursor = Cursors.NoMoveVert;
}
}
else
{
if (dragPrevIndexes[dragHoldRelIndex] != dragStartIndexes[dragHoldRelIndex])
{
//slideChar(dragPrevIndexes, dragStartIndexes); // ここで dragPrevIndexes の調整もしてしまう。オーバーロードで実装
//dragPrevIndex = dragStartIndex;
//this.Cursor = Cursors.No;
this.Cursor = Cursors.Default;
}
}
}
// else があってもいいけどひとつ目の条件から無くてもいい。
if (mouseDownPoint != System.Drawing.Point.Empty && dgvChars.SelectedRows.Count > 0)
{
//ドラッグとしないマウスの移動範囲を取得する
System.Drawing.Rectangle moveRect = new System.Drawing.Rectangle(
mouseDownPoint.X - SystemInformation.DragSize.Width / 2,
mouseDownPoint.Y - SystemInformation.DragSize.Height / 2,
SystemInformation.DragSize.Width,
SystemInformation.DragSize.Height);
//ドラッグとする移動範囲を超えたか調べる
if (!moveRect.Contains(e.X, e.Y))
{
DataGridView.HitTestInfo hit = dgvChars.HitTest(mouseDownPoint.X, mouseDownPoint.Y);
// ドラッグ元としての指定位置が、有効なセル上を選択している場合
if (hit.Type == DataGridViewHitTestType.Cell
&& (dgvChars.NewRowIndex == -1
|| dgvChars.NewRowIndex != hit.RowIndex))
{
// ドラッグ元の行
int ind = hit.RowIndex;
// 編集状態であれば解除
gbChars.Focus();
//dgvChars.Rows[dgvChars.SelectedRows[0].Index].Cells[0].Selected = true;
// ドラッグスタート位置を記憶
// は、マウスをクリックしたときにやらないと既に解除されていて意味が無い。
//dragStartIndex = dragPrevIndex = ind;
//dragStartIndexes = GetSelectedCharsIndexesArray();
Array.Sort(dragStartIndexes); // でもソートは必要。ここでやるのがいいでしょう。
// 掴んでいるのが選択したファイルのうち上から何番目であるかを
// ゼロオリジンで記憶
dragHoldRelIndex = -1;
for (int i = 0; i < dragStartIndexes.Length; i++)
{
if (dragStartIndexes[i] == ind)
{
dragHoldRelIndex = i;
break;
}
}
// これは想定外。でもありそう。
if (dragHoldRelIndex < 0)
{
return;
}
// 選択されているものを
// 掴んでいる前後に寄せ集める
for (int dir = -1; dir <= 1; dir += 2)
{
for (int i = dragHoldRelIndex + dir; i >= 0 && i < dragStartIndexes.Length; i += dir)
{
var dstIndex = ind + i - dragHoldRelIndex;
if (dir * (dstIndex - dragStartIndexes[i]) < 0)
{
var temp = dlcData.Chars[dragStartIndexes[i]];
dlcData.Chars[dragStartIndexes[i]] = dlcData.Chars[dstIndex];
dlcData.Chars[dstIndex] = temp;
}
}
}
//.........这里部分代码省略.........
示例7: _ControlAt
private Control _ControlAt(System.Drawing.Point mousePosition)
{
Control control = null;
if (Contexts.Count > 0)
{
for (int i = 0; i < Contexts.Count; i++)
{
var contextControl = Contexts[i];
var cRect = new System.Drawing.Rectangle(contextControl.Location.X, contextControl.Location.Y, contextControl.Width, contextControl.Height);
if (cRect.Contains(mousePosition))
{
control = contextControl;
break;
}
}
}
if (ModalForms.Count > 0)
{
if (control == null)
{
var lastModalForm = ModalForms.Last();
var formRect = new System.Drawing.Rectangle(lastModalForm.Location.X, lastModalForm.Location.Y, lastModalForm.Width, lastModalForm.Height);
if (formRect.Contains(mousePosition))
control = lastModalForm;
}
}
else
{
if (control == null)
for (int i = Forms.Count - 1; i >= 0; i--)
{
var form = Forms[i];
if (form.TopMost && form.Visible && form.Enabled)
{
var formRect = new System.Drawing.Rectangle(form.Location.X, form.Location.Y, form.Width, form.Height);
if (formRect.Contains(mousePosition))
{
control = form;
break;
}
}
}
if (control == null)
for (int i = Forms.Count - 1; i >= 0; i--)
{
var form = Forms[i];
if (form.TopMost == false && form.Visible && form.Enabled)
{
var formRect = new System.Drawing.Rectangle(form.Location.X, form.Location.Y, form.Width, form.Height);
if (formRect.Contains(mousePosition))
{
control = form;
break;
}
}
}
}
if (control != null)
control = FindControlAt(control, mousePosition);
return control;
}
示例8: Detect
public override bool Detect(System.Drawing.Point pTest)
{
SetHieghtAndWidth();
System.Drawing.Rectangle r = new System.Drawing.Rectangle(StartPt.X, StartPt.Y, width, height);
return r.Contains(pTest);
}