小编Dur*_*a S的帖子

直线与圆相交时如何找到交点

我想在圆的底部放置一个矩形,如下所示,

在此处输入图片说明

但是我无法得到相交点来放置矩形。

在此处输入图片说明

例:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent(); circleHeight = (circleWidth / 3) * 2;
        this.panel1.Paint += Panel1_Paint;
    }
    int circleWidth = 314;
    int circleHeight;
    int FrameThickness = 12;
    private void Panel1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
        GraphicsPath pth = new GraphicsPath();
        System.Drawing.Drawing2D.GraphicsPath basePath = new System.Drawing.Drawing2D.GraphicsPath();

        int x = this.circleWidth;

        int rectWidth = (int)Math.Ceiling(this.circleWidth * 0.94); // 94 % of the actual circle width            
        int rectRimWidth = rectWidth - …
Run Code Online (Sandbox Code Playgroud)

c# winforms

5
推荐指数
0
解决办法
98
查看次数

动态资源合并不将样式应用于第一个控件

我尝试通过在将控件添加到 UI 的同时将样式资源合并到应用程序资源来为我的自定义控件应用新样式,但新样式并未首次应用于控件。

样品控制

CustomTextBoxExt.cs

 public class CustomTextBoxExt : TextBox
    {
        static CustomTextBoxExt()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomTextBoxExt), new FrameworkPropertyMetadata(typeof(CustomTextBoxExt)));
        }
    }
Run Code Online (Sandbox Code Playgroud)

默认样式 Generic.xaml

 <Style x:Key="TextBoxExtStyle" TargetType="{x:Type local:CustomTextBoxExt}">
    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
    <Setter Property="BorderBrush" Value="Red" />
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="AllowDrop" Value="True" />
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
    <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CustomTextBoxExt}">
                <Border
                    x:Name="border"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding …
Run Code Online (Sandbox Code Playgroud)

wpf xaml custom-controls wpf-controls resourcedictionary

5
推荐指数
1
解决办法
225
查看次数