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();
Related
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.
Im really new at this, Im following an example of a book I bought and I'm lost since I'm not sure if things have change in this regards, I've look all over the internet (google and here) to find the answer and nothing, deeply apologize if it has been asked before.
The thing is I'm following the code snipets from the book and to do a Balloon Shop online store, so to create a user control that will present the information for the different departments located in the database.
I need to reference a method in the user control located in the public class CatalogAccess, but is showing that CatalogAccess does not exist in the current context.
This is the code behind of the user control, where the problem happens:
public partial class UserControls_DepartmentsList : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
list.DataSource = CatalogAccess.GetDepartments();
list.DataBind();
}
}
This is the code for CatalogAccess:
public static class CatalogAccess
{
public static DataTable GetDepartments()
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "Get Departments";
return GenericDataAccess.ExecuteSelectCommand(comm);
}
}
Mostly your CatalogAccess class is defined in a separate namespace and if so then you might want to import that saying using some_namespace;. Also, if it's defined in a separate project/assembly then you will have to add the reference of that assembly to your aspx project
Is there anyway that a reference can be added to a solution programmatically?
I have an add-in button, when the user presses it, I want a reference to be added.
The reason is, I have created a piece of software that I want to be integrated into any given VS program (if the developer wants it), they would simply click the add-in button and the reference would be loaded in the current solution.
Is this possible?
Something like this I haven't tested it
get the environment
EnvDTE80.DTE2 pEnv = null;
Type myType = Type.GetTypeFromProgID("VisualStudio.DTE.8.0");
pEnv = (EnvDTE80.DTE2)Activator.CreateInstance(myType, true);
get the solution.
Solution2 pSolution = (Solution2)pEnv.VS.Solution;
get the project that you want
Project pProject = pSolution.Projects[0];
add the reference
pProject.References.Add(string referenceFilePath);
There is an example on CodeProject.
The functionality is contained within a single class elRefManager and the method to call is CheckReferences. The code can be looked at here by selecting the elRefManager.cs file on the left hand side.
As seen in the article you could do...
private void button1_Click(object sender, System.EventArgs e)
{
int ec;
ec=elRefManager.CheckReferences(null, new string[] {textBox1.Text});
if (ec<0)
MessageBox.Show("An error occurred adding this reference");
if (ec>0)
MessageBox.Show("Could not add " + textBox1.Text +
"\nCheck its spelling and try again");
}
System.Assembly.load Allows you to call functions in a library that were not built with your program.
If you want to add a reference to the project so that its in the solution you can use the following. Basically the same as #Scots answer.
I did it in a macro which is vb but I'm sure you can get the idea
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
Dim objProject As EnvDTE.Project
Dim i As Long
i = DTE.Solution.Projects.Count
For Each objProject In DTE.Solution.Projects
If (objProject.Name() = "csCA") Then
Dim vsproj As VSLangProj.VSProject
vsproj = objProject.Object
vsproj.References.Add("C:\Users\test.dll")
End If
Next
The bottom code to open a form works but yet the top one does not, I can't think why?
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
PatientProfile Profile = new PatientProfile();
PatientProfile.Show();
}
private void returnTologin_Click(object sender, EventArgs e)
{
this.Hide();
Login Login = new Login();
Login.Show();
}
I dont know if this is your actual problem, since the description isnt very clear, but surely
PatientProfile.Show();
Should be:
Profile.Show();
You are calling .Show() on the class, not your instance of it.
Is the PatientProfile form in a sub-folder of your project?
For example, in a folder called 'Patient'?
If so, c# helpfully appends the name of your sub-folder to the Projects Namespace, which could result in the error you're having.
If this is the case there are two fixes;
Open the PatientProfile form and remove additional ending on it's namespace (i.e. namespace Project.Patient -> namespace Project)
Or, add the additional namespace in a using statement on your calling form (i.e. using Project.Patient;)
This may be a long shot, but I'm using ComponentOne's Spellchecker control for Silverlight. I made a test project, added a plain textbox and a button to it, added the references to the C1.Silverlight and C1.Silverlight.SpellChecker bits, and added the dictionary file to my project.
In the code, I called up the spellchecker on button1's click event and it worked SPLENDIDLY. The spellchecker dialog shows up, and works exactly as it should.
Since that test was successful, I then tried to implement this into my existing project. I've had no success for absolutely NO reason that I can determine, since I used the EXACT SAME code.
Here's the code I use to call the component:
using C1.Silverlight;
using C1.Silverlight.SpellChecker;
using C1.Silverlight.Resources;
public partial class MainPage : UserControl
{
C1SpellChecker spellChecker = new C1SpellChecker();
public MainPage()
{
InitializeComponent();
spellChecker.MainDictionary.LoadAsync("C1Spell_en-US.dct");
}
private void btnSpelling_Click(object sender, RoutedEventArgs e)
{
var dlg = new C1SpellDialog();
spellChecker.CheckControlAsync(txtArticle, false, dlg);
}
The references to C1.Silverlight and C1.Silverlight.Spellchecker are added to this project as well, and the dictionary as been added in the same fashion as well. The issue seems to be that for whatever reason the dictionary is not loading, because the spellChecker.Enabled method returns whether or not the main dictionary has been loaded. If I call MessageBox.Show("SpellChecker Enabled = " + spellChecker.Enabled.ToString()); it shows false, even though the call to load the dictionary is there (as you can see).
What would cause the dictionary to not load? Have I added it to my project incorrectly somehow?
EDIT: I suspect that I have added the dictionary to the project incorrectly, because the ComponentOne reference states:
If C1SpellChecker cannot find the
spelling dictionary, it will not throw
any exceptions. The Enabled property
will be set to false and the component
will not be able to spell-check any
text.
I just don't know what's wrong though because it was added in the same way that it was in the test project (Right clicked on the project.web->Add->Existing Item)
As always, thank you!
-Sootah
You could add the dictionary to the Silverlight app as an embedded resource and then load it using this code:
public MainPage()
{
InitializeComponent();
// load C1SpellChecker dictionary from embedded resource
var asm = this.GetType().Assembly;
foreach (var res in asm.GetManifestResourceNames())
{
if (res.EndsWith(".dct"))
{
using (var s = asm.GetManifestResourceStream(res))
{
sc.MainDictionary.Load(s);
break;
}
}
}
}
I think this post is duplicated in our forum as well, but will answer first here. Please try this:
1) Try to access the .dct file using your browser. If you cannot see it, it's probably because your web server is not serving that type of files. You need ton configure the web server to allow it.
2) verify the URL you are using is correct.http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/86955/241328.aspx#241328
3) Check you are setting everything correctly: http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/81924/227790.aspx#227790
Hope this helps!