本文整理汇总了C#中System.Drawing.Rectangle.Offset方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Rectangle.Offset方法的具体用法?C# System.Drawing.Rectangle.Offset怎么用?C# System.Drawing.Rectangle.Offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rectangle
的用法示例。
在下文中一共展示了System.Drawing.Rectangle.Offset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateRectangles
/// <summary>
/// Update the rectangles
/// </summary>
protected override void UpdateRectangles()
{
// Update base first
base.UpdateRectangles();
// Update the two rects
buttonRect = boundingBox;
buttonRect = new System.Drawing.Rectangle(boundingBox.Location,
new System.Drawing.Size(boundingBox.Height, boundingBox.Height));
textRect = boundingBox;
textRect.Offset((int) (1.25f * buttonRect.Width), 0);
}
示例2: OnRender
/// <summary>Render the dialog</summary>
public void OnRender(float elapsedTime)
{
// See if the dialog needs to be refreshed
if (timeLastRefresh < timeRefresh)
{
timeLastRefresh = FrameworkTimer.GetTime();
Refresh();
}
Device device = DialogResourceManager.GetGlobalInstance().Device;
// Set up a state block here and restore it when finished drawing all the controls
DialogResourceManager.GetGlobalInstance().StateBlock.Capture();
// Set some render/texture states
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.AlphaTestEnable = false;
device.TextureState[0].ColorOperation = TextureOperation.SelectArg2;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
device.RenderState.ZBufferEnable = false;
// Clear vertex/pixel shader
device.VertexShader = null;
device.PixelShader = null;
// Render if not minimized
if (!isDialogMinimized)
{
device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, vertices);
}
// Reset states
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
device.SamplerState[0].MinFilter = TextureFilter.Linear;
// Set the texture up, and begin the sprite
TextureNode tNode = GetTexture(0);
device.SetTexture(0, tNode.Texture);
DialogResourceManager.GetGlobalInstance().Sprite.Begin(SpriteFlags.DoNotSaveState);
// Render the caption if it's enabled.
if (hasCaption)
{
// DrawSprite will offset the rect down by
// captionHeight, so adjust the rect higher
// here to negate the effect.
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0,-captionHeight,width,0);
DrawSprite(captionElement, rect);
rect.Offset(5, 0); // Make a left margin
string output = caption + ((isDialogMinimized) ? " (Minimized)" : null);
DrawText(output, captionElement, rect, true);
}
// If the dialog is minimized, skip rendering
// its controls.
if (!isDialogMinimized)
{
for(int i = 0; i < controlList.Count; i++)
{
// Focused control is drawn last
if (controlList[i] == controlFocus)
continue;
(controlList[i] as Control).Render(device, elapsedTime);
}
// Render the focus control if necessary
if (controlFocus != null && controlFocus.Parent == this)
controlFocus.Render(device, elapsedTime);
}
// End the sprite and apply the stateblock
DialogResourceManager.GetGlobalInstance().Sprite.End();
DialogResourceManager.GetGlobalInstance().StateBlock.Apply();
}
示例3: HandleMouse
/// <summary>Stores data for a combo box item</summary>
public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
{
if (!IsEnabled || !IsVisible)
return false;
switch(msg)
{
case NativeMethods.WindowMessage.LeftButtonDoubleClick:
case NativeMethods.WindowMessage.LeftButtonDown:
{
NativeMethods.SetCapture(Parent.SampleFramework.Window);
// Check for on up button
if (upButtonRect.Contains(pt))
{
if (position > start)
--position;
UpdateThumbRectangle();
return true;
}
// Check for on down button
if (downButtonRect.Contains(pt))
{
if (position + pageSize < end)
++position;
UpdateThumbRectangle();
return true;
}
// Check for click on thumb
if (thumbRect.Contains(pt))
{
isDragging = true;
thumbOffsetY = pt.Y - thumbRect.Top;
return true;
}
// check for click on track
if (thumbRect.Left <= pt.X &&
thumbRect.Right > pt.X)
{
if (thumbRect.Top > pt.Y &&
trackRect.Top <= pt.Y)
{
Scroll(-(pageSize-1));
return true;
}
else if (thumbRect.Bottom <= pt.Y &&
trackRect.Bottom > pt.Y)
{
Scroll(pageSize-1);
return true;
}
}
break;
}
case NativeMethods.WindowMessage.LeftButtonUp:
{
isDragging = false;
NativeMethods.ReleaseCapture();
UpdateThumbRectangle();
break;
}
case NativeMethods.WindowMessage.MouseMove:
{
if (isDragging)
{
// Calculate new bottom and top of thumb rect
int bottom = thumbRect.Bottom + (pt.Y - thumbOffsetY - thumbRect.Top);
int top = pt.Y - thumbOffsetY;
thumbRect = new System.Drawing.Rectangle(thumbRect.Left, top, thumbRect.Width, bottom - top);
if (thumbRect.Top < trackRect.Top)
thumbRect.Offset(0, trackRect.Top - thumbRect.Top);
else if (thumbRect.Bottom > trackRect.Bottom)
thumbRect.Offset(0, trackRect.Bottom - thumbRect.Bottom);
// Compute first item index based on thumb position
int maxFirstItem = end - start - pageSize; // Largest possible index for first item
int maxThumb = trackRect.Height - thumbRect.Height; // Largest possible thumb position
position = start + (thumbRect.Top - trackRect.Top +
maxThumb / (maxFirstItem * 2) ) * // Shift by half a row to avoid last row covered
maxFirstItem / maxThumb;
return true;
}
break;
}
}
// Was not handled
return false;
}