ID2D1RenderTarget::D rawRoundedRectangle (constD2D1_ROUNDED_RECT*,ID2D1Brush*,FLOAT,ID2D1StrokeStyle*) 方法 (d2d1.h)
使用指定的筆劃樣式繪製指定圓角矩形的外框。
語法
void DrawRoundedRectangle(
const D2D1_ROUNDED_RECT *roundedRect,
ID2D1Brush *brush,
FLOAT strokeWidth,
ID2D1StrokeStyle *strokeStyle
);
參數
roundedRect
類型:[in] const D2D1_ROUNDED_RECT*
要繪製之圓角矩形的維度,以裝置無關的圖元為單位。
brush
類型:[in] ID2D1Brush*
用來繪製圓角矩形外框的筆刷。
strokeWidth
類型:[in] FLOAT
筆劃的寬度,以裝置無關的圖元為單位。 此值必須大於或等於 0.0f。 如果未指定此參數,則預設為 1.0f。 筆劃線上條上置中。
strokeStyle
類型:[in, 選擇性] ID2D1StrokeStyle*
圓角矩形筆劃的樣式,或要繪製實心筆劃的 Null 。 預設值是 NULL。
傳回值
無
備註
如果此方法失敗,此方法不會傳回錯誤碼。 若要判斷繪圖作業是否 (例如 DrawRoundedRectangle) 失敗,請檢查 ID2D1RenderTarget::EndDraw 或 ID2D1RenderTarget::Flush 方法傳回的結果。
範例
下列範例會使用 DrawRoundedRectangle 和 FillRoundedRectangle 方法來大綱和填滿圓角矩形。 此範例會產生下圖所示的輸出。
// Called whenever the application needs to display the client
// window.
HRESULT DrawAndFillRoundedRectangleExample::OnRender()
{
HRESULT hr;
// Create the render target and brushes if they
// don't already exists.
hr = CreateDeviceResources();
if (SUCCEEDED(hr))
{
// Retrieve the size of the render target.
D2D1_SIZE_F renderTargetSize = m_pRenderTarget->GetSize();
m_pRenderTarget->BeginDraw();
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
// Paint a grid background.
m_pRenderTarget->FillRectangle(
D2D1::RectF(0.0f, 0.0f, renderTargetSize.width, renderTargetSize.height),
m_pGridPatternBitmapBrush
);
// Define a rounded rectangle.
D2D1_ROUNDED_RECT roundedRect = D2D1::RoundedRect(
D2D1::RectF(20.f, 20.f, 150.f, 100.f),
10.f,
10.f
);
// Draw the rectangle.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f);
// Apply a translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(200.f, 0.f));
// Draw the rounded rectangle again, this time with a dashed stroke.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
// Apply another translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0.f, 150.f));
// Draw, then fill the rounded rectangle.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
m_pRenderTarget->FillRoundedRectangle(roundedRect, m_pSilverBrush);
// Apply another translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(200.f, 150.f));
// Fill, then draw the rounded rectangle.
m_pRenderTarget->FillRoundedRectangle(roundedRect, m_pSilverBrush);
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
hr = m_pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardDeviceResources();
}
}
return hr;
}
規格需求
目標平台 | Windows |
標頭 | d2d1.h |
程式庫 | D2d1.lib |
Dll | D2d1.dll |