Click here to Skip to main content
15,890,123 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionGlobal Hotkey Pin
Member 878710722-Apr-13 11:01
Member 878710722-Apr-13 11:01 
AnswerRe: Global Hotkey Pin
Dave Kreskowiak22-Apr-13 14:08
mveDave Kreskowiak22-Apr-13 14:08 
GeneralRe: Global Hotkey Pin
Member 878710723-Apr-13 6:33
Member 878710723-Apr-13 6:33 
GeneralRe: Global Hotkey Pin
Dave Kreskowiak23-Apr-13 7:39
mveDave Kreskowiak23-Apr-13 7:39 
QuestionHow to force a new instance when a form is created? Pin
GuyThiebaut22-Apr-13 4:26
professionalGuyThiebaut22-Apr-13 4:26 
AnswerRe: How to force a new instance when a form is created? Pin
Eddy Vluggen22-Apr-13 5:00
professionalEddy Vluggen22-Apr-13 5:00 
GeneralRe: How to force a new instance when a form is created? Pin
GuyThiebaut22-Apr-13 5:09
professionalGuyThiebaut22-Apr-13 5:09 
GeneralRe: How to force a new instance when a form is created? Pin
Eddy Vluggen22-Apr-13 7:58
professionalEddy Vluggen22-Apr-13 7:58 
Just created a vb-project, thrown in a second blanc Form and called it from a button's click using the ugly "Form2.Show"-approach. Using ILSpy, it's visible what's being generated;
C#
internal sealed class MyForms
{
	public Form1 m_Form1;
	public Form2 m_Form2;
        // ..more..
	public Form2 Form2
	{
		[DebuggerNonUserCode]
		get
		{
			this.m_Form2 = MyProject.MyForms.Create__Instance__<Form2>(this.m_Form2);
			return this.m_Form2;
		}
		[DebuggerNonUserCode]
		set
		{
			bool flag = value == this.m_Form2;
			if (!flag)
			{
				flag = (value != null);
				if (flag)
				{
					throw new ArgumentException("Property can only be set to Nothing");
				}
				this.Dispose__Instance__<Form2>(ref this.m_Form2);
			}
		}
	}
It's sealed, and generated by the compiler. It's only "illegal" if you change the project type from "Windows Forms Application" to "Console Application". Alternatively, one could consider the factory-pattern for forms;
VB
Public Class Form2

    <Obsolete("Use the CreateNew method")>
    Sub New()

        Throw New ApplicationException("")

    End Sub

    Private Sub New(ByVal skip As Boolean)
        ' This call is required by the designer.
        InitializeComponent()
    End Sub

    Public Shared Function CreateNew() As Form2
        Return New Form2(True) ' use generics for a real factory :)
    End Function

End Class
The generated code will try to use the parameterless version of the constructor, and throw an ApplicationException. Not a very good alternative.

I think this would be better solved by writing an FxCop-rule.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: How to force a new instance when a form is created? Pin
GuyThiebaut22-Apr-13 8:11
professionalGuyThiebaut22-Apr-13 8:11 
GeneralRe: How to force a new instance when a form is created? Pin
Eddy Vluggen22-Apr-13 8:21
professionalEddy Vluggen22-Apr-13 8:21 
AnswerRe: How to force a new instance when a form is created? Pin
TnTinMn23-Apr-13 18:12
TnTinMn23-Apr-13 18:12 
QuestionSetup issue Pin
SPSandy20-Apr-13 2:48
SPSandy20-Apr-13 2:48 
QuestionString issue Pin
SPSandy20-Apr-13 2:42
SPSandy20-Apr-13 2:42 
AnswerRe: String issue Pin
Richard MacCutchan20-Apr-13 4:41
mveRichard MacCutchan20-Apr-13 4:41 
GeneralRe: String issue Pin
SPSandy20-Apr-13 8:24
SPSandy20-Apr-13 8:24 
GeneralRe: String issue Pin
Richard MacCutchan20-Apr-13 9:27
mveRichard MacCutchan20-Apr-13 9:27 
GeneralRe: String issue Pin
SPSandy20-Apr-13 16:21
SPSandy20-Apr-13 16:21 
AnswerRe: String issue Pin
Alan N20-Apr-13 14:16
Alan N20-Apr-13 14:16 
GeneralRe: String issue Pin
SPSandy20-Apr-13 19:58
SPSandy20-Apr-13 19:58 
QuestionStored Procedures Pin
alecxa0518-Apr-13 17:58
alecxa0518-Apr-13 17:58 
AnswerRe: Stored Procedures Pin
Richard MacCutchan18-Apr-13 23:07
mveRichard MacCutchan18-Apr-13 23:07 
AnswerRe: Stored Procedures Pin
RedDk21-Apr-13 12:52
RedDk21-Apr-13 12:52 
QuestionHow to do this Relationship in Entity Framework using DataAnnotation not Fluent API Pin
ADSCNET18-Apr-13 16:01
ADSCNET18-Apr-13 16:01 
AnswerRe: How to do this Relationship in Entity Framework using DataAnnotation not Fluent API Pin
Richard MacCutchan18-Apr-13 23:03
mveRichard MacCutchan18-Apr-13 23:03 
GeneralRe: How to do this Relationship in Entity Framework using DataAnnotation not Fluent API Pin
ADSCNET19-Apr-13 0:26
ADSCNET19-Apr-13 0:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.