本文整理汇总了C#中IDesignerHost.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IDesignerHost.GetService方法的具体用法?C# IDesignerHost.GetService怎么用?C# IDesignerHost.GetService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDesignerHost
的用法示例。
在下文中一共展示了IDesignerHost.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectionUIService
public SelectionUIService(IDesignerHost host)
{
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.StandardClick | ControlStyles.Opaque, true);
this.host = host;
this.dragHandler = null;
this.dragComponents = null;
this.selectionItems = new Hashtable();
this.selectionHandlers = new Hashtable();
this.AllowDrop = true;
this.Text = "SelectionUIOverlay";
this.selSvc = (ISelectionService) host.GetService(typeof(ISelectionService));
if (this.selSvc != null)
{
this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged);
}
host.TransactionOpened += new EventHandler(this.OnTransactionOpened);
host.TransactionClosed += new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
if (host.InTransaction)
{
this.OnTransactionOpened(host, EventArgs.Empty);
}
IComponentChangeService service = (IComponentChangeService) host.GetService(typeof(IComponentChangeService));
if (service != null)
{
service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemove);
service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
}
SystemEvents.DisplaySettingsChanged += new EventHandler(this.OnSystemSettingChanged);
SystemEvents.InstalledFontsChanged += new EventHandler(this.OnSystemSettingChanged);
SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged);
}
示例2: GetExpressionBuilder
internal static ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host) {
// If there is no expressionPrefix, it's a v1 style databinding expression
if (expressionPrefix.Length == 0) {
if (dataBindingExpressionBuilder == null) {
dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
}
return dataBindingExpressionBuilder;
}
CompilationSection config = null;
// If we are in the designer, we need to access IWebApplication config instead
#if !FEATURE_PAL // FEATURE_PAL does not support designer-based features
if (host != null) {
IWebApplication webapp = (IWebApplication)host.GetService(typeof(IWebApplication));
if (webapp != null) {
config = webapp.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
}
}
#endif // !FEATURE_PAL
// If we failed to get config from the designer, fall back on runtime config always
if (config == null) {
config = MTConfigUtil.GetCompilationConfig(virtualPath);
}
System.Web.Configuration.ExpressionBuilder builder = config.ExpressionBuilders[expressionPrefix];
if (builder == null) {
throw new HttpParseException(SR.GetString(SR.InvalidExpressionPrefix, expressionPrefix));
}
Type expressionBuilderType = null;
if (host != null) {
// If we are in the designer, we have to use the type resolution service
ITypeResolutionService ts = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
if (ts != null) {
expressionBuilderType = ts.GetType(builder.Type);
}
}
if (expressionBuilderType == null) {
expressionBuilderType = builder.TypeInternal;
}
Debug.Assert(expressionBuilderType != null, "expressionBuilderType should not be null");
if (!typeof(ExpressionBuilder).IsAssignableFrom(expressionBuilderType)) {
throw new HttpParseException(SR.GetString(SR.ExpressionBuilder_InvalidType, expressionBuilderType.FullName));
}
ExpressionBuilder expressionBuilder = (ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(expressionBuilderType);
return expressionBuilder;
}
示例3: GetDeclarativeType
/// <summary>
/// <para>
/// Gets the delarative type for the
/// specified type.
/// </para>
/// </summary>
/// <param name='type'>
/// The type of the declarator.
/// </param>
/// <param name='host'>
/// The services interface exposed by the webforms designer.
/// </param>
private static string GetDeclarativeType(Type type, IDesignerHost host) {
Debug.Assert(host != null, "Need an IDesignerHost to create declarative type names");
string declarativeType = null;
if (host != null) {
IWebFormReferenceManager refMgr =
(IWebFormReferenceManager)host.GetService(typeof(IWebFormReferenceManager));
Debug.Assert(refMgr != null, "Did not get back IWebFormReferenceManager service from host.");
if (refMgr != null) {
string tagPrefix = refMgr.GetTagPrefix(type);
if ((tagPrefix != null) && (tagPrefix.Length != 0)) {
declarativeType = tagPrefix + ":" + type.Name;
}
}
}
if (declarativeType == null)
{
/* Begin AUI 7201 */
/* Original declarativeType = type.FullName; */
if (type == typeof(System.Web.UI.MobileControls.Style))
{
declarativeType = type.Name;
}
else
{
declarativeType = type.FullName;
}
/* End AUI 7201 */
}
return declarativeType;
}
示例4: CodeDomHostLoader
public CodeDomHostLoader(IDesignerHost host, string formFile, string unitFile)
{
_trs = host.GetService(typeof(ITypeResolutionService)) as TypeResolutionService;
this.formFile = formFile;
this.unitFile = unitFile;
this.host = host;
}
示例5: CreateComponentsCore
//
protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
Type typeOfComponent = GetType(host, AssemblyName, TypeName, true);
if (typeOfComponent == null && host != null)
typeOfComponent = host.GetType(TypeName);
if (typeOfComponent == null)
{
ITypeProviderCreator tpc = null;
if (host != null)
tpc = (ITypeProviderCreator)host.GetService(typeof(ITypeProviderCreator));
if (tpc != null)
{
System.Reflection.Assembly assembly = tpc.GetTransientAssembly(this.AssemblyName);
if (assembly != null)
typeOfComponent = assembly.GetType(this.TypeName);
}
if (typeOfComponent == null)
typeOfComponent = GetType(host, AssemblyName, TypeName, true);
}
ArrayList comps = new ArrayList();
if (typeOfComponent != null)
{
if (typeof(IComponent).IsAssignableFrom(typeOfComponent))
comps.Add(TypeDescriptor.CreateInstance(null, typeOfComponent, null, null));
}
IComponent[] temp = new IComponent[comps.Count];
comps.CopyTo(temp, 0);
return temp;
}
示例6: GetUniqueSiteName
public static string GetUniqueSiteName(IDesignerHost host, string name)
{
if (string.IsNullOrEmpty(name))
{
return null;
}
INameCreationService service = (INameCreationService)host.GetService(typeof(INameCreationService));
if (service == null)
{
return null;
}
if (host.Container.Components[name] == null)
{
if (!service.IsValidName(name))
{
return null;
}
return name;
}
string str = name;
for (int i = 1; !service.IsValidName(str); i++)
{
str = name + i.ToString(CultureInfo.InvariantCulture);
}
return str;
}
示例7: SampleToolboxService
public SampleToolboxService(IDesignerHost host)
{
this.host = host;
// Our MainForm adds our ToolboxPane to the host's services.
toolbox = host.GetService(typeof(SampleDesignerApplication.ToolBoxPane)) as SampleDesignerApplication.ToolBoxPane;
}
示例8: SampleSelectionService
internal SampleSelectionService(IDesignerHost host) {
this.host = host;
this.container = host.Container;
this.selectionsByComponent = new Hashtable();
this.selectionChanged = false;
// We initialize this to true to catch anything that would cause
// an update during load.
this.batchMode = true;
// And configure the events we want to listen to.
IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
Debug.Assert(cs != null, "IComponentChangeService not found");
if (cs != null) {
cs.ComponentAdded += new ComponentEventHandler(this.DesignerHost_ComponentAdd);
cs.ComponentRemoved += new ComponentEventHandler(this.DesignerHost_ComponentRemove);
cs.ComponentChanged += new ComponentChangedEventHandler(this.DesignerHost_ComponentChanged);
}
host.TransactionOpened += new EventHandler(this.DesignerHost_TransactionOpened);
host.TransactionClosed += new DesignerTransactionCloseEventHandler(this.DesignerHost_TransactionClosed);
// If our host is already in a transaction, we handle it.
if (host.InTransaction) {
DesignerHost_TransactionOpened(host, EventArgs.Empty);
}
host.LoadComplete += new EventHandler(this.DesignerHost_LoadComplete);
}
示例9: SelectWizard
private static void SelectWizard(IComponent wizardControl, IDesignerHost host)
{
if (wizardControl == null)
{
return;
}
if (host == null)
{
return;
}
while (true)
{
WizardDesigner designer = (WizardDesigner) host.GetDesigner(wizardControl);
if (designer == null)
{
return;
}
ISelectionService service = (ISelectionService) host.GetService(typeof (ISelectionService));
if (service == null)
{
return;
}
object[] components = new object[] {wizardControl};
service.SetSelectedComponents(components, SelectionTypes.Replace);
return;
}
}
示例10: RootParsingObject
public RootParsingObject(IDesignerHost host)
: base("", "", null)
{
this.host = host;
refMan = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;
if (refMan == null)
throw new Exception ("Could not get IWebFormReferenceManager from host");
}
示例11: fmEasilyReportDesigner
public fmEasilyReportDesigner(IReport rpt, IDesignerHost designerHost)
{
InitializeComponent();
designReport = rpt;
tempReport = rpt.Copy();
componentChangeService = designerHost.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
}
示例12: RunWizard
/// <summary>
/// This method sets various values on the newly created component.
/// </summary>
private IComponent[] RunWizard(IDesignerHost host, IComponent[] comps)
{
DialogResult result = DialogResult.No;
IVsUIShell uiShell = null;
if (host != null)
{
uiShell = (IVsUIShell)host.GetService(typeof(IVsUIShell));
}
// Always use the UI shell service to show a messagebox if possible.
// There are also some useful helper methods for this in VsShellUtilities.
if (uiShell != null)
{
int nResult = 0;
Guid emptyGuid = Guid.Empty;
uiShell.ShowMessageBox(0, ref emptyGuid, "Question", "Do you want to set the Text property?", null, 0,
OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_QUERY, 0, out nResult);
if (nResult == IDYES)
{
result = DialogResult.Yes;
}
}
else
{
result = MessageBox.Show("Do you want to set the Text property?", "Question", MessageBoxButtons.YesNo);
}
if (result == DialogResult.Yes)
{
if (comps.Length > 0)
{
// Use Types from the ITypeResolutionService. Do not use locally defined types.
ITypeResolutionService typeResolver = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
if (typeResolver != null)
{
Type t = typeResolver.GetType(typeof(MyCustomTextBoxWithPopup).FullName);
// Check to ensure we got the right Type.
if (t != null && comps[0].GetType().IsAssignableFrom(t))
{
// Use a property descriptor instead of direct property access.
// This will allow the change to appear in the undo stack and it will get
// serialized correctly.
PropertyDescriptor pd = TypeDescriptor.GetProperties(comps[0])["Text"];
if (pd != null)
{
pd.SetValue(comps[0], "Text Property was initialized!");
}
}
}
}
}
return comps;
}
示例13: SelectionService
public SelectionService(IDesignerHost host)
{
this.host = host;
selectedComponents = new ArrayList();
// Subscribe to the componentremoved event
IComponentChangeService c = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
c.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved);
}
示例14: SelectionServiceImpl
public SelectionServiceImpl(IDesignerHost host)
{
this.host = host;
selectedComponents = new ArrayList();
// we need to know when components get aded and/or removed
IComponentChangeService changeService = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
changeService.ComponentAdded +=new ComponentEventHandler(OnComponentAdded);
changeService.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved);
}
示例15: GetCodeCompileUnit
/// <summary>
/// This function generates the default CodeCompileUnit template
/// </summary>
public CodeCompileUnit GetCodeCompileUnit(IDesignerHost host)
{
this.host = host;
IDesignerHost idh = (IDesignerHost)this.host.GetService(typeof(IDesignerHost));
root = idh.RootComponent;
Hashtable nametable = new Hashtable(idh.Container.Components.Count);
ns = new CodeNamespace("DesignerHostSample");
myDesignerClass = new CodeTypeDeclaration();
initializeComponent = new CodeMemberMethod();
CodeCompileUnit code = new CodeCompileUnit();
// Imports
ns.Imports.Add(new CodeNamespaceImport("System"));
ns.Imports.Add(new CodeNamespaceImport("System.ComponentModel"));
ns.Imports.Add(new CodeNamespaceImport("System.Windows.Forms"));
code.Namespaces.Add(ns);
myDesignerClass = new CodeTypeDeclaration(root.Site.Name);
myDesignerClass.BaseTypes.Add(typeof(Form).FullName);
IDesignerSerializationManager manager = host.GetService(typeof(IDesignerSerializationManager)) as IDesignerSerializationManager;
ns.Types.Add(myDesignerClass);
// Constructor
CodeConstructor con = new CodeConstructor();
con.Attributes = MemberAttributes.Public;
con.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "InitializeComponent")));
myDesignerClass.Members.Add(con);
// Main
CodeEntryPointMethod main = new CodeEntryPointMethod();
main.Name = "Main";
main.Attributes = MemberAttributes.Public | MemberAttributes.Static;
main.CustomAttributes.Add(new CodeAttributeDeclaration("System.STAThreadAttribute"));
main.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(System.Windows.Forms.Application)), "Run"), new CodeExpression[] {
new CodeObjectCreateExpression(new CodeTypeReference(root.Site.Name))
}));
myDesignerClass.Members.Add(main);
// InitializeComponent
initializeComponent.Name = "InitializeComponent";
initializeComponent.Attributes = MemberAttributes.Private;
initializeComponent.ReturnType = new CodeTypeReference(typeof(void));
initializeComponent.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Text"), new CodePrimitiveExpression(root.Site.Name))); //roman//
myDesignerClass.Members.Add(initializeComponent);
codeCompileUnit = code;
return codeCompileUnit;
}