Cannot view Designer - vb.net

Please help! I can not view the Control Parameter Adjustment Form in my VB project, other three forms are normal.
How can I fix this problem?
Here is the Designer.vb code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Control_Parameter_Adjustment
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.Label1 = New System.Windows.Forms.Label()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Label31 = New System.Windows.Forms.Label()
......
End Class

At first, I apologize for my bad english.
This worked for me: If you add an empty form to your project, you can double clik on it, and you can see the following:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
You can't see that class definition in the other form, probably because this class have dissapeared (I can't explain you why).
Also and probably, you can find the form_Load event in the form code.
Simply rewrite this class, changing the Form Name in class definition. Then, you can see the designer. The icon also change.

Related

ListViewGroup shows items but not headers

I have read through several forums and tried different options. Most of the answers were this, which makes me assume that would be the issue. I placed Application.EnableVisualStyles()
at the beginning of InitializeComponent() in the .Designer.vb file as seen below:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class MetadataCollectionGUI
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()
Application.EnableVisualStyles() ' <--- See Here
Me.ListViewMetaDataCollection = New System.Windows.Forms.ListView()
Me.ColumnTags = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
etc... etc...
End Sub
Etc...
End Class
Did I misunderstand how to execute that particular solution or is the issue something different?
I found out what the issue was. Go to the project properties and enable the application framework. Now you can enabled the XP visual styles.
Thank you Hursey & jmcilhinney, I would not have figured it out without you all!

Can I maintain vb.net windows form designer code in .vb?

Can I maintain vb.net windows form designer code in .vb?
i.e I wanted to ask whether I can maintain only one .vb file for both form design and logic part, instead of having one designer.vb for form design part and .vb file for logic part?
Here is a functional sample:
_
Partial Class Form1
Inherits System.Windows.Forms.Form
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
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
Public Sub Intiialize()
'Form overrides dispose to clean up the component list.
InitializeComponent()
'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.
End Sub
<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

VB.NET Absolutely strange form load behaviour

I am experiencing a strange behaviour when using RightToLayout layout:
My form automatically closes.
I have created a simple project to reproduce the problem:
Create a new VB.NET project in VS2012 and add forms "Form1" and "Form2" to it.
Set "Form1" to be the start form.
Then add the following code to "Form1":
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Hide()
Dim f As New Form2
f.ShowDialog()
MessageBox.Show("After dialog closed.")
modControls.setFormRTL(Me) 'This line causes the Form2 to automatically close. Why??? This line should only be processed AFTER the dialog has been shown and closed
End Sub
End Class
Add the following code to "Form2":
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
modControls.setFormRTL(Me)
End Sub
End Class
Add a module with the name "modControls" to the project.
Add the following code to it:
Module modControls
Public Sub setFormRTL(ByVal uForm As Form)
uForm.RightToLeft = RightToLeft.Yes
End Sub
End Module
Without the setFormRTL, my project works perfectly fine, but with it, "Form2" automatically closes down. You can see this because the messagebox is shown.
When I remove the line
modControls.setFormRTL(Me)
from Form1 load, it works fine again.
Yes, I really mean from "Form1", not from "Form2"!!!
Now this is really strange because it should not matter at all because this line is not processed before the dialog is closed.
I hope somebody understands what I mean.
Can anybody shed some light on what might be happening here?
Yes, you'll get unexpected behavior if you set the RightToLeft property anywhere other than a control's constructor (in VB.NET parlance, that's the New method).
In fact, the constructor is where you should set all of the properties of a form or control object. If you come from VB 6, it might seem logical to do it in the Load event handler, but that's not idiomatic .NET and, as you've discovered, can cause problems when initializing certain properties.
The technical reason for this is that certain properties (like RightToLeft) can actually only be set on the native window (which is how the Form objects used in the .NET world are implemented behind the scenes) at the time that it is created. When you attempt to change the property, the framework code actually has to destroy and then re-create the native window with the new property values.
Change the code to look like this instead:
Public Class Form1
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
modControls.SetFormRtl(Me)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Hide()
Dim f As New Form2
f.ShowDialog()
MessageBox.Show("After dialog closed.")
End Sub
End Class
Public Class Form2
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
modControls.SetFormRtl(Me)
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
End Class
Speaking of non-idiomatic .NET code:
Methods should all be Pascal cased by convention. That means your setFormRTL method should be named SetFormRtl.
A helper function that sets the properties of an object just seems wrong to me. If anything, that's just bad OO design. If you want this method to be available for all of your Form objects, derive a custom form class and add this method (or even do the desired initialization in the constructor). Either way, all forms that you derive from this custom form object will inherit the functionality. Example:
Public Class MyCustomForm : Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
Me.SetRtl()
End Sub
Public Sub SetRtl()
Me.RightToLeft = RightToLeft.Yes
End Sub
End Class
Public Class Form1 : Inherits MyCustomForm
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Hide()
Dim f As New Form2
f.ShowDialog()
MessageBox.Show("After dialog closed.")
End Sub
End Class
Public Class Form2 : Inherits MyCustomForm
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
End Class
can you try this? all i am doing here is setting the RTL before the form is displayed.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Hide()
Dim f As New Form2
modControls.setFormRTL(f)
f.ShowDialog()
MessageBox.Show("After dialog closed.")
modControls.setFormRTL(Me)
End Sub
End Class
and remove code form load event of form 2

Changing the color of a selected item in a listbox/listview

I'm reasonably new to programming and soon I will be creating a program and would like to change the colour of a selected row via a button click.
I have been attempting this but I don't even know where to begin. If someone could point me in the correct direction it would be much appreciated.
Thanks ^.^
You could simply create a new control, then change the designer to inherit from the listbox control.
the designer code would then look something like this (vs2010):
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class UserControl1
Inherits ListBox
'UserControl 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()
End Sub
End Class
To see the designer code, select "Show All Files" (button at the top of your solution explorer). Then expand the new control node in your solution explorer.
then change the line:
Inherits System.Windows.Forms.UserControl
to:
Inherits ListBox
and finally delete delete the line:
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Hope that helps.

VB.net - Derived class from MenuStrip

What I am trying to do is make a custom MenuStrip control with several items (Main Menu, Log Out, Exit, etc...) already attached. There would be methods to handle items being clicked. I think this would save me a some redundant code in the long run and I might learn a little something too.
The end product would basically be a custom MenuStrip control that I can throw on my forms and already have the functionality for the items within it.
So my question is, can this be done? I am a novice but if it can be done and is actually a good idea, then I want give it a shot.
Errors abound but this is what I was thinking...
Public Class MenuStripCustom
Inherits MenuStrip
Add MenuItem(MainMenuToolStripMenuItem)
MainMenuToolStripMenuItem.Text = Main Menu
Protected Sub MainMenuNav(e As System.EventArgs) _
Handles MyBase.MainMenuToolStripMenuItem.Click
MainMenu.Visible = True
Me.Close()
End Sub
End Class
Thanks!
Yes, can be done no problems. Just create a new user control, and make it inherit from MenuStrip. Then put in code similar to the below for a user control called "UserControl1".
Public Class UserControl1
Inherits MenuStrip
Private WithEvents NavToolStrip As New ToolStripMenuItem("Nav")
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim tsi As New ToolStripMenuItem
Me.Items.Add(NavToolStrip)
End Sub
Private Sub NavToolStrip_Click(sender As Object, e As EventArgs) Handles NavToolStrip.Click
MsgBox("Nav clicked")
End Sub
End Class
Compile the code then you will be able to drag "UserControl1" from your toolbox onto your form.