HitTest.zip
0.01MB

These days I need a HitTest program which is circle sector with empty in the middle of it and there are some rectangles.

 

There is a rectangle In the middle of the circle and the hit count of the circle is one.

I referenced lots of good articles and thanks for them.

 

This sample is so simple that I will explain it brifly.

Please see the source.

Thank you.

 

This is DrawImagtes, that is drawing sector circle and one rectangle.

        private void DrawImages()
        {
            PathGeometry pg1 = DrawArc(40, 100, new Point(100, 100), 0);
            PathGeometry pg2 = DrawArc(40, 60, new Point(100, 100), 0);

            PathGeometry pg3 = DrawArc(40, 100, new Point(100, 100), 90);
            PathGeometry pg4 = DrawArc(40, 60, new Point(100, 100), 90);

            PathGeometry pg5 = DrawArc(40, 100, new Point(100, 100), 180);
            PathGeometry pg6 = DrawArc(40, 60, new Point(100, 100), 180);

            PathGeometry pg7 = DrawArc(40, 100, new Point(100, 100), 270);
            PathGeometry pg8 = DrawArc(40, 60, new Point(100, 100), 270);

            Rectangle rect1 = new Rectangle();
            rect1.Width = 10;
            rect1.Height = 10;
            rect1.Fill = Brushes.Red;
            Canvas.SetTop(rect1, 100);
            Canvas.SetLeft(rect1, 100);
            canvas1.Children.Add(rect1);
        }

And DrawArc function is as follow.

   private PathGeometry DrawArc(int interval, int size, Point center, int angle)
        {
            PathFigure pf1 = new PathFigure();

            switch (angle)
            {
                case 0:
                    pf1.StartPoint = new Point(center.X, center.Y - size);

                    pf1.Segments.Add(
                    new ArcSegment(
                        new Point(center.X + size, center.Y),
                        new Size(size, size),
                        0,
                        false, /* IsLargeArc */
                        SweepDirection.Clockwise,
                        true /* IsStroked */ ));

                    pf1.Segments.Add(
                        new LineSegment(
                            new Point(center.X + size - interval, center.Y),


                    pf1.Segments.Add(
                    new ArcSegment(
                        new Point(center.X, center.Y - size + interval),
                        new Size(size - interval, size - interval),
                        0,
                        false, /* IsLargeArc */
                        SweepDirection.Counterclockwise,
                        true /* IsStroked */ ));

                    pf1.Segments.Add(
                        new LineSegment(
                            pf1.StartPoint,
                            true /* IsStroked */ ));
                    break;
              .........................
            }

            PathGeometry pg1 = new PathGeometry();
            pg1.Figures.Add(pf1);

            Path p1 = new Path();
            p1.Stroke = Brushes.Black;
            p1.StrokeThickness = 2;
            p1.Data = pg1;

            canvas1.Children.Add(p1);
            return pg1;
        }

'C# > WPF' 카테고리의 다른 글

Make a animation button  (0) 2018.12.19



var strList = new List<string>() { "aaa", "bbb", "ccc" };
var str1 = strList.Aggregate((a, b) => a + ", " + b);

=> result : aaa,bbb


var str2 = strList.Aggregate((a, b) => "'" + a + "', '" + b + "'"); => result : 'aaa','bbb' …

'C# > visualstudio' 카테고리의 다른 글

useful shortcut.  (0) 2019.01.24
What kind of shortcut in VisualStudio 2017 and how to change shortcut.  (0) 2019.01.23

1. How to remove unused using.


Press ctrl and continuously press G and R.

You should not release the ctrl until pressing G and R.


2. Cutting line and past it as a new line in the middle of line.


Press ctrl + x where you want to cut the line.

Press ctrl + v where you want to paste it on the before line.




press ctrl + c



press ctrl + v



3. auto complete


Write if and press tab twice then the 'if' will change as follow.


            if (true)

            {


            }


After you change the true value, Hit enter then cursor is located in the middle of the brace.


You can use it at the almost reserved word.




First open the visual studio and then select 도구 menu.

You can see 사용자지정 menu. Click it then You can see below popup screen.




If you click 키보드 button then you will see below popup.




If you Input any value in the 다음 문자열을 포함하는 명령 표시, You will see the related command.

For example, Input 클래스 text then you can ess below popup.



I am focused at the 프로젝트.클래스 추가.

It's shortcut is Ctrl+Alt+C so if you press it shortcut then you will see add new class dialog.


Additionally, If you change the shortcut then focus ont 바로 가기 키 누르기 textbox and then press keyboard what you want to change value.(for example shift + alt + c.)


'C# > visualstudio' 카테고리의 다른 글

Convert List<string>to a string divided into comma.  (0) 2019.01.30
useful shortcut.  (0) 2019.01.24

AnimatedButton.zip


출처 : https://docs.microsoft.com/ko-kr/dotnet/framework/wpf/controls/walkthrough-create-a-button-by-using-xaml


Sometimes I found good articles.

This is one of those.


In this lecture, I will explain how to make to glass button.


First make a project named AnimatedButton.


And then open MainWindow.xaml and replace <Grid> to below code.


<Window...>

    <StackPanel HorizontalAlignment="Left">
        <Button>Button 1</Button>
        <Button>Button 2</Button>
        <Button>Button 3</Button>
    </StackPanel>

</Window>


First run the application and see how to display the program.


Open the App.xaml.

This file is global file. 

So if you add style in it, it will apply to all the control.

If you specify TargetType then the style is just applied to the specific TargetType.


Change the App.xaml as follow.


<Application.Resources> 
  <Style TargetType="Button">
    <Setter Property="Width" Value="90" />
    <Setter Property="Margin" Value="10" />
  </Style> 
</Application.Resources>


The TargetType is Button, so the style is applied to only Button controls.


I attached full source so you can run it.


If this is hard for you to understand, change source code and test a lot.


Thank you.

'C# > WPF' 카테고리의 다른 글

circle sector HitTest example in wpf  (0) 2019.05.20

+ Recent posts