This might be a case of never noticed OR I have broke something
I have three projects two with multiple forms and one with only one form
Visual Studio 2019 v 16.6.2 with Frame Work 4.7.2 On Windows 7 64 bit
All the projects are WinForms with VB
I have been making a number of changes like Under Compile un-check 32 bit it is back on now
Under Application I changed framework to 4.6.1 It is back to 4.72 now
My Subs do not look to have the correct format to me please I am only 3 weeks into this IDE
I do not see the ByVal and ByRef tabs in any of my Subs in any of the Projects
Private Sub frmOne_Load(sender As Object, e As EventArgs) Handles MyBase.Load<br/>
I have Shutdown Mode set to When Last Form Closes for startup form YES I tested both ways
When I say Shows Project Closed here is what I see (See Screen Shot)
All the projects run as expected
I tested these lines of code on all three project it does not work and I do not understand it so it is deleted
Public Sub SetIcon()
InitializeComponent()
Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location)
End Sub
The question is this normal behavior and I have been asleep for 3 weeks?
If this is not normal behavior where do I look or how do I fix this?
That red square is simply the tool button to stop a debugging session. The Debug toolbar is only displayed while you're debugging, so maybe you just haven't looked at the toolbar at that time before. Have a look at the Debug menu in VS while you're debugging your project and while you're not to see the difference. Only options that apply to the current state are displayed.
As I mentioned in a comment, ByVal is the default and is now generally implicit. You can make it explicit if you want but if you have Pretty Listing (auto-formatting) enabled, it will be removed automatically.
InitializeComponent is basically the auto-generated method that creates and configures the controls and components you add in the designer. It must and should only be called in a constructor for that reason.
Related
I wrote a Visual Basic program back in VB4 (yes, really!) to track my petrol/gas consumption, and subsequently compiled it in VB6, Visual Studio Express 2010 (I think), VS Express 2015 for desktop, and I'm now trying to compile it in VS 2019 Community, without success.
I made a back-up copy of the source code folders, and pointed VB at the original .sln file. The source all seemed to load up ok, but when I try to run the program in debug mode, the splash screen comes up, but never goes away, and the main form "frmMain" never gets loaded. I set a breakpoint at the first line of code in frmMain:
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
but I get an error "The breakpoint will never be hit. No symbols have been loaded for the current document".
This doesn't mean anything to me, and this message has appeared in the forums for years, seeking explanation, without an agreed common solution. I'm definitely in 'Debug' mode, not 'Release'. I've checked in Properties/Application that frmMain is the Startup form, and the Splash screen is set to frmSplash. Is the 'current document' frmMain? What are 'Symbols'?
Incidentally, I have a lot of 'Messages' which say, eg 'Message IDE1006 Naming rule violation: These words must begin with upper case characters: btnSaveNewCar_Click'. Why is this? It's never arisen before - has something changed in VB?
I have an app built in VB in Visual Studio 2012 that works absolutely fine on my windows 10 desktop, but as soon as i use it on my windows 10 tablet i see a couple of issues :
1) any forms that were intended to be smaller than full screen are shown fullscreen anyway (almost as if you're not allowed any windows less than full screen) i can live with that if need be, but surely theres a way around it?
2) - the most important one - for some strange reason, i start my app, and when i click on a button let's say it opens form 6. once i finish what i'm doing the code closes the form 6, but the previous form is now hidden and all you see is the desktop. ie it's still running, it just lost its focus and must be selected again. I understand i could set the focus to the underlying form before closing form 6, but here's the problem : it can be one of several different forms calling form 6..... so how do i make the app stay aware of what form called form6 so that when done i can return focus there?
this doesnt seem to be a problem on the desktop so i've never encountered it before. i hope one of you experts has dealt with this before
I don't have enough points yet to comment. My guess for #1 is either resolution or DPI differences between the 2 screens, and I don't have experience with the latter.
As for #2 and keeping the form aware of who called it, this is how I do it, which may not be the best solution, of course. ;)
First any form that can have multiple callers has a variable defined like
Dim callingForm As New Form
I typically create an Initialize routine to handle as much as possible before loading a form and this routine is called with the parent form (Me) as a parameter.
Dim frm As New frmClient
frm.Initialize(Me)
frm.Show()
Me.Hide()
In Initialize, callingForm is set to the parent
Public Sub Initialize(parent As Form)
callingForm = parent
'whatever else you need to do to init...
End Sub
Then when you exit the form...
Private Sub exitForm()
'whatever other closing stuff you need to do...
callingForm.Show()
Me.Close()
End Sub
That should get you started.
fyi for anyone encountering this problem, i solved it myself and it didn't require any coding. It was a difference between how vb apps act when the tablet is in "TABLET" mode, and when tablet mode is switched off. So all that needed doing is switching off enhanced tablet mode in the windows 10 settings
I have a vb.net Windows Forms application using Visual Studio 2010. At design time my buttons look like this:
at run time they seem to revert to a Windows classic style:
It only happens for this project which I took over from a developer who left. I want them to look like they do at design time. I'm stumped. Any ideas?
If the app starts from a Sub Main rather than a main form (See Project -> Properties -> StartUp Object) it might be missing this:
Public Sub Main()
' probably missing:
Application.EnableVisualStyles()
Application.Run(New Form1)
End Sub
When starting from a Main sub, be sure that EnableVisualStyles() is invoked very early in the procedure before any UI Objects are created.
If it starts from a main form, go to the same Project properties and be sure that both Enable application framework and Enable XP Visual Styles are checked.
If it still doesnt work, turn on Show All Files in Solution Explorer and open Application.myApp under My Project. Make sure this setting is true:
<EnableVisualStyles>true</EnableVisualStyles>
This file/setting should be managed by VS, so if it is not being updated to match the IDE, you might have other issues.
This is an IDE question for Visual Basic 2008 Express Edition. It might be a bug in the IDE, or maybe it's my fault somehow?
My main form is named frmMain and in my application's properties I have set frmMain as my startup object. All of that seems like what a lot of software engineers do.
But while debugging I hit Ctrl + Break, as I have done for years, and I get an behavior in the IDE that I wasn't expecting. Upon doing so, I get the green background text and the green arrow indicating in a tooltip:
This is the next statement to execute when this thread returns from the current function.
Even if I didn't have the designer document open, it automatically opens frmMain.Designer.vb in the editor and hihglights line in green. The line is of course: Partial Class frmMain which is line 2 of the file. (Yes, it's highlighting the second line of the designer-generated code.)
frmMain seems to have fully loaded and it's my startup object. As far as I know, there shouldn't be a "next statement to execute" at all because code should be idle. I don't want to see the Designer.vb document... I want to edit my own code.
What's causing this? Even though my form is behaving just fine, could there somehow be an unfinished aspect of loading the form such that it is "not returning" from a function?
The Visual Basic compiler will add an entry point in your form. The entry point is the standard main function or "shared sub main", which in turn contains the code "application.run(new form)". Since this is compiler generated code there is no source location, so the Visual Basic editor highlights the class definition.
The clue to this is in the call stack. Notice the Main().
Shared Sub Main()
Application.Run(new frmMain)
End Sub
I found the answer on my own:
I checked the "Enable application framework" checkbox in the solution's properties, and all is well!
I believe this issue arose when I was working on experimental code in which I had desired to make Sub Main my startup object. I had cleared the checkbox because doing so is necessary to use Sub Main.
When the experiment didn't pan out I reset the startup object back to frmMain, and my app worked fine. However I had not re-checked the box. I hadn't noticed the change in the IDE behavior for several days (when I needed the more standard behavior) so I had not observed any correlation.
Although checking that box is definitely the solution, it's still not exactly clear to me is what the heck this box actually does, other than cause me to spend a lot of time on StackOverflow.com! ;-)
To others who encounter a similar situation, I'm now quite confident that my settings were not corrupt, and if you're using the Express edition, please don't be mislead by MS documentation which may lead you to believe it's the "Just My Code" option. This option cannot be changed in the Express versions. (But it's not because you can't turn it on -- It's because you can't turn it OFF in Express!)
Thanks to everyone for your efforts.
I'm going to guess that it is trying to show you the equivalent of:
Application.Run(new frmMain)
This is the code that gets generated to startup your form. But in VB.NET this code gets burried. Create a Main() function and change your startup type to that with this line in it and repeat the process. You'll see it highlight Application.Run. That is the method that contains your Windows message pump loop.
I have a problem in my project with the .designer which as everyone know is autogenerated and I ahvent changed at all. One day I was working fine, I did a back up and next day boom! the project suddenly stops working and sends a message that the designer cant procees a code line... and due to this I get more errores (2 in my case), I even had a back up from the day it was working and is useless too, I get the same error, I tryed in my laptop and the same problem comes. How can I delete the "FitTrack"? The incredible part is that while I was trying on the laptop the errors on the desktop were gone in front of my eyes, one and one second later the other one (but still have the warning from the designer and cant see the form), I closed and open it again and again I have the errors...
The error is:
Warning 1 The designer cannot process the code at line 27:
Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. C:\Documents and Settings\Alan Cardero\Desktop\Reportes Liquidacion\Reportes Liquidacion\Reportes Liquidacion\Form1.Designer.vb 28 0
I would back up the designer.cs file associated with it (like copy it to the desktop), then edit the designer.cs file and remove the offending lines (keeping track of what they do) and then I'd try to redo those lines via the design mode of that form.
I would take out the static assignment in the designer to the resource CrystalReport11 and then add a load handler to your form and before setting the ReportSource back to CrystalReport11 do a check
If(Not DesignMode) Then Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
Here is a mockup..
Public Sub New()
InitializeComponent()
AddHandler Me.Load, New EventHandler(AddressOf Form1_Load)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (Not DesignMode) Then Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
End Sub
You should be able to take a backup, clear the lines that are having problems then when you re-open it the designer will fix the code.
The key is that you want to let the designer re-generate, then just validate that all needed lines are there.
That usually works for me, but you just have to be sure to remove all lines that it doesn't like.
I do an easy way; Right Click on the report then choose Run Custom Tool.
Automatically it fixes all problems and working for me, i solve 52 crystal ReportViewer errors.