Я получаю GraphicsControl
из Control
:
public abstract class GraphicsControl : Control
{
GraphicsDeviceService graphicsDeviceService;
protected override void OnCreateControl ( )
{
// Don't initialize the graphics device if we are running in the designer.
if (!DesignMode)
{
graphicsDeviceService =
GraphicsDeviceService.AddReference
(
Handle,
new System.Drawing.Size ( ClientSize.Width,
ClientSize.Height )
);
// Register the service, so components like ContentManager can find it.
services.AddService ( graphicsDeviceService );
// Give derived classes a chance to initialize themselves.
Initialize ( );
}
base.OnCreateControl ( );
}
string DeviceBeginDraw ( )
{
// ensure drawing is valid
// set up viewport
Viewport viewport = new Viewport
(
ClientRectangle.X,
ClientRectangle.Y,
ClientSize.Width,
ClientSize.Height
);
viewport.MinDepth = 0;
viewport.MaxDepth = 1;
GraphicsDevice.Viewport = viewport;
if (viewport.Bounds.Contains ( mouse.X, mouse.Y ))
{
// fire event
OnMouseMoved(this,
new MouseMovedEventArgs(new Microsoft.Xna.Framework.Point(mouse.X, mouse.Y)));
}
}
}
Затем производная Canvas
управления выглядит следующим образом:
public sealed class Canvas : GraphicsControl
{
// subscribe to MousedMoved event
}
Область, реагирующая на движение мыши, расположена в левом верхнем углу экрана (0, 0). Общая область перекрывает предполагаемый базовый элемент управления, но не закреплена, заполняя родительский элемент управления. Смотрите изображение:
![Viewport does not fill the intended parent control area.](https://i.stack.imgur.com/x2Ei3.png)
Может кто-нибудь сказать мне, что я могу делать неправильно? Если требуется дополнительный код, просто спросите.
Кроме того, MSDN, по-видимому, ссылается на ClientRectangle
в качестве используемого свойства.