How do I open a form in WinForm - winforms

I am new to WinForm.
I have Visual Studio Express 2015
I have a project with 5 forms.
Form1, Form2, Form3, Form4, Form5.
Form1 opens by default when I start application.
I am working on Form5.
Question:
How do I open ONLY Form5 for testing?
I don't want to put a link from Form1 to Form5.
I am not talking about writing some code to open a form.

For C#, double click on program.cs in the Solution Explorer and change:
Application.Run(new Form1());
To:
Application.Run(new Form5());
For Visual Basic, click on Project --> Properties and change the Startup form dropdown to the Form you want.

In the Program.cs file, Replace
Application.Run(new Form1);
With
Application.Run(new Form5);
Do the steps in reverse to get it back to normal.
Note: This is in C#

Related

Write logs to reach text box with serilog extensions

I saw this extension to Serilog that proides writing logs to text box on WinForms..
https://github.com/umairsyed613/Serilog.Sinks.WinForms
What I did not understand, is how I decide on the textbox that I want to write to.
Or there is another step to do that I didn't noticed?
I had the same issue. Here are the steps to use it:
download the library "Install-Package Serilog.Sinks.WinForms" or use NuGet. I used VS2019 package manager console to install mine.
This part i missed and it took me a while to get. You need to add "SeriLog Control" from the toolbox menu. So search toolbox menu and add the gidLog1 control.
Configure your logger (i did mine in the Form load event.)
Log.Logger = new LoggerConfiguration()
.WriteToGridView()
.CreateLogger();
Perform/trigger a log action, you can add to you form load event too eg. below.
Log.Information("Application Started");

How do I link a WPF app to a Telerik Report?

I created a Report Library with a report.
I created a WPF App.
I added a Report Viewer to the WPF App & pointed it to the report.
How do I link everything together?
The data within the WPF App needs to be in the report.
My Solution:
I added a “data” DLL and dded a reference to the data DLL to both the report & the WPF App.
When I run the program:
instance not found
OK, that makes sense since there’s no link.
After the WPF App instantiates the data, how is this instance linked to the report?
Key idea:
Within the Report's code behind,
protected override void OnNeedDataSource(object sender, System.EventArgs e)
In the constructor
Report.DataSource = null;
// "At runtime Report.NeedDataSource event is raised only when the report has no data source set"
Pass the data from the App to the Report as a parameter.
// This is a work in progress...

Cefsharp3-WinForms x64 shows blank page but x86 works

I have issues with initializing CefSharp3. The control give a blank page after initializing.
I follow the instructions from CefSharp Wiki page (https://github.com/cefsharp/CefSharp/wiki/Quick-Start and http://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application)
The problem is that when I build the application for x64 i get a blank page, but it works fine in x86.
The only code in my WinForms project is this:
public ChromiumWebBrowser chromeBrowser;
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
// Initialize cef with the provided settings
Cef.Initialize(settings);
// Create a browser component
chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com");
// Add it to the form and fill it to the form window.
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
public Form1()
{
InitializeComponent();
// Start the browser after initialize global component
InitializeChromium();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
I also tried adding a panel, and initializing ChromiumBrowser in the panel with panel1.Controls.Add(chromeBrowser) instead of this.Controls.add(chromeBrowser), but the issue is still there.
I found this in the troubleshooting section at CefSharp wiki:
https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting
b) The developer tools. Add a button to your form and make a call to "browser.ShowDevTools()". If you can see a document has loaded and you have a DOM in there, then your problem is a display output one and your most likely problem is one of not setting 'Dock' correctly, or some other setting is causing the browser to render offscreen/headless. If you get a blank tool window, or no tool window at all, then CefSharp has failed to initialize correctly, so you have a set-up issue to troubleshoot.
This is exactly the symptoms that I experience.
I tried creating the same project on my laptop (MacBook Pro with Win7, VS2013 and .NET 4.5.2) and it worked like a charm. This means something is up with my workstation (win10, VS2015 .NET 4.5.3).
Any ideas?
This appears to be a bug in the latest build. The solution for now is to use the v51.0.0 build.
You can do this quite easily in the NuGet package manager in VS2015, or if your using VS2013, use the "--version 51.0.0" option when installing cefsharp from the package manager command line.
The issue for the problem is here:
https://github.com/cefsharp/CefSharp/issues/1870
Keep an eye on the issue for future solutions.
Update 28/11/2016
This is a bug in the current V53 release of CefSharp. It's been confirmed by the CefSharp team and is addressed in issue #1819 (https://github.com/cefsharp/CefSharp/issues/1819)
The bug has been apparently fixed, but will not be released until V55.
The solution for now, is to either go back to V51 or to build your own version from source for V55.

Are WPF Application Settings automatically saved by default?

Are WPF Application Settings automatically saved by default when exit?
I just added a boolean to my application settings (by default is setted to false). I want to set it to true when application is running and next time when I open it again, to be false. I don't want to save my application settings. I want to be static for that boolean.
It is saving automatically?
When I used to work with VB.NET Winforms, there was a setting in Application tab, named "Save my.settings on shutdown". But, how is in WPF?
I use Visual Studio 2012, Vb.NET WPF application
Thank you
Are settings saved automatically? No, you have to explicit invoke the Save method upon each settings class.
Since you mention that you have multiple windows, then i think the quick and dirty way would be to override the OnExit Method in App:
Class Application
Protected Overrides Sub OnExit(ByVal e As ExitEventArgs)
MySettings.Default.Save()
MyBase.OnExit(e)
End Sub
End Class

Make an single instance app and showing the MainWindow when another instance is launched in VB.NET with WPF

I am looking for a way to make my app running in a single instance mode and showing the MainWindow of the first instance when another instance is launched.
I do a quick search on the internet but I did'nt find anything to open the MainWindow of the first instance or it was for Windows Form not for WPF.
I am working in VB.Net with Framework 4 and WPF.
Thanks
I wrote up an article for Winforms a while back at http://www.thinqlinq.com/Post.aspx/Title/Single-Instance-Winform-Issue. With winforms you can use the MyApplication_StartupNextInstance event handler to intercept subsequent launch requests and redirect them (navigating back to the MainWindow?) Unfortunately, I don't see that StartupNextInstance is still available with WPF. Maybe the pre 2.0 sample I posted at http://web.archive.org/web/20060528010613/http://www.avbsg.net/Uploads/SingleInstanceVB.zip can give you an idea of how to do this with WPF. My blog post walks through the general steps that I used.

Resources