Reputation:
I am working on a vb.net application with winforms and need to create lots of forms (about 50) for the user interface.
The layout of the forms schould be the same in terms of size (1920x1080), background colours, fonts, size of the controls etc.
Is there a way of creating winforms very efficient without creating every form with the designer?
I would like to define somekind of a template which the other forms are based on.
Should i create the forms with code without using the designer or is there a better way? Any ideas or best practices are welcome.
Upvotes: 1
Views: 184
Reputation: 9759
You can create the form with all the specification like size, background colours, fonts etc as your base form. This will act as your template.
Now when you add a new form it inherits from Form
class by default. Instead of Form
simply inherit your form from the BaseForm
.
To have uniformity with the controls, you can create User Controls and use them instead to windows form controls.
Upvotes: 5
Reputation: 5403
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 1 To 50
Dim f As New Form
f.Text = "Form " & i.ToString
f.Width = 1920
f.Height = 1080
Dim b As New Button
AddHandler b.Click, AddressOf CloseButton
b.Text = "Close " & i.ToString
b.Top = 100
b.Left = 100
b.Visible = True
f.Controls.Add(b)
f.Visible = True
Next i
End Sub
Private Sub CloseButton(sender As Object, e As EventArgs)
Dim b As Button = DirectCast(sender, Button)
b.FindForm.Close()
End Sub
End Class
Upvotes: 0