VS2010 custom installer with own forms - visual-studio-2010

I am currently using custom forms in my VS2010 generated installer. Here is the code
namespace MyWinFormApp
{
[RunInstaller(true)]
public partial class MyInstaller : System.Configuration.Install.Installer
{
public MyInstaller()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
InstallForm topmostForm = new InstallForm();
topmostForm.BringToFront();
topmostForm.TopMost = true;
topmostForm.ShowDialog();
}
}
}
This shows my InstallForm as a popup while my installer generated wizard is still hanging in the background. The problem here is that even though I tried to make it modal. It still allows actions to be performed on the installer generated wizard while installing on my Windows 7 pc. It is not truly modal.
Any way to make my InstallForm as modal or get it to show as one of the installer generated wizard windows and not separately as a popup?
Using another install creator is not an option. I need to use Visual Studio only.

The only way I know to make the form modal is to make the installer generated wizard window owner of your form. But it is not a trivial task. Another complication is that your form and installer generated wizard run in different processes.
One way to overcome it is to hide installer wizard window. Although I'm not sure there's an easy way to do it. Otherwise you'll face the same problem as above: you have to find the correct installer window.
The better approach would be not to use forms shown from custom actions. You can create native MSI forms and insert them into the wizard UI sequence. And form would need to be topmost; I'd not recommend using topmost windows in an installer.

Related

How do I create a VS Extension without adding UI?

I'm writing a Visual Studio 2015 extension that adds messages to the Error List window. It needs no new UI. My code runs correctly if used in a tool window or menu item, but adding UI just for this feels like a sloppy workaround to obtain an IServiceProvider.
How can my code run and obtain an IServiceProvider without adding any UI elements?
Your Package class is an IServiceProvider; you can just call its GetService method.
If you're in a MEF class, you can instead simply import SVsServiceProvider.
For more information, see my blog.

how to make c# window form of AutoCAD plugin and AutoCAD itself available simultaneously

I have created a basic plugin for AutoCAD. In my plugin some task is being done through c# windows form. My end user require to access autocad while windows form is open. Currently AutoCAD is being un-accessible if c# windows form is open. To use AutoCAD user has to close form first.
Is there a way to make both the autocad and windows form accessible simultaneously?
Yes, you can use a modeless form:
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog
But it's not very intuitive, I would suggest a PaletteSet that hosts a user control.
Autodesk.AutoCAD.Windows.PaletteSet ps; // declare as a STATIC variable, avoid duplicate
ps.Add("Name here", userCtrl);
ps.Visible = true;
I prefer the Modal way and, inside a button where you need the user to select something on the drawing, use a EditorUserInteraction object
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
using (EditorUserInteraction userIt = ed.StartUserInteraction())
{
// this will close the form and go to the model space, once finished, the form gets back
}

Where should I attach solution or project events in my Visual Studio add-in?

Can anyone suggest the best place to add solution or project events, such as ProjectAdded, to a Visual Studio add-in?
If I do this when the add-in connects then there's no solution loaded, so how can I tell when a solution has been loaded?
For example, if I write an event to handle project items being added, where should I attach this? The event would be fired by the project, and that in turn by the solution, so I can't attach the events when the add-in connects because there is no solution when the add-in connects.
On the other hand, if I add them in the Exec() event then I need to do checks such as whether the event has been attached already, and I'm sure there must be a neater way sometime between the connection events and the Exec() event.
You probably figured this out long ago, but anyway: You can setup your events from within OnConnection like shown below, this is a snippet of an Addin's Connect class (assuming you're using c#):
using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using EnvDTE;
using EnvDTE80;
using Extensibility;
using Microsoft.VisualStudio.CommandBars;
namespace MyAddin1
{
/// <summary>The object for implementing an Add-in.</summary>
/// <seealso class='IDTExtensibility2' />
public class Connect : IDTExtensibility2, IDTCommandTarget
{
private DTE2 _applicationObject;
private AddIn _addInInstance;
private SolutionEvents _solutionEvents;
public void OnConnection(object application, ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// check the value of connectMode here, depending on your scenario
if(connectMode == ...)
SetupEvents();
}
private void SetupEvents()
{
// this is important ...
_solutionEvents = _applicationObject.Events.SolutionEvents;
// wire up the events you need
_solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(_solutionEvents_Opened);
_solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(_solutionEvents_AfterClosing);
_solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(_solutionEvents_ProjectAdded);
}
// add procedures to handle the events here, plus any other
// handling you need, ie. OnDisconnection and friends
}
The main point is, to wire up the solution and project events you need, it's not important if a solution or project is already loaded. They're not attached to any particular solution or project, they're provided by the Visual Studio object model and are embedded within the EnvDTE namespace.
It wouldn't make much sense to do anything else anyway, since you can configure an addin to load when VS starts, and in this case there will never ever be any solutions/projects loaded.
There's a few catches though:
It's important that you keep a reference to the SolutionEvents class as a member variable within your connect class, otherwise the events will never fire, (see also here).
You need to make sure you check the connectMode parameter passed into OnConnection. This gets called multiple times with different parameters, and if you do it the wrong way you may get the event wired up multiple times, which definetly will be a problem. Also, usually any Addin IDE, like Menus and stuff, is set up from within OnConnection, so you may end up with duplicate menu items if you don't do it right.
Here's a few pointers, some of the code provided is VB code, in case you're looking for that:
HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in
HOWTO: Getting Project and ProjectItem events from a Visual Studio .NET add-in.
HOWTO: Add an event handler from a Visual Studio add-in
Finally, here's a list of articles, about 70% of them cover basic and advanced topics regarding addins:
Resources about Visual Studio .NET extensibility
Find the section entitled MZ-Tools Articles Series (about add-ins) and have a look at what's covered there.

.NET VS2005 WinForms: How do i drop a user control onto a form?

i've written a UserControl descendant that is in an assembly dll.
How do i drop the control on a form?
namespace StackOverflowExample
{
public partial class MonthViewCalendar : UserControl
{
...
}
}
i've added a reference to the assembly under the References node in the Solution Explorer, but no new control has appeared in my Toolbox.
How do i make the control appear in the Toolbox so i can drop it on a form?
Update 1:
i tried building the assembly while the Visual Studio option:
Tools-->Options...-->Windows Forms Designer-->AutoToolboxPopulate = true
The control didn't appear when in the toolbox in a new solution.
Note: i somehow mistakenly wrote "...that is not in an assembly dll...". i don't know how i managed to write that, when it specifically is in an assembly dll. Controls have magically appeared when they're in the same project, but not now that it's a different project/solution.
Update 2: Answer
Right-click the Toolbox
Select Choose Items...
.NET Framework Components tab
Select Browse...
Browse to the assembly dll file that contains the control and select Open
Note: Controls in the assembly will silently be added to the list of .NET Framework Components.
Check each of the controls you wish to appear in the toolbox
Select OK
Normally, when you build your project, your user control will appear in your toolbox at the top. Normally, you will see a new pane with each of your Assemblies and the controls in there.
If that doesn't happen, you can also add your control by right clicking on the toolbox, selecting Choose Items, then under .NET Framework Components browsing for your assembly, adding it, then make sure your control is checked.
What I notice is that User Controls and Components are only automatically added to the Toolbox by vs2005 when your project (containing the controls/components) is located in the same folder as your solution. When this project is in a subfolder vs2005 won't add the controls and components in the Toolbox.
I stumbled upon some problems with this. In the end, just rebuild and re-reference will work. I had preferred to inherit from UserControl. It made my life simpler ;)
If for example you want to create a "rounded border" label, do something like this:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace YourUIControls
{
[DefaultProperty("TextString")]
[DefaultEvent("TextClick")]
public partial class RoundedLabel : UserControl
{
public RoundedLabel()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
//Draw your label hereā€¦
}
}
}
Compile and add a reference to the output. You'll be able to drag that to the Toolbox and later to the Designer.
You need to build the project containing the control you've created and make sure your options are set for the Toolbox to rebuild. If you haven't changed it from defaults, it should work; otherwise, go to Tools-->Options... and select the Windows Forms Designer group. Make sure the AutoToolboxPopulate option is set to true.
You don't need the ToolboxItemAttribute for it to work. If the providing assembly is in the same solution as the consuming assembly, it should appear in the toolbox. If the providing assembly is not part of the solution, you can manually add the assembly to the toolbox by selecting **Choose items...* from the toolbox context menu and adding your assembly directly. If you want the toolbox to automatically pick them up, you will need to use the ToolboxItemAttribute.
Add the ToolboxAttribute to your class.

Krypton Form not showing up in Visual Studio Professional 2008

I have just installed the Krypton Toolkit 3.0.6 from component Factory.
I find that in the create new Project Dialog Box , Krypton Form does not show up as an option. I am sure it used to show up ( and I have actually used it in an earlier version of krypton toolkit).But after the new install it does not.
For the sake of completeness and accuracy , I am posting the actual code for inheriting from a krypton form.
public partial class Form1 : ComponentFactory.Krypton.Toolkit.KryptonForm
The "New Krypton Form" used to show up not inside the "new project" dialog, but inside the "new item" dialog. (e.g. right-click on project, Add New Item)
But I don't see it there either. Phil may have removed this from the installer.
In any case, just add a regular Form, then make it derive from KryptonForm rather than Form, and voila, you have yourself a KryptonForm.

Resources