Benutzer mit den meisten Antworten
RichTextBox mit Hintergrund?

Frage
Antworten
-
Hallo Der-Fuchs10,
In VB.NET würde das so gehen:
1. Ein neues Windows Forms Applikation Projekt erstellen.
2. Eine neue Klasse zum Projekt hinzufügen.
3. Klasse speichern und Build
4. Die Custom Kontrolle auf die Form bringen.
Code für die Klasse (erstellt eine anwendungsspezifische RichTextBox Kontrolle:
Imports System Imports System.Windows.Forms Imports System.Runtime.InteropServices Public Class _RichTextBox Inherits RichTextBox #Region "Params" <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Public Shared Function LoadLibrary(ByVal path As String) As IntPtr End Function Private Shared moduleHandle As IntPtr Protected Overrides ReadOnly Property CreateParams() As _ System.Windows.Forms.CreateParams Get If moduleHandle = IntPtr.Zero Then moduleHandle = LoadLibrary("msftedit.dll") If CType(moduleHandle, Integer) < &H20 Then Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), _ "Could not load Msftedit.dll") End If End If Dim cParams As CreateParams = MyBase.CreateParams cParams.ClassName = "RichEdit50W" If Me.Multiline = True Then If ((Me.ScrollBars And RichTextBoxScrollBars.Horizontal) <> _ RichTextBoxScrollBars.None) _ AndAlso MyBase.WordWrap = False Then cParams.Style = cParams.Style Or &H100000 If (Me.ScrollBars And CType(&H10, RichTextBoxScrollBars)) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H2000 End If End If End If If (Me.ScrollBars And RichTextBoxScrollBars.Vertical) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H200000 If (Me.ScrollBars And CType(&H10, RichTextBoxScrollBars)) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H2000 End If End If If BorderStyle.FixedSingle = MyBase.BorderStyle AndAlso _ (cParams.Style And &H800000) <> 0 Then cParams.Style = cParams.Style And -8388609 cParams.ExStyle = cParams.ExStyle Or &H200 End If cParams.ExStyle = cParams.ExStyle Or &H20 '//WS_EX_TRANSPARENT = 0x20 Return cParams End Get End Property Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs) ' MyBase.OnPaintBackground(pevent) End Sub Public Sub New() Me.SetStyle(ControlStyles.DoubleBuffer, True) Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) '//Me.ScrollBars = RichTextBoxScrollBars.None End Sub #End Region End Class
Die Custom Kontrolle auf die Form bringen.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim mycontrol As New _RichTextBox Controls.Add(mycontrol) End Sub
Grüße,
Robert
- Als Antwort markiert Application-Developer Freitag, 8. Januar 2010 21:09
-
Hallo,
Du kannst nicht einfach Deine Hintergrund Ressource als Argument für die OnPaintBackground Methode übergeben. Diese Methode erwartet einen PaintEventArgs Typ. Wenn Du Deine Hintergrund Ressource zeichnen lassen möchtest, würdest Du das etwa über
pevent.Graphics.DrawImage
erledigen. Stell Dir das aber nicht zu einfach vor.
Thorsten Dörfler
Microsoft MVP Visual Basic- Als Antwort markiert Application-Developer Samstag, 9. Januar 2010 21:38
Alle Antworten
-
Hallo,
Du kannst es mal versuchen mit:
http://www.codeproject.com/KB/edit/AlphaBlendedTextControls.aspx
(ist allerdings C#)
Gruß Elmar- Als Antwort vorgeschlagen Thorsten Dörfler Mittwoch, 6. Januar 2010 11:24
-
Hallo Der-Fuchs10,
In VB.NET würde das so gehen:
1. Ein neues Windows Forms Applikation Projekt erstellen.
2. Eine neue Klasse zum Projekt hinzufügen.
3. Klasse speichern und Build
4. Die Custom Kontrolle auf die Form bringen.
Code für die Klasse (erstellt eine anwendungsspezifische RichTextBox Kontrolle:
Imports System Imports System.Windows.Forms Imports System.Runtime.InteropServices Public Class _RichTextBox Inherits RichTextBox #Region "Params" <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Public Shared Function LoadLibrary(ByVal path As String) As IntPtr End Function Private Shared moduleHandle As IntPtr Protected Overrides ReadOnly Property CreateParams() As _ System.Windows.Forms.CreateParams Get If moduleHandle = IntPtr.Zero Then moduleHandle = LoadLibrary("msftedit.dll") If CType(moduleHandle, Integer) < &H20 Then Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), _ "Could not load Msftedit.dll") End If End If Dim cParams As CreateParams = MyBase.CreateParams cParams.ClassName = "RichEdit50W" If Me.Multiline = True Then If ((Me.ScrollBars And RichTextBoxScrollBars.Horizontal) <> _ RichTextBoxScrollBars.None) _ AndAlso MyBase.WordWrap = False Then cParams.Style = cParams.Style Or &H100000 If (Me.ScrollBars And CType(&H10, RichTextBoxScrollBars)) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H2000 End If End If End If If (Me.ScrollBars And RichTextBoxScrollBars.Vertical) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H200000 If (Me.ScrollBars And CType(&H10, RichTextBoxScrollBars)) <> _ RichTextBoxScrollBars.None Then cParams.Style = cParams.Style Or &H2000 End If End If If BorderStyle.FixedSingle = MyBase.BorderStyle AndAlso _ (cParams.Style And &H800000) <> 0 Then cParams.Style = cParams.Style And -8388609 cParams.ExStyle = cParams.ExStyle Or &H200 End If cParams.ExStyle = cParams.ExStyle Or &H20 '//WS_EX_TRANSPARENT = 0x20 Return cParams End Get End Property Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs) ' MyBase.OnPaintBackground(pevent) End Sub Public Sub New() Me.SetStyle(ControlStyles.DoubleBuffer, True) Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) '//Me.ScrollBars = RichTextBoxScrollBars.None End Sub #End Region End Class
Die Custom Kontrolle auf die Form bringen.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim mycontrol As New _RichTextBox Controls.Add(mycontrol) End Sub
Grüße,
Robert
- Als Antwort markiert Application-Developer Freitag, 8. Januar 2010 21:09
-
Hallo,
erstmal vielen herzlichen Dank für diese schnelle und gute Antwort :)
Leider mache ich wohl noch einen kleinen Fehler...
bei:
Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs) MyBase.OnPaintBackground(My.Resources.notiz_background) End Sub
unterstreicht er mir mit blau "My.Resources.notiz_background" obwohl die Resource-Datei existiert.
PS. Die Resource-Datei ist eine .jpg-Datei.
MFG Der-Fuchs10 -
Hallo,
Du kannst nicht einfach Deine Hintergrund Ressource als Argument für die OnPaintBackground Methode übergeben. Diese Methode erwartet einen PaintEventArgs Typ. Wenn Du Deine Hintergrund Ressource zeichnen lassen möchtest, würdest Du das etwa über
pevent.Graphics.DrawImage
erledigen. Stell Dir das aber nicht zu einfach vor.
Thorsten Dörfler
Microsoft MVP Visual Basic- Als Antwort markiert Application-Developer Samstag, 9. Januar 2010 21:38