I am building a popup keyboard. I'm using sendkeys, so I don't want the form/keyboard to take focus. This code prevents that:
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
However, when I try to move the form/keyboard it doesn't move smoothly. It will move, but only after you release the mouse. Is there a way that I can have both, no focus and move smoothly?
I added:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOVING Then
Dim r As RECT
r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
Me.Location = New Point(r.Left, r.Top)
End If
MyBase.WndProc(m)
End Sub
which then allowed the form to move correctly.
Here's all of the code:
Imports System.Runtime.InteropServices
Private Const WS_CHILD = &H40000000
Private Const WS_EX_NOACTIVATE = &H8000000
Private Const WM_MOVING = &H216
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim p As CreateParams = MyBase.CreateParams
p.Style = p.Style Or WS_CHILD
p.ExStyle = p.ExStyle Or WS_EX_NOACTIVATE
Return p
End Get
End Property
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOVING Then
Dim r As RECT
r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
Me.Location = New Point(r.Left, r.Top)
End If
MyBase.WndProc(m)
End Sub
Related
I've developed a program that inserts an array of Panel-like controls into another Panel control, the code is as follows:
Dim ModSe As Bitmap = Nothing
ModSe = My.Resources.example
Dim pbdoors As New Panel With {
.Width = 100,
.Height = 200,
.Top = 10,
.Left = 10,
.BorderStyle = BorderStyle.FixedSingle,
.BackgroundImage = ModSe,
.BackgroundImageLayout = ImageLayout.Stretch,
.ContextMenuStrip = CntxtMnuStrpUnit,
.Name = ("Test")
}
But when I see the arrangement of Panel controls already inserted, when I step over a control type Tab, they start to flash as if it were a strobe light. In this case, for my Form, I went to the "DoubleBuffered" property and set it to True, but it keeps flashing.
Add the following without any results.
Public Class FlickerPanel
Inherits System.Windows.Forms.Panel
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.EnableNotifyMessage, True)
End Sub
Protected Overrides Sub OnNotifyMessage(ByVal m As Message)
If (m.Msg <> &H14) Then
MyBase.OnNotifyMessage(m)
End If
End Sub
End Class
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
'Dim cp As CreateParams = MyBase.CreateParams
'cp.ExStyle = cp.ExStyle Or 33554432
'Return cp
Dim cp As CreateParams = MyBase.CreateParams
Dim OSVer As Version = System.Environment.OSVersion.Version()
Select Case OSVer.Major
Case Is <= 5
Case 5
If OSVer.Minor > 0 Then
cp.ExStyle = cp.ExStyle Or &H2000000
End If
Case Is > 5
cp.ExStyle = cp.ExStyle Or &H2000000
Case Else
End Select
Return cp
End Get
End Property
Please, how can I eliminate this flicker?
I have a modified ListView. When I scroll using the mouse wheel, it scrolls three rows.
I want it to scroll one row at a time using the mouse wheel.
Public Class listviewEx
Inherits ListView
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As IntPtr, ByVal wBar As Integer,
ByVal bShow As Boolean) As Integer
' Constants
Private Const SB_HORZ As Integer = 0
Private Const WM_HSCROLL As Integer = &H114
Private Const WM_VSCROLL As Integer = &H115
Public Event Scroll As ScrollEventHandler
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
ShowScrollBar(MyBase.Handle, SB_HORZ, False)
If m.Msg = &H115 Then
' Trap WM_VSCROLL
End If
End Sub
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.EnableNotifyMessage, True)
End Sub
End Class
You can add a behavior to your ListView, to make it scroll one row instead of the default three, using the Ctrl key (as this modifier is often used to change this kind of behaviors) in combination with the mouse wheel.
You can then have the standard three-rows scroll when Ctrl is not pressed and one-row scroll behavior when it's pressed.
Override WndProc (as you're already doing), to handle WM_MOUSEWHEEL and verify that the Ctrl key is pressed, checking whether the low-word of WParam is MK_CONTROL = &H08.
When it's pressed, determine whether the delta is positive or negative and increment the value returned by ListView.TopItem.Index to then set the TopItem based on the calculated offset (adding a minimum/maximum check to avoid overflows):
Imports System.Windows.Forms
Public Class ListViewEx
Inherits ListView
Private Const WM_MOUSEWHEEL As Integer = &H20A
Private Const MK_CONTROL As Integer = &H8
Public Sub New()
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case WM_MOUSEWHEEL
If Items.Count > 0 AndAlso (m.WParam.ToInt64() And &HFF) = MK_CONTROL Then
Dim offset = If((m.WParam.ToInt64() >> 16) > 0, -1, 1) + TopItem.Index
offset = Math.Max(Math.Min(offset, Items.Count - 1), 0)
TopItem = Items(offset)
m.Result = IntPtr.Zero
End If
End Select
End Sub
End Class
Someone named Viorel did it:
Public Class listviewEx
Inherits ListView
Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_MOUSEWHEEL = &H20A
Select Case m.Msg
Case WM_MOUSEWHEEL
If TopItem IsNot Nothing Then
Dim d As Int16 = (m.WParam.ToInt32 >> 16)
Dim i As Integer
If d > 0 Then
i = Math.Max(TopItem.Index - 1, 0)
Else
i = Math.Min(TopItem.Index + 1, Items.Count - 1)
End If
TopItem = Items(i)
End If
m.Result = IntPtr.Zero
Return
End Select
MyBase.WndProc(m)
End Sub
End Class
public Class BotaoEmergencia
Private pressedcolorvermelho As SolidColorBrush = "#d73f3e".ToBrush()
Private pressedfundoamarelo As SolidColorBrush = DirectCast(New BrushConverter().ConvertFrom("#FFF500"), SolidColorBrush)
Private pressedDisabledColor As SolidColorBrush = DirectCast(New BrushConverter().ConvertFrom("#DA251D"), SolidColorBrush)
Private pressedcontornolinhas As SolidColorBrush = DirectCast(New BrushConverter().ConvertFrom("#da251d"), SolidColorBrush)
Public Shared ReadOnly IsPressedProperty As DependencyProperty = DependencyProperty.Register("IsPressed", GetType(Boolean), GetType(BotaoEmergencia), New PropertyMetadata(False, AddressOf OnIsPressedChanged))
Public Property IsPressed() As Boolean
Get
Return DirectCast(GetValue(IsPressedProperty), Boolean)
End Get
Set(value As Boolean)
SetValue(IsPressedProperty, value)
End Set
End Property
Public Shared Sub OnIsPressedChanged(source As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim botao As BotaoEmergencia = TryCast(source, BotaoEmergencia)
botao.ActualizarDesenho()
End Sub
Private Sub UserControl_IsEnabledChanged(sender As Object, e As DependencyPropertyChangedEventArgs) Handles Me.IsEnabledChanged
ActualizarDesenho()
End Sub
Protected Sub ActualizarDesenho()
If IsEnabled Then
If IsPressed Then
Canvas.SetTop(elpCamadaVermelha1, 9.45)
Canvas.SetLeft(elpCamadaVermelha1, -20)
Canvas.SetTop(elpCamadaVermelha2, -122)
Canvas.SetLeft(elpCamadaVermelha2, -61)
Canvas.SetTop(elpContornoBotao, 16.8)
Canvas.SetLeft(elpContornoBotao, 78)
elpContornoBotao.Width = 52
elpContornoBotao.Height = 52
elpContornoBotao.Stroke = If(IsEnabled, pressedcontornolinhas, pressedcontornolinhas)
elpCamadaVermelha1.Fill = If(IsEnabled, pressedcolorvermelho, pressedcolorvermelho)
elpCamadaVermelha2.Stroke = If(IsEnabled, pressedcontornolinhas, pressedcontornolinhas)
elpCamadaVermelha2.StrokeThickness = 0.8
elpFundoAmarelo.Fill = If(IsEnabled, pressedfundoamarelo, pressedfundoamarelo)
Hello guys im making some buttons for a software that im working, and i need to give some 3D vision thats why i wanna use gradient.
This is my code for solidcolorbrush, i wanna make some Gradientcolorbrush but i don't know how can i make it from here...
Can you guys help?
Got it thx anyway -> -> ->
Private normalgradientbigcircle As LinearGradientBrush = New LinearGradientBrush(Color.FromRgb(219, 142, 141), Color.FromRgb(212, 7, 7), New Point(0.5, 0), New Point(0.5, 1))
I derived a component from System.Windows.Forms.ScrollableControl and I have problems to add border property. I tried with CreateParams but without success, maybe I miss something?
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim params As CreateParams = MyBase.CreateParams
params.Style = params.Style Or &H800000 ' Turn on WS_BORDER
Return params
End Get
End Property
'disable scroll bars, this part also disables my border
Protected Overrides Sub DefWndProc(ByRef m As Message)
If m.Msg <> 131 Then
MyBase.DefWndProc(m)
End If
End Sub
Looks like you want to have a border property of true/false:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim params As CreateParams = MyBase.CreateParams
If _Border Then
params.Style = params.Style Or &H800000 ' Turn on WS_BORDER
End If
Return params
End Get
End Property
Private _Border As Boolean = False
Property Border() As Boolean
Get
Return _Border
End Get
Set(ByVal value As Boolean)
_Border = value
Me.RecreateHandle()
Me.Invalidate()
End Set
End Property
Bob Powell has an article regarding that: Adding a standard border to a control
Ok, solved to have no scrollbars and the nice standard border property together :) Here is the code, in case anyone needs:
Region "Disable scroll bars"
<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
End Function
Protected Overrides Sub DefWndProc(ByRef m As Message)
If m.Msg = 131 Then
ShowScrollBar(m.HWnd, 3, 0)
End If
MyBase.DefWndProc(m)
End Sub
End Region
I would like to overrides the datetimepicker object to remove the texte when the property _clearOnDisabled is true. When _readOnly property is true, I would like to show the text in black not gray.
So I tried with WndProc but I seem that every single object go through my function not only my datetimepicker. I get 100% CPU when I put the WM_PAINT message. I also tried to overrides the OnPaint but its not getting in.
Thx for the help
Imports System.Drawing
Imports System.Windows.Forms
Imports DTP.WindowsMessages
Public Class DTP
Inherits System.Windows.Forms.DateTimePicker
Private _readOnly As Boolean = False
Private _clearOnDisabled As Boolean = True
Private _backColorReadOnly As Color = MyBase.BackColor
Public Sub New()
MyBase.New()
End Sub
Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As Color)
MyBase.BackColor = Value
If Not _readOnly Then
Me.Invalidate()
End If
End Set
End Property
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_ERASEBKGND
Dim g As Graphics = Graphics.FromHdc(m.WParam)
Dim backBrush As SolidBrush
If _readOnly Then
backBrush = New SolidBrush(_backColorReadOnly)
g.FillRectangle(backBrush, Me.ClientRectangle)
Else
backBrush = New SolidBrush(MyBase.BackColor)
g.FillRectangle(backBrush, Me.ClientRectangle)
End If
g.Dispose()
Case WM_LBUTTONDOWN, WM_KEYDOWN
If Not _readOnly Then
MyBase.WndProc(m)
End If
'Case WM_PAINT ', WM_NCPAINT, WM_DRAWITEM
' If Not _clearOnDisabled Then
' MyBase.WndProc(m)
' End If
Case Else
MyBase.WndProc(m)
End Select
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Not _clearOnDisabled Then
MyBase.OnPaint(e)
End If
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(pevent)
End Sub
Public Property [ReadOnly]() As Boolean
Get
Return _readOnly
End Get
Set(ByVal Value As Boolean)
_readOnly = Value
Me.Invalidate()
End Set
End Property
Public Property BackColorReadOnly() As Color
Get
Return _backColorReadOnly
End Get
Set(ByVal Value As Color)
_backColorReadOnly = Value
If _readOnly Then
Me.Invalidate()
End If
End Set
End Property
End Class
Don't eat the paint message, but paint after it:
Case WM_PAINT
MyBase.WndProc(m)
If _clearOnDisabled Then
Dim dc As IntPtr = GetWindowDC(Me.Handle)
Using g As Graphics = Graphics.FromHdc(dc)
g.FillRectangle(SystemBrushes.Window, New Rectangle(SystemInformation.Border3DSize.Width, _
SystemInformation.Border3DSize.Height, _
Me.ClientSize.Width - SystemInformation.VerticalScrollBarWidth, _
Me.ClientSize.Height))
End Using
ReleaseDC(Me.Handle, dc)
End If
You can get rid of your OnPaint, OnPaintBackground overrides.