RichTextBox에 평평한 모습을 어떻게 제공합니까?
-
22-08-2019 - |
문제
나는 많은 RichTextBox 컨트롤을 사용하는 WinForms SmartClient Application을 사용하고 있습니다. 불행히도 RichTextBox는 테마 XP 또는 Vista 스타일 테두리 대신 Ugly Win95 3D 테두리를 그립니다.
테마 테두리를 RichTextBox에 적용하는 방법을 아는 사람이 있습니까? 나는이 목적을 위해 그들을 서브 클래스하는 것을 신경 쓰지 않는다.
감사!
해결책
이것은 실제로 해킹이지만 당신이 할 수있는 한 가지는 페이지에 패널 컨트롤을 떨어 뜨리는 것입니다. 고정 싱크의 국경을 부여하십시오 (기본적으로 아무것도 아닙니다.)
RichTextBox를 패널에 놓고 Borderstyle을 없음으로 설정하십시오. 그런 다음 RichTextBox의 Dock 속성을 채우도록 설정하십시오.
이것은 평평한 테두리가있는 RichTextBox를 제공합니다.
다른 팁
그 날에 나는 텍스트 상자가 내부 구성 요소이고 도크 패딩을 3 ~ 4 픽셀로 설정 한 패널로 이것을 해결해야했습니다. 그런 다음 그 패널을 단일 픽셀로 스타일링했습니다.
나는 항상 이것이 정말로 성가신 것을 발견했다!
나는 이것이 너무 늦었지만 그럼에도 불구하고.
당신은 언제든지 p/invoke를 사용하고 uxtheme api를 사용하여 Richedit을 서브 클래스를 사용하여 원하는대로 비활성화/활성화 할 수 있습니다.
CodeProject는 Uxtheme/Visual Styles API를 사용한 Ricedit 컨트롤을 가지고 있다고 생각합니다.
Visual Styles uxtheme API가 Windows 8이 출시 될 때 쓸모 없거나 감가 상승세가 될 수 있습니다.
VB.NET 코드는 다음과 같습니다. 비 클라이언트 영역을 -1로 팽창시킨 다음 비 클리어 영역을 캐드 블루로 채 웁니다. 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
예를 들어 버튼