Buttons change style at run time - vb.net

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.

Related

vb.net startup form shows project closed

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.

VB.Net Application starts as background process in Windows 10

We have an internally developed VB.Net Windows Forms Application that handles all our Auto-Updating for our other software applications. Whenever I run the application in Windows 10, the application starts under the "Background Processes" section of the Task Manager. The only way I can get it to run in the foreground is to run it as an Administrator even though I'm an Admin on the VM and my UAC settings are turned all the way down. This doesn't happen in Windows 7 or 8 so I'm wondering if there's something I'm doing wrong or something about Windows 10 that's changed where it has to be run as an Admin. Our other applications don't seem to have this issue, it's just specifically this one application for some reason but I can't seem to figure out what's different.
So I put some more error handling in and it sounds like #xfx was onto the right idea. The application is erring when it starts up because it can't register the URL of the WCF service so it never got to the point where it was displaying the form. Once I manually registered the URL of the WCF service and ran the application as an Admin, it displayed and worked like normal.
This is because of the way the project has been configured in Visual Studio.
Here's how to create an application that behaves like a background process:
In the Project settings dialog, disable the Enable application framework option
Next, change the Startup object to Sub Main
Finally, add a Module to the project and add the following code:
Module Module1
Sub Main()
Application.Run()
End Sub
End Module
If you run the application (not from within the IDE, but directly) it will behave just like the one you describe.
The application will remain as a background process as long as it doesn't display a Form. As soon as one is displayed, you will see that Task Manager moves the process from the Background processes list to the Apps list.
To test this, just change the code in the Module for this version:
Imports System.Threading
Module Module1
Sub Main()
Dim tmp As New Thread(Sub()
Thread.Sleep(3000)
Using f As New Form1()
f.ShowDialog()
End Using
End Sub)
tmp.Start()
Application.Run()
End Sub
End Module
The application will start as a background process and 3 seconds later will display form, becoming a foreground process.

VS2010 VB.NET Winforms select startup form programmatically

I'm really struggling to find out how to dynamically load a form when starting a VB.NET winforms application in VS2010.
Looking at existing answers such as this: Programmatically change the startup form on application launch?
Has not helped. I do not have a main method (that I can see) in my winforms project and when I go into the project properties I can only select a start-up form. But I have one of two forms to display on start-up depending on the user accessing the application.
I tried to set a loading form up which, in it's load event would call .Show() on the correct loading form after it had determined it and then the loading form would close itself down, but doing this led to both forms being closed.
Below are steps for VS2010 VB.NET Winforms select startup form programmatically.
1 : Go to My project from Solution Explorer
2 : Click on Application Tab--->Uncheck Enable application Framework
3 : Then Inside module create Sub like this
Public Sub Main()
MsgBox("called Main") 'This is testing
Login.Show() 'Set your start up form here
End Sub
4 : Again My Project--->Application Tab--->Startup Object--->Sub Main
5 : Thats it, It will give you message box and will show Login form.
Hope It will help you.
Thanks
Mahesh
Nevermind. I found in the properties a button to generate the MyApplication class in which I can access the startup event.
Another option is to use an MDI form. When it loads you can determine which child form to display.
Using Sub Main is the way I have done this forever but for some reason, MS has decided to make the norm, difficult. To use the Sub Main way, create a "Module" if you dont already have one. Put this code in there:
Sub Main()
Stop
End Sub
Now, in your project properties, assuming your are doing a standard WinForms application, on the "Application" tab, uncheck the "Enable Application Framework". This will allow you to see (and select) "Sub Main" in the "Startup Object" drop-down.

VB.NET - Ctrl + Break suspends code on "Partial Class frmMain"

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.

VB.net program with no UI

I'm making a VB.net program via a text file and I'm compiling it using vbc.exe via command line. I'm trying to get just a simple program to run in the background of my computer. Problem is, it displays the annoying console window. How do I get nothing to show? No form, no console?
Just use windows forms application don't load the form at all! Just go in project properties and uncheck enable application framework. Now, in the startup object dropdown, select "sub main". Add a module to the project and put a Public Sub Main() in it. You do all the stuff in main() and don't load form at all.
I think you need a form of some kind to keep the message loop going.
Maybe a NotifyIcon type program. It would keep it away from the task bar and desktop areas.
And then customize the NotifyIcon to "Only Show Notifications" from the "Customize" menu for your icon using Windows.
1) Add a module in your project, and create Sub Main
2) Write whatever you want in Sub Main,and MAKE SURE you end it with this statement:
Application.Run()
3) Open properties of your project and choose "Sub Main" as startup object
So , your application will have NO INTERFACE (NO FORM / NOT CONSOLE APPLICATION) and will run from Sub Main(), in addition it will NOT TERMINATE once all the code in Sub Main has executed.Your program will run like a NORMAL windows form application, and will only exit when you want.