线条和不透明度

发布于 2024-09-29 03:41:23 字数 132 浏览 5 评论 0原文

我想在 C# 中的控件上画一条不透明的线。

我用 Visual Basic powerpacks shapecontrol 尝试了这个。但我找不到任何设置不透明度的属性。

如何画一条不透明的线?

谢谢,

I would like to draw an opaque line on a control in c#.

I tried this with visual basic powerpacks shapecontrol.. but I couldn't find any properties that set opacity.

How do I draw an opaque line ?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲鸠 2024-10-06 03:41:23

此代码将绘制两条半透明白线的十字。

WPF

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" Background="LightGray">
    <Grid>
        <Line X1="0" Y1="0" X2="100" Y2="100" Stroke="White" Opacity=".5" StrokeThickness="10" />
        <Line X1="0" Y1="100" X2="100" Y2="0" Stroke="White" Opacity=".5" StrokeThickness="10" />
    </Grid>
</Window>

Windows.Forms

var pen = new Pen(Color.FromArgb(128, 255, 255, 255), 10);
using (var g = CreateGraphics())
{
    g.DrawLine(pen, 0, 0, 100, 100);
    g.DrawLine(pen, 0, 100, 100, 0);
}

This code will draw a cross of two half-transparent white lines.

WPF

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" Background="LightGray">
    <Grid>
        <Line X1="0" Y1="0" X2="100" Y2="100" Stroke="White" Opacity=".5" StrokeThickness="10" />
        <Line X1="0" Y1="100" X2="100" Y2="0" Stroke="White" Opacity=".5" StrokeThickness="10" />
    </Grid>
</Window>

Windows.Forms

var pen = new Pen(Color.FromArgb(128, 255, 255, 255), 10);
using (var g = CreateGraphics())
{
    g.DrawLine(pen, 0, 0, 100, 100);
    g.DrawLine(pen, 0, 100, 100, 0);
}
埋情葬爱 2024-10-06 03:41:23

感谢您的帮助,
我找到了另一种不使用WPF的方法。

C# wnidows 窗体具有 Opacity 属性,因此

  1. 创建一个覆盖 windows 窗体的屏幕层。
  2. 通过将透明度键设置为与图层背景颜色相同的颜色,使屏幕图层透明。
  3. 当Windows窗体加载时,将图层的大小更改为与Windows窗体相同。
  4. 确保屏幕层与窗口窗体一起移动。
  5. 使用 ShapeControl (Visual Basic Power Pack)或 Graphic 在图层上绘制任何形状,如上面的答案。
  6. 设置不透明度 = 0.5

Thanks for your help,
I found another way without using WPF.

C# wnidows form has Opacity property, so

  1. Create a screen layer that covers the windows form.
  2. make the screen layer to be transparent by setting transparencykey to be the same color as the layer back color.
  3. when the windows form is being loaded, change the size of layer to be the same as the windows form.
  4. make sure to move screen layer along with the windows form.
  5. draw any shapes on the layer by using ShapeControl (visual basic power pack) or Graphic like the answer above.
  6. set Opacity = 0.5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文