So the weirdness has hit. I created a new Visual Studio 2022 - fully patched, updated, and current.net 6.0 Windows Desktop app. It has 1 form that has a menu bar dragged from the toolbox on it and that is it. I have done nothing else to it! System, Form, void, object, EventArgs, and Application are all red and not available (see below)
using System;
namespace Developmeny_Test_Application
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
}
private void e7xitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
This is as basic as it gets and can I get Visual Studio to let it in?
Under Dependencies/COM it is showing an orange triangle (which I always thought meant depreciated but as this was created with the wizard templates that's not likely)
So my question is what am I missing? All the web searching I have done has revealed nothing of any use.
Any help is gratefully appreciated.
Added as an edit for more information
The section that has the triangle has this section in the project file :
<ItemGroup>
<COMReference Include="{bee4bfec-6683-3e67-9167-3c0cbc68f40a}">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>4</VersionMinor>
<VersionMajor>2</VersionMajor>
<Guid>bee4bfec-6683-3e67-9167-3c0cbc68f40a</Guid>
</COMReference>
</ItemGroup>
That COM-Reference is fishy. You should not need that. When I do the same (create a new Winforms project and add a "MenuStrip" to the form) I'm not getting that reference.
I'm assuming you accidentally added a component from a third-party library to your form, which caused this strange reference. Just delete that section from the project file and see what happens. If the error persists, please quote the exact error message you get.
Related
I just want to start by saying that I've done a lot of research but couldn't find an answer, hence the post.
I'm adding user settings functionality to my app which works as a plugin inside a common off the shelf program for architecture (called Autodesk Revit). The main project (let's call it MainProj) has several dependencies including a project that handles logging and usage (let's call it Loggers). I created a Settings file inside the Loggers project with the goal to have users change the logging level from Error to Debug when there are issues so I can ask them to make the change and send me the log.
The issue I'm facing is that when I change the log level directly inside the config file and re-run the command from within Revit, the change doesn't get translated into the log, as if the log level is somehow compiled during design and is never changed.
I actually tried to reproduce the problem in a simpler way and created a little console program and I'm facing the same issue. Below is the code from the Loggers project.
namespace Loggers
{
public static class Logger
{
public static string RunMe()
{
if (Properties.Settings.Default.LogMode == "Debug") { return "DEBUG"; }
else return "NOTHING";
}
}
}
I then changed the LogMode property from Debug to anything else in the config file but the console kept on returning DEBUG.
static void Main(string[] args)
{
Console.WriteLine(Logger.RunMe());
Console.Read();
}
I also tried changing the setting from user to application and editing its value in the config file and re-running the command but the outcome was the same.
Any help would be very much appreciated. I've been stuck on this for a while. Thank you.
Thanks to #BurnsBA, the link you shared had comments saying that the user.config lives in a different folder and it's not created until the user changes a setting. This made me understand that there wasn't a point in manually editing the app.config and expect the settings to work.
I then did some testing by creating a simple form with a checkbox linked to the Property I wanted to change and the user.config file gets created straight after I call the Save() method on the Properties.
private void btnOK_Click(object sender, EventArgs e)
{
if (chkDebugMode.Checked == true)
Loggers.Properties.Settings.Default.LogMode = "Debug";
else Loggers.Properties.Settings.Default.LogMode = "Error";
Loggers.Properties.Settings.Default.Save();
Close();
}
I want to have a Windows Form Application use a menustrip with three options to launch a console application. The console application is a .exe file built in C# in Visual Studio with some basic code for as school project. The console application does not need to return any values, it only needs to run and allow the user to use it. This is what the form will look like: Menu Application
I have tried importing the System.Diagnostics.Process.Start namespace with Process.Start#("Path of file") in my menu item click event method to launch my C# console application but have not been successful. I am getting a "Win32Exception was unhandled: An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll. Additional information: The system cannot find the file specified"
Here is the code in the menu item click event:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void lesson13LabCToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start(#"\C:\Users\Sam\Documents\Visual Studio 2015\Projects\LabMenu\LabMenu\Lesson13LabC.exe");
}
}
Any ideas on what I am doing wrong?
The error is clear The system cannot find the file specified. Check the path of file.
Also remove the starting \ in the path
Remove the backslash at the beginning of your path (before the drive letter).
So I have one Solution with four Projects in it. In Project_Owner_Add I want a Next button so that when it is clicked one of the other Projects is displayed.
This is my code.
private void buttonNext_Click(object sender, EventArgs e)
{
Project_Owner_Add.Form1 next = Project_Owner_Add_Product_Owner.Form1();
next.Show();
}
The error message is as follows:
Project_Owner_Add_Product_Owner does not exist in the current context
I'm assuming I'm going about calling information from a separate Project all wrong but I had sort of thought it was a matter of simply linking the forms together (this also doesn't work).
Any suggestions on how to get around this?
Add reference to your other project as already suggested, also you can use using directive to set some alias for your Form1 class in case when it exists in both projects.
The keyword new is essential when it comes to instantiating classes in C#. You can do something like this :
Add reference to other project if needed - > then :
using MyForm = Project_Owner_Add.Form1;
private void buttonNext_Click(object sender, EventArgs e)
{
MyForm next = new MyForm();
next.Show();
}
You need to add a reference to the second project. Do the following steps:
Right click Project_Owner_Add and select Add Reference.
Then Solution --> Projects and select second project from the list.
Then try this:
secondprojectNamespace.Form1 next = new secondprojectNamespace.Form1();
next.Show();
I am rebuilding a project that I originally coded in SharpDevelop in Visual Studio. The relevant code worked in SharpDevelop.
The following steps should illustrate the problem:
Create a new project
Add a reference to System.Data.SQLLite (I am using the DLL for .NET 4.5)
In the main form, add the using statement:
using System.Data.SQLite;
In the form's Load event, attach the event handler
private void PriceType2_Load(object sender, EventArgs e)
{
MessageBox.Show("Load event hNDLER");
SQLiteConnection con;
//con = new SQLiteConnection();
}
That works, but if you uncomment the next line, it doesn't.
private void PriceType2_Load(object sender, EventArgs e)
{
//SetDisableColors();
//ToggleEnableOff();
MessageBox.Show("Load event");
SQLiteConnection con;
con = new SQLiteConnection();
}
The form opens, but the message box is not displayed. As I said, it works fine in SharpDevelop. And in case you're wondering, I am migrating the project because I need a grown up Report Viewer.
Any ideas?
I just changed the reference to the assembly for .NET 4.0 (although my dev machine and all my others have 4.5) and it works. I remembered reading somewhere that there was an issue with the 4.5 DLL, but I don't know what it was.
Thanks for all the pointers.
I've been experiemnting with the community version of ILNumerics 3.2.1.0 with .Net 4.0 in Visual Studio 2010 pro on Windows 7, and going through the documentation I succesfully get a windows form project to display a chart, using the code below.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void ilPanel1_Load(object sender, EventArgs e)
{
ILSurface mySurface = new ILSurface(ILSpecialData.sincf(100, 200));
ILPlotCube myCube = new ILPlotCube(twoDMode: false);
myCube.Add(mySurface);
ilPanel1.Scene.Add(myCube);
}
}
If I try exactly the same code but from inside a VSTO Excel 2010 application all that is displayed in the form is the designer view of the ILPanel, blue circle on white background. I don't get any error messages. Am I missing something obvious? or does anyone have a solution of how to get the chart to display in VSTO?
Update
Thanks to Philliproso for pointing out the IsDesignMode() method. As pointed out in various places, including this question, Detecting design mode from a Control's constructor , the following method is not ideal, but for me is has provided a quick fix to allow me to evaluate ILNumerics.
public static bool IsDesignMode() {
if (System.Windows.Forms.Application.ExecutablePath.IndexOf("devenv.exe", StringComparison.OrdinalIgnoreCase) > -1)
{
return true;
}
return false;
}
This is the same issue as here:
Ilnumerics Ilpanel not activating when compiled in a winform into a dll when loaded into matlab
in-a-winform-into-a-dll-when-loa
Using VSTO as host for ILNumerics lets the panels assume, it was loaded in a designer. We are currently collecting possible workarounds and solutions. One solution might be to introduce a flag in the Settings of ILNumerics:
Hosted [default: false]
Your situation would require the flag to be enabled. In hosted mode, a blacklist of common designers could be checked at runtime and compared to the current entry assembly. Any other suggestions?