Thủ thuật: Không cho Resize UserControl
Tác giả: KasperMô tả: Không cho Resize UserControl
bài viết được chuyển qua từ:
http://www.caulacbovb.com/forum/viewtop ... =8&t=10655có gì các bạn có thể tham khảo thêm qua link đó nha
tạo một cái UserControl rồi sử dụng code sau
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
If Me.Width < 100 Or Me.Width > 100 Then Me.Width = 100
If Me.Height < 100 Or Me.Height > 100 Then Me.Height = 100
MyBase.OnResize(e)
End Sub
hoặc có thể sử dụng đoạn code sau(code by:1045007)
Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As System.Windows.Forms.BoundsSpecified)
MyBase.SetBoundsCore(x, y, 100, 100, BoundsSpecified.All)
End Sub
tác giả yêu cầu cao hơn một chút là, không cho resize thì không có hình mũi tên 2 chiều khi đưa chuột ra cạnh của control luôn. Giống như cái Textbox single line đó
code như sau:
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.ComponentModel
<Designer(GetType(MyControlDesigner))> _
Public Class FixSizeControl1
Inherits ListBox
Private _Size As Drawing.Size
Public Overloads Property Size()
Get
Return _Size
End Get
Set(ByVal value)
_Size = New Drawing.Size(100, 100)
End Set
End Property
End Class
Friend Class MyControlDesigner
Inherits ControlDesigner
Public Overrides ReadOnly Property SelectionRules() As System.Windows.Forms.Design.SelectionRules
Get
Return SelectionRules.Moveable Or SelectionRules.Visible
End Get
End Property
End Class
thanks Kasper & 1045007 đã chia sẻ
