Windows Forms from VB6

13.1 How do I draw a line in VB7 as there is no Line command as there was in VB6?

Try this code:

Dim g as Graphics

g = frmMain.CreateGraphics()

g.DrawLine(Pens.Black, new Point(0,0), new

Point(frmMain.ClientRectangle.Width), frmMain.ClientRectangle.Height)


This should draw a line from the upper left to the bottom right corner of your application, but only if it's visible. If this code isn't in the paint event, when something obscures your application and/or it repaints, this line will *not* be redrawn.

(from on microsoft.public.dotnet.framework.windowsforms)

Another possible solution that has a design-time element is to use a label with height 1 and FixedSingle Border. (suggested by Mark Lewis in microsoft.public.dotnet.framework.windowsforms)

13.2 What is the replacement for VB6's SendKeys statement?

It is the Send method from the SendKeys class found in the System.Windows.Forms namespace.

13.3 In VB6, I used control arrays to have a common handler handle events from several controls. How can I do this in Windows Forms?

You can specify events from different controls be handled by a single method. When you define your handler, you can list several events that are to be handled by listing them in the Handles argument. This statement handles three different textbox's TextChanged event.

Private Sub TextsChanged(ByVal sender As System.Object, _

ByVal e As System.EventArgs) _

Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged

In the TextsChanged handler, you may need to identify the particular control that fired the event. This sender parameter holds the control. You can use it with code such as:

Dim eventTextBox as TextBox = sender

13.4 What is different about working with forms in VB.NET? For example, how can I reference one form from another form?

Check out this Microsoft article on working with multiple forms in VB.NET by Duncan Mackenzie.

No comments: