이제 WPF로 바꿔보세요 (10)

Boke 문제 다시



세팅 항목을 전개 표시할 때의 작은 삼각형.
원래의 Forms판에서는 16×16픽셀의 BMP를 2개 만들어 ON/OFF로 스위치해 pictureBox에 표시하고 있었습니다. 화면 해상도 비율이 1이면 화면 픽셀이 이미지의 픽셀과 일치하므로 자연스럽게 흐려지지 않습니다.

이번 해상도에 따라 컨트롤의 물리 픽셀 사이즈가 자동으로 바뀌기 때문에, 원 화상이 16 픽셀의 고정 사이즈로 작성하고 있으면 확대시에 아무래도 흐려져 표시됩니다 (이전의 notifyIcon 때와 같은 문제).
그럼 어떻게 하면 돼? 라는 것이 됩니다만 생각해 내는 것은 논리 사이즈 16×16 픽셀의 canvas를 작성해 거기에 Draw할 정도 밖에 떠오릅니다. 시험에 구현하고 IMAGE와 CANVAS를 화면에 나란히 보면


왼쪽이 BITMAP를 imagesource 변환하여 Image에 붙인 것. 오른쪽이 Canvas를 만들고 Polygon으로 그린 ​​것. 확실히 모르기 때문에 확대. 네 당연히 20*20픽셀이 되네요.


다른 곳에서도 마찬가지이므로 canvas와 상태를 인수로 분리
 private void DrawArrowBox(Canvas aCanvas , int sw)
        {

            aCanvas.Children.Clear();

            //外枠
            Rectangle myRectangle = new Rectangle();
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();
            mySolidColorBrush.Color = Color.FromArgb(255, 150, 150, 150);
            myRectangle.Fill = mySolidColorBrush;
            myRectangle.StrokeThickness = 1 / 1.25;    //ここは解像度に変更
            myRectangle.Stroke = Brushes.White;
            myRectangle.Width = aCanvas.Width;
            myRectangle.Height = aCanvas.Height;
            aCanvas.Children.Add(myRectangle);

            //三角形
            Polygon myPolygon = new Polygon();
            SolidColorBrush myPolyColorBrush = new SolidColorBrush();

            if (sw == 1)
            {
                System.Windows.Point Point1 = new System.Windows.Point(aCanvas.Width * 2 / 10, aCanvas.Height * 1 / 3);
                System.Windows.Point Point2 = new System.Windows.Point(aCanvas.Width * 8 / 10, aCanvas.Height * 1 / 3);
                System.Windows.Point Point3 = new System.Windows.Point(aCanvas.Width * 1 / 2, aCanvas.Height * 2 / 3);
                System.Windows.Point Point4 = new System.Windows.Point(aCanvas.Width * 2 / 10, aCanvas.Height * 1 / 3);
                PointCollection polygonPoints = new PointCollection();
                polygonPoints.Add(Point1);
                polygonPoints.Add(Point2);
                polygonPoints.Add(Point3);
                polygonPoints.Add(Point4);
                myPolygon.Points = polygonPoints;
                myPolyColorBrush.Color = Color.FromArgb(255, 150, 150, 150);
            }
            else
            {
                System.Windows.Point Point1 = new System.Windows.Point(CanvasSettings.Width * 1 / 3, CanvasSettings.Height - CanvasSettings.Height * 8 / 10);
                System.Windows.Point Point2 = new System.Windows.Point(CanvasSettings.Width * 1 / 3, CanvasSettings.Height - CanvasSettings.Height * 2 / 10);
                System.Windows.Point Point3 = new System.Windows.Point(CanvasSettings.Width - CanvasSettings.Width * 1 / 3, CanvasSettings.Height * 1 / 2);
                System.Windows.Point Point4 = new System.Windows.Point(CanvasSettings.Width * 1 / 3, CanvasSettings.Height - CanvasSettings.Height * 8 / 10);
                PointCollection polygonPoints = new PointCollection();
                polygonPoints.Add(Point1);
                polygonPoints.Add(Point2);
                polygonPoints.Add(Point3);
                polygonPoints.Add(Point4);
                myPolygon.Points = polygonPoints;
                myPolyColorBrush.Color = Color.FromArgb(255, 255, 255, 255);
            }
            myPolygon.Stroke = Brushes.White;
            myPolygon.StrokeThickness = 1 / 1.25;    //ここは解像度に変更
            myPolygon.Fill = myPolyColorBrush;
            aCanvas.Children.Add(myPolygon);
        }


당초 원래의 Canvas를 1회 묘화해, on/off 전환시에는 rotatetransform 시키면 좋을까, 라고 생각했습니다만, 회전의 중심점의 지정 방법이 모르겠다.
결국 poly내의 누키를 바꾸어 재묘화해 버리면, 기술로서는 끈질긴 것이 되어 있습니다.

설정 화면 전환. 너무 편리하다



이전 고민하고 있던 설정부의 표시 비표시입니다만, StackPanel을 구성의 상위에 배치해, 그 아래에 각각의 컨트롤 그룹으로 Grid를 늘어놓고, visibility로 표시 비표시를 전환. StackPanel로 해 두는 것으로 중간의 Grid를 Collapsed로 한 경우, 흘려 들어가 아래의 Grid가 올라 주기 때문에, 귀찮은 위치 조작은 불필요.
메인 Window의 Height에 대상의 Grid의 Height를 가감함으로써 희망의 표현을 할 수 있었습니다.

좋은 웹페이지 즐겨찾기