どのように私は、リッチテキストボックスにフラットな外観を与えるのですか?

StackOverflow https://stackoverflow.com/questions/700479

質問

様々な理由のために、通常のテキストボックスの代わりにいくつか -

私は、リッチテキストボックスコントロールの多くを使用しWinFormsのスマートクライアントアプリケーション、に取り組んでいます。残念ながら、リッチテキストボックスではなく、テーマにXPまたはVistaスタイルのボーダーの醜いWin95の3Dの境界線を描画します。

誰でもリッチテキストボックスにテーマに罫線を適用する方法を知っていますか?私は、この目的のためにそれらをサブクラス化する気にしない。

ありがとうございます。

役に立ちましたか?

解決

これは本当にハックですが、あなたが行うことができます一つのことは、ページ上にPanelコントロールをドロップです。 (これはデフォルトではNoneになります。)それをFixedSingleのBorderStyleプロパティを与える。

パネルにあなたのリッチテキストボックスをドロップし、noneにBorderStyleプロパティを設定します。そして、フィルするリッチテキストボックスのDockプロパティを設定します。

このはフラット国境であなたにリッチテキストボックスを与えるだろう。

他のヒント

先頭Iは、テキストボックスは、コンポーネント内部とDockPadding 3つの又は4ピクセルに設定していたであるパネルでこれを解決する必要があった日です。私は、単一のピクセルにそのパネルのスタイルを思います。

私はいつもこれを見つけた本当に迷惑!

私は、これは少し遅すぎる、それにもかかわらず、だと思います。

あなたはいつもあなたが望むようにそれを有効/無効にすることができ、そのようP /呼び出しを使用してUXThemeのAPIを使用してリッチエディットのサブクラスを作成することができます。

私はCodeProjectのは、

ビジュアルUXTheme /スタイルのAPIを使用するリッチエディットコントロールを持っていたと思います

視覚スタイルUXTheme APIロールアウトされた陳腐化またはWindows 8で廃止予定も

ここでは-1と非クライアント領域を膨張した後cadedブルーで非クライアント領域を塗りつぶし、VB.NETコードです。これはSharpDevelopの4.4を使ってC#に変換することができます。私はこの記事からコードを派生します:

のhttp:// WWW。 codeproject.com/Articles/13723/Themed-RichTextBox-A-RichTextBox-with-XP-styled-boする

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles
Imports System.Drawing
Imports System.Diagnostics

Public Class FlatRichTextBox
    Inherits RichTextBox

    Private BorderRect As RECT

    Sub New()
        If VisualStyleInformation.IsEnabledByUser Then
            BorderStyle = BorderStyle.None
        End If
    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        Const WM_NCPAINT = &H85
        Const WM_NCCALCSIZE = &H83
        Const WM_THEMECHANGED = &H31A

        Select Case m.Msg
            Case WM_NCPAINT
                WmNcpaint(m)
            Case WM_NCCALCSIZE
                WmNccalcsize(m)
            Case WM_THEMECHANGED
                UpdateStyles()
            Case Else
                MyBase.WndProc(m)
        End Select
    End Sub

    Private Sub WmNccalcsize(ByRef m As Message)
        MyBase.WndProc(m)

        If Not VisualStyleInformation.IsEnabledByUser Then Return

        Dim par As New NCCALCSIZE_PARAMS()
        Dim windowRect As RECT

        If m.WParam <> IntPtr.Zero Then
            par = CType(Marshal.PtrToStructure(m.LParam, GetType(NCCALCSIZE_PARAMS)), NCCALCSIZE_PARAMS)
            windowRect = par.rgrc0
        End If

        Dim clientRect = windowRect

        clientRect.Left += 1
        clientRect.Top += 1
        clientRect.Right -= 1
        clientRect.Bottom -= 1

        BorderRect = New RECT(clientRect.Left - windowRect.Left,
                              clientRect.Top - windowRect.Top,
                              windowRect.Right - clientRect.Right,
                              windowRect.Bottom - clientRect.Bottom)

        If m.WParam = IntPtr.Zero Then
            Marshal.StructureToPtr(clientRect, m.LParam, False)
        Else
            par.rgrc0 = clientRect
            Marshal.StructureToPtr(par, m.LParam, False)
        End If

        Const WVR_HREDRAW = &H100
        Const WVR_VREDRAW = &H200
        Const WVR_REDRAW = (WVR_HREDRAW Or WVR_VREDRAW)

        m.Result = New IntPtr(WVR_REDRAW)
    End Sub

    Private Sub WmNcpaint(ByRef m As Message)
        MyBase.WndProc(m)

        If Not VisualStyleInformation.IsEnabledByUser Then Return

        Dim r As RECT
        GetWindowRect(Handle, r)

        r.Right -= r.Left
        r.Bottom -= r.Top
        r.Top = 0
        r.Left = 0

        r.Left += BorderRect.Left
        r.Top += BorderRect.Top
        r.Right -= BorderRect.Right
        r.Bottom -= BorderRect.Bottom

        Dim hDC = GetWindowDC(Handle)
        ExcludeClipRect(hDC, r.Left, r.Top, r.Right, r.Bottom)

        Using g = Graphics.FromHdc(hDC)
            g.Clear(Color.CadetBlue)
        End Using

        ReleaseDC(Handle, hDC)
        m.Result = IntPtr.Zero
    End Sub

    <DllImport("user32.dll")>
    Public Shared Function GetWindowRect(hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
    End Function

    <DllImport("user32.dll")>
    Public Shared Function GetWindowDC(hWnd As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")>
    Public Shared Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As Integer
    End Function

    <DllImport("gdi32.dll")>
    Public Shared Function ExcludeClipRect(hdc As IntPtr, nLeftRect As Integer, nTopRect As Integer, nRightRect As Integer, nBottomRect As Integer) As Integer
    End Function

    <StructLayout(LayoutKind.Sequential)>
    Public Structure NCCALCSIZE_PARAMS
        Public rgrc0, rgrc1, rgrc2 As RECT
        Public lppos As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)>
    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer

        Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
            Me.Left = left
            Me.Top = top
            Me.Right = right
            Me.Bottom = bottom
        End Sub
    End Structure
End Class

3D-国境を取り除くための最も簡単な方法は、別のものを設定することです

richTextBox.BorderStyle = BorderStyle.FixedSingle;

FixedSingle-のBorderStyleは、例えばのFlatStyleに最も近いですボタン

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top