I am currently working on a project using MS VS 2017.
I was able to open the designer and open the forms before. Now, I'm trying to open the same file but all forms' designers cannot be opened. But the project runs smoothly and I can edit the code.
I tried what others have suggested, like cleaning and building the solution, and deleting the obj subfolder, however none of these worked for me. What should I do?
This is what I get every time I try to open the designer:
The designer could not be shown for this file because none of the classes within it can be designed.
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
This is the code of the form I am trying to open:
Public Class frmLogin
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Application.Exit()
End Sub
Private Sub lblExit_Click_1(sender As Object, e As EventArgs) Handles lblExit.Click
If (MessageBox.Show("Are you sure to Exit?", "Exit from the system", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
frmDashboard.Show()
Me.Hide()
End Sub
End Class
The file you need to look at is frmLogin.Designer.vb in your project directory. You can see it by right-clicking (in Visual Studio), for instance "btnLogin" in the code that you posted above, then "Go To Implementation". Or just use File Explorer and open the file with NotePad to see inside.
This is where the design for your form is stored. The file contains auto-generated code and data for your form, and seems to be corrupted somehow, maybe it was accidentally edited.
I have no idea what frmLogin actually looks like, but here is a frmLogin.Designer.vb I just created using the names in your code;
I suggest you compare the contents of your file with the example below which should lead to the source of your problem:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class frmLogin
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()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnLogin = New System.Windows.Forms.Button()
Me.lblExit = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(310, 130)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(107, 43)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'btnLogin
'
Me.btnLogin.Location = New System.Drawing.Point(310, 192)
Me.btnLogin.Name = "btnLogin"
Me.btnLogin.Size = New System.Drawing.Size(107, 48)
Me.btnLogin.TabIndex = 1
Me.btnLogin.Text = "Log in"
Me.btnLogin.UseVisualStyleBackColor = True
'
'lblExit
'
Me.lblExit.AutoSize = True
Me.lblExit.Location = New System.Drawing.Point(233, 130)
Me.lblExit.Name = "lblExit"
Me.lblExit.Size = New System.Drawing.Size(24, 13)
Me.lblExit.TabIndex = 2
Me.lblExit.Text = "Exit"
'
'frmLogin
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.lblExit)
Me.Controls.Add(Me.btnLogin)
Me.Controls.Add(Me.btnCancel)
Me.Name = "frmLogin"
Me.Text = "frmLogin"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents btnCancel As Button
Friend WithEvents btnLogin As Button
Friend WithEvents lblExit As Label
End Class
Good luck!
I had the same issue where the project would build and run but the Windows Forms designer refused to display any forms or controls.
I had to delete the ProjectAssemblies directory and reopen the project and then it worked fine.
%LOCALAPPDATA%\Microsoft\VisualStudio*16.0_72ecbfa4*\ProjectAssemblies
Related
I am writing an application in VB.net (using Visual Studio 2022) which has a lot of text boxes. I am wondering if there is a way to write a routine so any time any of the textboxes have the "enter" action called it will highlight the text contained in the textbox, as opposed to writing the code for each individual textbox "enter" routine?
Assuming that "have the "enter" action called" means when it receives focus, the simplest option would be to create your own custom control that includes that functionality, then use that control instead of regular TextBoxes. Creating custom controls is pretty simple when you want to add to an existing control rather than start from srcatch.
Public Class TextBoxEx
Inherits TextBox
Protected Overrides Sub OnEnter(e As EventArgs)
MyBase.OnEnter(e)
SelectAll()
End Sub
End Class
Once you have that class in your project, it's just a matter replacing existing TextBox refrerences in the designer code with that class. If your project targets .NET Framework, you'll have to Show All Files in the Soluion Explorer to access the designer code file. The designer code for a form with a TextBox will look something like this:
<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()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(100, 20)
Me.TextBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As TextBox
End Class
You just need to replace this:
Friend WithEvents TextBox1 As TextBox
with this:
Friend WithEvents TextBox1 As TextBoxEx
and this:
Me.TextBox1 = New System.Windows.Forms.TextBox()
with this:
Me.TextBox1 = New TextBoxEx()
You can even use the Find & Replace functionality in VS to find all the instances you need to replace. Once that's done, everything else is automatic.
Just be sure to have backed up your code before messing with the designer files, in case you break them. Of course, you should be using source control so you should just be able to undo changes to go back to your last good code.
My main form is frmInvoice. This sub is located inside frmInvoice.
This is one of the Subs that sometimes causes frmDark to not close. frmLookup does not display when this happens. frmDark just stays there covering frmInvoice. It's like it doesn't reach the call to frm.ShowDialog(frmDark), cause when I press the lookup key, it displays the frmLookup, but upon closing frmLookup, frmDark is still there.
No exception is being raised.
Note that this only happens in Windows 10. In Windows 8/7, this never happened. What am I missing?
This happens at different times. Sometimes I could press the lookup key for 20 times and it will display fine. Sometimes, after 1 press of the lookup key and this happens.
Private Sub ItemLookup()
Try
Using frmDark As New Form
With frmDark
.ShowInTaskbar = False
.Icon = Me.Icon
.FormBorderStyle = Windows.Forms.FormBorderStyle.None
.BackColor = Color.Black
.Opacity = 0.95
.WindowState = FormWindowState.Maximized
.Show(Me)
Using frm As New frmLookup
With frm
.Icon = Me.Icon
.ShowDialog(frmDark)
frmDark.Close()
If .DialogResult = Windows.Forms.DialogResult.OK Then
' Do stuff here
End If
End With
End Using
End With
End Using
Catch ex As Exception
ErrMsg(ex)
End Try
End Sub
UPDATE: I'm using .Net Framework 4.8
Thanks
I would suggest rearranging the code like so:
Dim lookupResult As DialogResult
Using frmDark As New Form With {.ShowInTaskbar = False,
.Icon = Me.Icon,
...}
frmDark.Show(Me)
Using frm As New frmLookup With {.Icon = Me.Icon}
lookupResult = frm.ShowDialog(frmDark)
End Using
End Using
If lookupResult = DialogResult.OK Then
'...
End If
Because that code exits the Using block that created frmDark, there should be no way that it can't close.
Also, instead of using a vanilla Form and configuring it on demand, I would suggest that you create a dedicated form type to use as the overlay in that scenario. You can then get rid of all the property assignments.
Having a dedicated overlay form would also allow you to reconfigure things significantly and, in my opinion, better. The overlay form could have a property of type Form. You main form could then create a frmLookup instance and assign it to that property, than call ShowDialog on the overlay form. In the Shown event handler of the overlay form, it could then call ShowDialog on the form in that property. When that call returns, it could assign the result to its own DialogResult property and close itself. The main form would then just get the result from calling ShowDialog on the overlay. That might look like this:
Public Class OverlayForm
Public Property DialogueForm As Form
Private Sub OverlayForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
DialogResult = DialogueForm.ShowDialog()
End Sub
End Class
and this:
Public Class MainForm
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using dialogue As New DialogueForm,
overlay As New OverlayForm With {.DialogueForm = dialogue}
If overlay.ShowDialog() = DialogResult.OK Then
MessageBox.Show("OK")
End If
End Using
End Sub
End Class
i am creating a windows forms app with 3 forms.
I am able to send values and update them timely between form1 and form2.
But i have problems with updating values from form3 to form2.
My code in form2 is as follows:
Public Sub GetValues_Form3()
xlExcelLink = Form3.LoadProjDB()
If xlExcelLink Is Nothing Then
MsgBox("Projekt Datenbank fehlt." & vbNewLine & "Bitte wählen Sie in den Optionen erneut die Projektdatenbank aus.", , "Fehler")
Form1.ib_OptionsTab_Click(Form1.ib_OptionsTab, Nothing) 'Opens Form3
End If
End Sub
My code in Form 3 is as follows:
Private Sub ib_ProjDB_Browse_Click(sender As Object, e As EventArgs) Handles ib_ProjDB_Browse.Click
If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then
tb_Excel.Text = OpenFileDialog1.FileName
End If
End Sub
Function LoadProjDB() As String
Dim Form3_ExcelPath As String = tb_Excel.Text
MsgBox(Form3_ExcelPath)
If Form3_ExcelPath IsNot Nothing And System.IO.File.Exists(Form3_ExcelPath) Then
MsgBox(Form3_ExcelPath)
Form2.Label1.Text = Form3_ExcelPath
Return Form3_ExcelPath
Else
Return Nothing
End If
End Function
I have a default file path. I check if the path exists.
If it doesnt exist, i want my form2 to open form3, where i can select the new file.
After form3 is closed, i get the path string from form3 in form2, and it checks if the string is nothing.
If it is nothing, it will open form3 again.
The problem here is:
I am able to select a new file and it is displaying correctly in form3.
But form2 is not updating its vale from form3.
It still has the first value that it got from form3.
Please help.
Thank you.
Edit1:
Now I am trying to run Subs and Function in Form2 from Form1.
It seems the variables are changing temporarily when executed, but the functions are not being triggered by my action.
I cant seem to find a solution for it till now.
Edit 2:
#Idle_Mind
Im using a public sub which handles button click in form1 to display form3.
Public Sub ib_OptionsTab_Click(sender As Object, e As EventArgs) Handles ib_OptionsTab.Click
If ib_OptionsTab.Tag = 0 Then
Form3_in_Panel()
ElseIf ib_OptionsTab.Tag = 1 Then
Form3_Out_Panel()
End If
End Sub
Form3 is the oped using this function in form1.
Function Form3_in_Panel()
If Form3_Load = True Then
Dim f3 As New Form3
f3.TopLevel = False
f3.Dock = DockStyle.Fill
pnl_Fill.Controls.Add(f3)
f3.Visible = True
f3.BringToFront()
Form3_Load = False
frm3 = pnl_Fill.Controls.Item("Form3")
Else
pnl_Fill.Controls.Item("Form3").Visible = True
End If
ib_OptionsTab.Tag = 1
Return Nothing
End Function
I'll try and keep this brief without leaving out details. I'm working in Visual Stuido 2012 using .NET 4.5
I have a Splash Screen, a "version selection" form as my main startup form, and then from there it branches out in two ways based on the user's choice.
The Version Select can save the user's choice for the future, and checks if they have a saved setting, and if they do it skips the selection form and goes straight to their version. The problem I'm encountering is that when the user has a saved version, the splash screen remains up and never closes unless I force it to.
I tried using the MinimumSplashScreen time in the application events but that hasn't helped. This only happens if the user has a version saved.
Any thoughts on this? I can post more details as needed. Thanks in advance
From Comments
Private Sub Version_Selection_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.VersionSelected = "OSRS" Then
'Code to close initial form and load old school
Dim OSmain As New OldSchoolMain
OSmain.Show()
Me.Close()
ElseIf My.Settings.VersionSelected = "RS3" Then
'Code to close intital form and load RS3
End If
End Sub
Private Sub btnConfirmSelection_Click(sender As Object, e As EventArgs) Handles btnConfirmSelection.Click
If radOSRS.Checked = True Then
If cboxSaveVersion.Checked = True Then
My.Settings.VersionSelected = "OSRS"
End If
Dim OSmain As New OldSchoolMain
OSmain.Show()
Me.Close()
ElseIf radRS3.Checked = True Then
If cboxSaveVersion.Checked = True Then
My.Settings.VersionSelected = "RS3"
End If
Dim RS3main As New RS3Main
RS3main.Show()
Me.Close()
End If
End Sub
Looking at your code, I think the problem with your Splash Screen is that you are closing the startup form before it finishes. I would try using the Form Shown event since that doesn't get fired until the SplashScreen has finished, I also am Minimizing the form to try to keep it from flashing briefly on the screen. See if something like this works for you.
Private Sub Splash_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
If My.Settings.StartupForm = "Form1" Then
Dim frm As New Form1
frm.Show()
Me.WindowState = FormWindowState.Minimized
Me.ShowInTaskbar = False
Me.Close()
ElseIf My.Settings.StartupForm = "Form2" Then
Dim frm As New Form2
frm.Show()
Me.WindowState = FormWindowState.Minimized
Me.ShowInTaskbar = False
Me.Close()
End If
End Sub
I am using Windows Vista x64 + VSTS 2008. I am debugging the sample program from the following URL (associated sample code for this article),
http://www.codeproject.com/KB/audio-video/CaptureScreenAsVideo.aspx?display=PrintAll&fid=129831&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101&select=1160633
But I met with null pointer exception when press the write to file button, here is my screen snapshot.
http://tinypic.com/view.php?pic=14cbfop&s=5
Any ideas what is wrong?
EDIT1: here is the whole source code.
Imports WMEncoderLib
Imports WMPREVIEWLib
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
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.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(48, 80)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(216, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Write To file and Close application"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Dim Encoder As WMEncoder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a WMEncoder object.
Encoder = New WMEncoder
' Retrieve the source group collection and add a source group.
Dim SrcGrp As IWMEncSourceGroup2
Dim SrcGrpColl As IWMEncSourceGroupCollection
SrcGrpColl = Encoder.SourceGroupCollection
SrcGrp = SrcGrpColl.Add("SG_1")
' Add a video and audio source to the source group.
Dim SrcVid As IWMEncVideoSource2
Dim SrcAud As IWMEncAudioSource
SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO)
SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
' Identify the source files to encode.
SrcVid.SetInput("ScreenCap://ScreenCapture1")
SrcAud.SetInput("Device://Default_Audio_Device")
' Choose a profile from the collection.
Dim ProColl As IWMEncProfileCollection
Dim Pro As IWMEncProfile
Dim i As Integer
Dim lLength As Long
ProColl = Encoder.ProfileCollection
lLength = ProColl.Count
'For i = 0 To lLength - 1
' Console.WriteLine(ProColl.Item(i).Name)
'Next
For i = 0 To lLength - 1
Pro = ProColl.Item(i)
If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
SrcGrp.Profile = Pro
Exit For
End If
Next
' Fill in the description object members.
Dim Descr As IWMEncDisplayInfo
Descr = Encoder.DisplayInfo
Descr.Author = "Armoghan Asif"
Descr.Copyright = "Copyright information"
Descr.Description = "Text description of encoded content"
Descr.Rating = "Rating information"
Descr.Title = "Title of encoded content"
' Add an attribute to the collection.
Dim Attr As IWMEncAttributes
Attr = Encoder.Attributes
Attr.Add("URL", "www.adnare.com")
' Specify a file object in which to save encoded content.
Dim File As IWMEncFile
File = Encoder.File
File.LocalFileName = "C:\OutputFile.avi"
' Crop 2 pixels from each edge of the video image.
SrcVid.CroppingBottomMargin = 2
SrcVid.CroppingTopMargin = 2
SrcVid.CroppingLeftMargin = 2
SrcVid.CroppingRightMargin = 2
' Start the encoding process.
Encoder.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Encoder.RunState Then
Encoder.Stop()
Application.Exit()
End If
End Sub
End Class
Did you install Windows Media Encoder 9 Series and SDK as instructed by the article? My guess is that this is the culprit.
You probably don't have the encoder. Check the prerequisites (See this line: "You will be needing Windows Media Encoder 9 Series and SDK.").
Is this code still intact?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a WMEncoder object.
Encoder = New WMEncoder
The implication is that that code is missing or quietly failing.
If you put a breakpoint on the line following Encoder = New WMEncoder, what's the value of Encoder?