如何在不影响任何控件的情况下减少表单的不透明度? [英] How can I lessen the opacity of the form without affecting any controls?

查看:68
本文介绍了如何在不影响任何控件的情况下减少表单的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在.net中使我的表单的不透明度降低,但我不希望任何控制因素受到影响。如何在不影响任何控件的情况下减少表单的不透明度?

I want to make the opacity of my form in .net lower but I don't want any contol to be affected. How can I lessen the opacity of the form without affecting any controls?

推荐答案

我当时不知道解决方案。



您必须自定义一个表格,并且在此表格中必须单独处理背景绘画(覆盖OnPaint方法,自己处理不透明度而不是表格本身)
I don't know THE SOLUTION at the Moment.

You have to customize a Form and in this Form the Background-Painting must be handled seperatly (Overriding the OnPaint-method , handling the Opacity by yourself and not by the Form itself)


在WinForms中,你不能轻易做到 - Opacity是表单的一个特性,而不是它包含的控件。

你可以用两种形式做一些看起来正确的事情,一个在另一个之上。顶部窗体包含控件,具有透明背景,无边框等等。下面的形式有不透明度。虽然凌乱。
In WinForms, you can't do it easily - Opacity is a feature of the form, not the controls it contains.
You could do something that looks right, with two forms, one on top of the other. The top form contains the controls, and has a transparent background, is borderless, and so forth. The lower form has the opacity. Messy though.


因为对我来说这还没有解决 - 这是我发布的解决方案的代码(2):



Because for me this isn't solved - here is the codee to my posted solution (2) :

Imports System.ComponentModel

Public Class OpacForm
    Inherits System.Windows.Forms.Form

    Public Sub New()
        Me.SetStyle(ControlStyles.Opaque, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)

        MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub

    <designerserializationvisibility(designerserializationvisibility.hidden)>
    <browsable(false),> _
    Shadows Property FormBorderStyle As FormBorderStyle



    <typeconverterattribute(gettype(opacityconverter))>
    Shadows Property Opacity As Double
        Get
            Return my_Opacity / 255
        End Get
        Set(ByVal value As Double)
            my_Opacity = value * 255
            Me.Refresh()
        End Set
    End Property

    Private my_Opacity As Integer = 255



    Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
        'MyBase.OnPaint(pe)

        Dim gr As System.Drawing.Graphics = pe.Graphics

        Dim myBrush As New SolidBrush(Color.FromArgb(my_Opacity, BackColor))

        gr.FillRectangle(myBrush, 0, 0, Width, Height)

    End Sub

End Class





此表格类必须由您要使用此功能的表格继承。

如果你想要任何类型的背景,它也必须在OnPaint方法中创建。



This Form-Class must be inherited by the Form in which you want to use this Feature.
If you want to have any kind of Background it must also be created inside the OnPaint-method.


这篇关于如何在不影响任何控件的情况下减少表单的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆