-
Jan 10th, 2018, 11:21 PM
#1
Thread Starter
New Member
How to change VB 2015 from public partial class form to public class form
I am new to VB. For my computer science class we must create a simple form. However, when I try to edit the form it is in the public partial class format. It says
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
However, I want to change it to a public class form as my instructions are using the public class format. Thanks
-
Jan 11th, 2018, 12:40 AM
#2
Re: How to change VB 2015 from public partial class form to public class form
You are trying to solve a problem that doesn't exist. That 'partial' keyword simply means that code for the class can be split over multiple code files. Given that VS automatically uses two code files (one for designer-generated code and one for your own code) you require that 'partial' keyword or your form will simply stop working. Just go ahead and put your code within that class definition and everything will work as it should.
-
Jan 11th, 2018, 12:42 AM
#3
Re: How to change VB 2015 from public partial class form to public class form
Hang on a minute! That's C# code that you've posted. What language are you supposed to be using? It would help if you knew that to begin with.
Note that VB still uses partial classes but VB only requires that one part be declared with the 'Partial' keyword where C# requires all parts to use the 'partial' keyword.
-
Jan 11th, 2018, 10:37 AM
#4
Re: How to change VB 2015 from public partial class form to public class form
Yeah, I was tempted to move the thread, but now that I think about it, the problem may really be that this is a C# project created when a VB project was desired. If that's the case, then the thread is in the right forum.
My usual boring signature: Nothing
-
Jan 11th, 2018, 12:22 PM
#5
Re: How to change VB 2015 from public partial class form to public class form
If you're in a VB class, you're making C# projects so nothing you see in your textbook or class lectures is going to work. C# is a different language.
Technically VB could have the partial keyword there, but the historic design philosophy of VB is to "reduce clutter" by doing as much as possible implicitly. So since the keyword is optional in most class definitions, VB doesn't use it. C# has a philosophy of "be explicit in everything you do" so even though the partial keyword is optional it uses it so you know it's there.
This creates a sort of clash: many .NET features are designed with explicit philosophies in mind, but VB's cultural propensity towards implicit philosophies means you often find out you're using a feature a few hours after "not knowing the feature is there" creates the problem.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Jan 11th, 2018, 07:57 PM
#6
Re: How to change VB 2015 from public partial class form to public class form
The rules for the use of the 'partial' (C#) and 'Partial' (VB) keywords are as follows:
C#: It is an error to have multiple class declarations with the same name unless all declarations include the 'partial' keyword.
VB: It is an error to have multiple class declarations with the same name unless at least one of them includes the 'Partial' keyword. It is a warning to have more than two class declarations with the same name if more than one of them does not include the 'Partial' keyword.
Since 2005, which was when partial classes were introduced, VS has generated two code files for a Windows Form with one being for code generated by the designer and one being for user code. In the case of C#, the 'partial' keyword is required on all partial definitions so the definition in the user code file includes the 'partial' keyword, as you are seeing in the code you posted in post #1. In the case of VB, one class definition can omit the 'Partial' keyword without error or warning so you'll find that the definition in the user code file doesn't include the 'Partial' keyword while the one in the designer code file does include it. You could include it in both if you wanted to, but the IDE does not do so by default.
Note that C# projects display the designer code file in the Solution Explorer by default, while VB projects do not. That's because designer code files should generally not be edited manually so VB tries to protect you from yourself. If you do want to see it or in the rare case where you need to edit it manually, you can see the designer code file in a VB project by clicking the 'Show All Files' button at the top of the Solution Explorer and expanding the node for your form. In VB 2017, the default designer code file looks like this:
vb.net Code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() components = New System.ComponentModel.Container() Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.Text = "Form1" End Sub End Class
As you can see, the class is declared Partial.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|