Visual Studio 2008的IDE无法呈现定制控件正确 [英] Visual studio 2008 IDE not rendering Custom Controls correctly

查看:155
本文介绍了Visual Studio 2008的IDE无法呈现定制控件正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,直到前面的视觉工作室2008年之内最多在设计时用我所有的形式和自定义控件的问题检查,所有的控件都呈现预期。当前版本和以前的工作版本之间唯一的主要区别是,在控制 UIText A属性是从更名为内容。其他的变化是增加了新的形式和新的3枚举,但肯定没有这将影响到所有形式的程序(包括新的)明显的变化。

I'm having an issue at design time with all my forms and custom controls within Visual Studios 2008. Up until the previous check in, all of the controls were rendering as expected. The only main difference between the current version and the previous working version was that a Property on the control UIText was renamed from Content to Value. The other changes are adding a new form and 3 new enums, but there's certainly no obvious change that would affect all forms in the program (including new ones).

所有的控件(各种形式的)现在呈现为与对照的名称框(但他们都正确地呈现在运行时):

All of the controls (on every form) now render as a box with the name of the control (however they all render correctly at run time):

我试过在我的项目创建一个全新的形式,创建一个只有它一个标签一个全新的自定义的控制,而我还有完全相同的问题:

I've tried creating a brand new form in my project, creating a brand new custom control with just a label on it, and I've still got exactly the same problem:

请注意, 。标准.NET窗体控件做工精细,所以这是只与自定义控件问题

Note that standard .Net form controls work fine, so this is only an issue with custom controls.

如果我从资料库恢复我以前的版本,那么一切都开始重新正确渲染:

If I restore my previous version from the repository, then everything starts rendering correctly again:

我能恢复到这个工作版本进行的,但我宁愿知道如何它应该再次出现解决这个问题。 。我在这里发帖,希望它为(顺便说一下关于SP1)结合在一个视觉工作室2008年发行的编程问题。

I could just revert back to this working version and carry on, but I'd rather know how to fix the problem should it occur again. I'm posting here hoping it's a programming issue as apposed to a Visual Studios 2008 issue (on SP1 by the way).

我的固定的问题。那么,固定是不是真的为它正确的字。我所在的问题通过一次删除所有的用户控件1,直到形式又开始正常渲染。这个问题是在我的签名控件(这一直存在了好半天,只在我最新的支票我已经添加到项目 iVirtualDocket.CodeLibrary 引用到主项目:

I fixed the issue. Well, fixed isn't really the right word for it. I located the issue by removing all of the user controls 1 at a time until the form started rendering properly again. The issue was in my Signature control (which has been present for ages, only in my latest check in I had added a reference to the project iVirtualDocket.CodeLibrary into the main project:

  iVirtualDocket
    - References iVirtualDocket.UIControls
    - References iVirtualDocket.CodeLibrary
  iVirtualDocket.UIControls
    -References iVirtualDocket.CodeLibrary

签名有一个叫做物业 SignatureData ,这是这样做的:

The signature has a property called SignatureData, which was doing this:

public byte[] SignatureData
{
    get
    {
        if (_signature == null)
        {
            return null;
        }
        else
        {
            return iVirtualDocket.CodeLibrary.Conversions.ImageToByteArray(
                _signature, ImageFormat.Png);
        }
    }
}

ImageToByteArray如下所示:

ImageToByteArray looks like the following:

public static byte[] ImageToByteArray(Image imageToConvert,
        ImageFormat formatOfImage)
{
    byte[] ret;
    using (MemoryStream ms = new MemoryStream())
    {
        imageToConvert.Save(ms, formatOfImage);
        ret = ms.ToArray();
    }

    return ret;
}

如果我移动上面的方法插入 UIControls 项目,然后一切工作正常。然而,当我把方法放回 CodeLibrary 项目,并把它那里,我的所有形式的停止渲染的用户控件。

If I move the above method into the UIControls project, then everything works fine. However, as soon as I put the method back into the CodeLibrary project and call it there, all my forms stop rendering UserControls.

这样算下来下列修复这个问题,但我真的很想知道为什么:

So doing the following fixes the problem, but I'd really like to know why:

public byte[] SignatureData
{
    get
    {
        if (_signature == null)
        {
            return null;
        }
        else
        {
            // Need to call this code directly here instead of through 
            // the CodeLibrary conversions, otherwise all user controls stop 
            // rendering in design mode
            byte[] ret;
            using (MemoryStream ms = new MemoryStream())
            {
                _signature.Save(ms, ImageFormat.Png);
                ret = ms.ToArray();
            }

            return ret;
        }
    }
}

(什么是连更离奇的是,我甚至不使用这个属性呢。)

推荐答案

我们有过一个应用程序类似的非设计时间显示问题。通过做一些研究(我不记得确切位置,我们发现它),我们结束了创建一个文件

We have an application that had similar non-design-time display problems. By doing some research (and I don't remember exactly where we found it), we ended up creating a file

DesignTimeAttributes.xmta

DesignTimeAttributes.xmta

它的类型是设计时属性文件

Its type is that of "Design-Time Attribute File"

在它和我们刚刚宣布每次我们有控制类界定和限定为DesktopCompatible。这样,它显然会告诉设计师其确定绘制,有的控件中的实际功能(也为我们手持式扫描器的签名控件),将实际调用运行时的东西,是不具备的设计师。该文件的内容是类似...

and in it, we just had to declare each of the control classes we had defined and qualified it as "DesktopCompatible". This way it apparently tells the designer its ok to draw, and the actual functionality within some controls (also a signature control on a handheld scanner for us), would actually invoke something during runtime that was not available in the designer. The content of the file was something like...

<?xml version="1.0" encoding="utf-16"?>
<Classes xmlns="http://schemas.microsoft.com/VisualStudio/2004/03/SmartDevices/XMTA.xsd">
  <Class Name="MyNamespace.MyControl">
    <DesktopCompatible>true</DesktopCompatible>
  </Class>

  <Class Name="MyNamespace.MyOtherControl">
    <DesktopCompatible>true</DesktopCompatible>
  </Class>

  <Class Name="AnotherNamespace.MySignControl">
    <DesktopCompatible>true</DesktopCompatible>
  </Class>
</Classes>

这也是除了提供csauve的答复意见。如果你的构造函数试图初始化的东西是设备相关的,因此抛出一个错误,因为设计时不明明有设备的dll,控制,或任何可以/也将杀死在设计时的控制。我们已经通过

This was also in addition to the comments provided csauve's answer. If your constructor is trying to initialize something that is device dependent and thus throws an error because the design-time doesn't obviously have the device dlls, controls, or whatever could/would also kill that control at design time. We've created two static functions to test either way via

public static bool IsDesignTime()
{
  return System.ComponentModel.LicenseManager.UsageMode ==
         System.ComponentModel.LicenseUsageMode.Designtime;
}

public static bool IsRunTime()
{
  return System.ComponentModel.LicenseManager.UsageMode ==
         System.ComponentModel.LicenseUsageMode.Runtime;
}

和分别在车队打电话给他们...

and call them respectively in the constructors...

这篇关于Visual Studio 2008的IDE无法呈现定制控件正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆