I가 어떤 모양 그리는 OnPaint를 기존의 방법해당하는 WPF에 윈도우 폼의 OnPaint 변환은 모양
protected override void OnPaintBackground(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.CompositingQuality = CompositingQuality.HighQuality;
Brush greenBrush = new SolidBrush(Color.FromArgb(73,172,113));
Brush blueBrush = new SolidBrush(Color.FromArgb(197,232,221));
Brush whiteBrush = new SolidBrush(Color.White);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
Rectangle newRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
ClientRectangle.Width, ClientRectangle.Height);
// Green background
g.FillRectangle(greenBrush, newRect);
// Blue ellipse
int rectX = System.Convert.ToInt32(newRect.Width * .244) * -1;
int rectY = System.Convert.ToInt32(newRect.Height * .025);
int rectWidth = System.Convert.ToInt32(newRect.Width * 1.416);
int rectHeight = System.Convert.ToInt32(newRect.Height * 1.685);
g.FillEllipse(blueBrush, rectX, rectY, rectWidth, rectHeight);
// Green ellipse
rectX = System.Convert.ToInt32(newRect.Width * .283) * -1;
rectY = System.Convert.ToInt32(newRect.Height * .035);
rectWidth = System.Convert.ToInt32(newRect.Width * 1.26);
rectHeight = System.Convert.ToInt32(newRect.Height * 1.35);
g.FillEllipse(greenBrush, rectX, rectY, rectWidth, rectHeight);
// Blue ellipse
rectX = System.Convert.ToInt32(newRect.Width * .009) * -1;
rectY = System.Convert.ToInt32(newRect.Height * .175);
rectWidth = System.Convert.ToInt32(newRect.Width * 1.094);
rectHeight = System.Convert.ToInt32(newRect.Height * 1.755);
g.FillEllipse(blueBrush, rectX, rectY, rectWidth, rectHeight);
// White ellipse
rectX = System.Convert.ToInt32(newRect.Width * .146);
rectY = System.Convert.ToInt32(newRect.Height * .225);
rectWidth = System.Convert.ToInt32(newRect.Width * .928);
rectHeight = System.Convert.ToInt32(newRect.Height * 1.545);
g.FillEllipse(whiteBrush, rectX, rectY, rectWidth, rectHeight);
} 나는이를 변환 한
- WPF에서 :
<Grid>
<Viewbox HorizontalAlignment="Left" VerticalAlignment="Top" >
<Canvas Width="1680" Height="1050">
<Rectangle Fill="#FF49AC71" Width="1780" Height="1050" VerticalAlignment="Stretch" />
<Ellipse Fill="#FFC5E8DD" Width="2379" Height="1770" Canvas.Left="-410" Canvas.Top="25"/>
<Ellipse Fill= "#FF49AC71" Width="2116" Height="1417" Canvas.Left="-475" Canvas.Top="37"/>
<Ellipse Fill="#FFC5E8DD" Width="1837" Height="1842" Canvas.Left="-15" Canvas.Top="183"/>
<Ellipse Fill="White" Width="1559" Height="1622" Canvas.Left="245" Canvas.Top="236"/>
</Canvas>
</Viewbox>
을
크기 조정 동작이 동일하지 않습니다. 누군가 나에게이 문제를 해결할 수있는 방법이나 WPF의 더 좋은 예를 들어 줄 수 있습니까?
"동일하지 않은"크기 변경 동작에 대해 자세히 설명 할 수 있습니까? – ChrisF
가장 명백한 차이점은 WinForms 코드에서는 WPF 예제에서 크기와 위치를 하드 코딩했으나 'ClientRectangle'속성을 사용하여 컨트롤의 크기에 따라 요소의 크기와 위치를 결정한다는 점입니다. – ChrisF
ChrisF - 네 - 맞습니다.하지만 저는 Wpf에서 "ClientRectangle"를 사용하는 방법을 볼 수 없습니다. Wpf 버전에서 너비를 늘리려고하면 오른쪽에 흰색 패치가 표시되지만 Windows 양식에서는 예상대로 작동합니다. – hayrob