ILNumerics and Visual Studio Tools for Office (VSTO) - c#

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?

Related

.Net 6.0 Windows App Cant Reference System

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.

How to set C# application icon on Control Panel for Visual Studio 2015

This is a cosmetic issue but my application has a default icon on the control panel. Many other applications have custom icons.
My application does have custom icons for the menu and task bar.
How can the icon displayed on the Control Panel be changed using Visual Studio 2015 or later?
Update:
There has been a change in how Visual Studio creates installers. I'm not sure when it occurred, but 2015 definitely does not have a "deployment project". The majority of the hits on Google suggest going to the deployment project properties which does not exist under VS 2015 apps.
This was why I included the tag for visual-studio-2015. Sorry, not to have mentioned that in the original question. It would have been good information.
Using the registry is a possibility but the registry path mentioned, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, does not exist. It does sound kludgy to have the application check it's own icon in the registry all the time. It sounds like an installer function to me.
A post on the Microsoft Developer Network provided an answer. It also modifies the registry. I enhanced it by removing hard-coded values for the application name and the icon file.
// These references are needed:
// using System.Reflection;
// using System.Deployment.Application;
// using System.IO;
// using Microsoft.Win32;
private static void SetAddRemoveProgramsIcon(string iconName)
{
// only run if deployed
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string assemblyTitle="";
object[] titleAttributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
if (titleAttributes.Length > 0 && titleAttributes[0] is AssemblyTitleAttribute)
{
assemblyTitle = (titleAttributes[0] as AssemblyTitleAttribute).Title;
}
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, iconName);
if (!File.Exists(iconSourcePath))
{
return;
}
RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
for (int i = 0; i < mySubKeyNames.Length; i++)
{
RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
object myValue = myKey.GetValue("DisplayName");
if (myValue != null && myValue.ToString() == assemblyTitle)
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch (Exception) { }
}
return;
}
The original article by Robin Shahan is here: RobinDotNet
For WPF application we need to replace the following code
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, iconName);
Replace with below code
string iconSourcePath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Startup), "TestIcon.ico");
I know you want 2015 but others may be looking for this in newer versions, like I was.
In Visual Studio 2019 Community we can go to the properties panel for the main setup project and the top property is AddRemoveProgramsIcon.
I have just come through this case today. I know it is old but will be useful for new seekers. To expose icon in Control Panel do the following:
Make a folder in [solution Folder][Project Folder]\bin\debug\images
Copy your icon in the new folder
In Set Up project always refer to the icon in the new created folder.
Solved my problem easily

C# ChromimunFX: How to create multiTab browsing, and isolate between each tab?

I’m trying to use an embedded browser into my WinForms application. I used CefSharp ChromiumWebBrowser, it work perfectly. However, CEFSharp requires the Visual C++ 2013, or the Visual C++ 2008….I think it is a complicated dependency. I'm creating a portable application without the dependency envirenment.
I have found another library, similar CefSharp, also use Chrominum, called ChromiumFX (visit: https://bitbucket.org/chromiumfx/chromiumfx ). The library uses the .Net Framework 3.5 (Default available in Windows 7) , no need to install Visual C++. And it is suitable for my application.
But I don’t find any way to create multi tabs application with this library. Here is what I tried to do:
private void LifeSpanHandler_OnBeforePopup(object sender, CfxOnBeforePopupEventArgs e)
{
e.SetReturnValue(true);
tabPage2.InvokeOnUiThreadIfRequired(() =>
{
ChromiumWebBrowser b = new ChromiumWebBrowser(e.TargetUrl);
b.Dock = DockStyle.Fill;
tabPage2.Controls.Add(b);
});
}
InvokeOnUiThreadIfRequired is an extension method:
public static void InvokeOnUiThreadIfRequired(this Control control, Action action)
{
if (control.InvokeRequired)
{
control.BeginInvoke(action);
}
else
{
action.Invoke();
}
}
But the application error and the program has crashed.
Another thing, when I created a new instance of ChromiumWebBrowser, I want it isolated with another instance, it means do not use the same cookies, sessions with any instance (private browser). In CefSharp, just create a new RequestContext for new instance:
webbrowser.RequestContext = new RequestContext();
But in ChromiumFX, I dont find any way to do that!
Somebody help me? Thank for you help!

Localization works during debug, fails upon setup

I have a c# winform program which is translated to both Spanish and Portuguese. When debugging the program itself translates to the current windows chosen culture, and I also have a button to manually translate the program:
private void SetLanguage(string cul)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul);
foreach (System.Windows.Forms.Control control in Controls)
{
var resources = new ComponentResourceManager(typeof(FrmLogin));
resources.ApplyResources(control, control.Name, new CultureInfo(cul));
}
}
but when I install said application (with the Setup solution in visual studio) nothing works. The program loads default language (Spanish) and the button to manually translate doesn't work.
I'm using visual studio 2010. "Localizable" property is set to true.
Thanks!

learning monodevelop and am having trouble getting a messgae box to appear

I am working in monodevelop and learning c#....
I am trying to get a message box to appear but I can't get it to function correctly ...
Here is my code:
using System;
using Gtk;
using GtkSharp;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButton11ResizeChecked (object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Hello World Again!!");
}
}
What am i missing?
You cannot mix the GTK# and System.Windows.Forms UI toolkits. You need to use a GTK dialog, something like this:
void ShowMessage (Window parent, string title, string message)
{
Dialog dialog = null;
try {
dialog = new Dialog (title, parent,
DialogFlags.DestroyWithParent | DialogFlags.Modal,
ResponseType.Ok);
dialog.VBox.Add (new Label (message));
dialog.ShowAll ();
dialog.Run ();
} finally {
if (dialog != null)
dialog.Destroy ();
}
}
See also this question.
You are referencing GTK which is the bundled graphical toolkit in mono but are trying to use Windows.Forms which, although included in mono too, is a different toolkit:
System.Windows.Forms: This is the toolkit used in windows, the implementation on mono "emulates" how this controls are drawn and behave under platforms that mono runs on.
Gtk: This is a toolkit used in many OpenSource applications (Firefox, Pidgin, etc) and GTKSharp is simply the implementation of this same library but exposed to the .Net languages available on mono although you could use it directly with Visual Studio or a Microsoft compiler too.
So summarizing, as Mike said, you cannot use them both, you have to choose either one. If you are just learning .Net I would greatly advice to learn GTK instead of Windows Forms. Windows forms is kind of poor and basic toolkit, and soon you'll find that you'll need to learn a new API from a third party to do stuff that windows forms cant do (DevExpress, Infragistics) and Gtk can be easily extended and adjusted to your needs.

Categories