Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How do I use AddHandler when using IDesignerHost
 

How do I use AddHandler when using IDesignerHost

Here is my current coding...

Code Snippet

Imports System.ComponentModel.Design




Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

Dim surface As New DesignSurface()

Dim host As IDesignerHost = TryCast(surface.GetService(GetType(IDesignerHost)), IDesignerHost)



Dim root As UserControl = TryCast(host.CreateComponent(GetType(UserControl)), UserControl)

root.BackColor = Color.AliceBlue

root.Width = Me.Width - 100

root.Height = Me.Height - 150



Dim flp As FlowLayoutPanel = TryCast(host.CreateComponent(GetType(FlowLayoutPanel)), FlowLayoutPanel)

flp.Text = "FlowLayoutPanel"
flp.Dock = DockStyle.Fill
root.Controls.Add(flp)



Dim tb As TextBox = TryCast(host.CreateComponent(GetType(TextBox)), TextBox)
tb.Size = New Size(50, 100)
tb.Text = "TextBox"

AddHandler tb.MouseDown, Me.mMove

flp.Controls.Add(tb)

End Sub

Public Sub mMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

If e.Button = Windows.Forms.MouseButtons.Right Then

Msgbox ("Hi")

end if

End Sub



For some reason it isn't allowing me to add a handler to anything that is located within the IDesignerHost. Now if i did a normal add of the TextBox to the Windows Form then the AddHandler works. What am i doing wrong?
matt ham  Wednesday, February 06, 2008 11:36 PM
Here is my current coding...

Code Snippet

Imports System.ComponentModel.Design




Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

Dim surface As New DesignSurface()

Dim host As IDesignerHost = TryCast(surface.GetService(GetType(IDesignerHost)), IDesignerHost)



Dim root As UserControl = TryCast(host.CreateComponent(GetType(UserControl)), UserControl)

root.BackColor = Color.AliceBlue

root.Width = Me.Width - 100

root.Height = Me.Height - 150



Dim flp As FlowLayoutPanel = TryCast(host.CreateComponent(GetType(FlowLayoutPanel)), FlowLayoutPanel)

flp.Text = "FlowLayoutPanel"
flp.Dock = DockStyle.Fill
root.Controls.Add(flp)

Dim c As Control = TryCast(surface.View, Control)

c.BackColor = Color.White

c.Width = Me.Width - 30

c.Height = Me.Height - 50

c.Location = New Point(15, 25)

c.Parent = Me

Dim tb As TextBox = TryCast(host.CreateComponent(GetType(TextBox)), TextBox)
tb.Size = New Size(50, 100)
tb.Text = "TextBox"

AddHandler tb.MouseDown, Me.mMove

flp.Controls.Add(tb)

End Sub

Public Sub mMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

If e.Button = Windows.Forms.MouseButtons.Right Then

Msgbox ("Hi")

end if

End Sub



For some reason it isn't allowing me to add a handler to anything that is located within the IDesignerHost. Now if i did a normal add of the TextBox to the Windows Form then the AddHandler works. What am i doing wrong?

I want to be able to make it so whenever i select the textbox, it will do a Message box saying a message.
matt ham  Thursday, February 07, 2008 6:09 PM

You can use google to search for other answers

Custom Search

More Threads

• AVI and background problem
• Using SplitContainer in MDI Form.
• Dataset disappears
• What's the EditorBrowsableState.Advanced meaning?
• panel anchor bug
• GDI+ graphics and viewport
• Strange behaviour when changing language
• Custom control can't be resized with mouse using Width Property
• How can I make VS.NET designer create subclassed menuitems?
• last question